Example usage for java.util Vector indexOf

List of usage examples for java.util Vector indexOf

Introduction

In this page you can find the example usage for java.util Vector indexOf.

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this vector, or -1 if this vector does not contain the element.

Usage

From source file:com.ricemap.spateDB.operations.RangeQuery.java

public static void main(String[] args) throws IOException {
    CommandLineArguments cla = new CommandLineArguments(args);
    final QueryInput query = cla.getQuery();
    final Path[] paths = cla.getPaths();
    if (paths.length == 0 || (cla.getPrism() == null && cla.getSelectionRatio() < 0.0f)) {
        printUsage();/*  w ww . jav  a2 s.co  m*/
        throw new RuntimeException("Illegal parameters");
    }
    JobConf conf = new JobConf(FileMBR.class);
    final Path inputFile = paths[0];
    final FileSystem fs = inputFile.getFileSystem(conf);
    if (!fs.exists(inputFile)) {
        printUsage();
        throw new RuntimeException("Input file does not exist");
    }
    final Path outputPath = paths.length > 1 ? paths[1] : null;
    final Prism[] queryRanges = cla.getPrisms();
    int concurrency = cla.getConcurrency();
    final Shape stockShape = cla.getShape(true);
    final boolean overwrite = cla.isOverwrite();

    final long[] results = new long[queryRanges.length];
    final Vector<Thread> threads = new Vector<Thread>();

    final BooleanWritable exceptionHappened = new BooleanWritable();

    Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread th, Throwable ex) {
            ex.printStackTrace();
            exceptionHappened.set(true);
        }
    };

    for (int i = 0; i < queryRanges.length; i++) {
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    int thread_i = threads.indexOf(this);

                    long result_count = rangeQueryMapReduce(fs, inputFile, outputPath, queryRanges[thread_i],
                            stockShape, overwrite, false, query);
                    results[thread_i] = result_count;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        t.setUncaughtExceptionHandler(h);
        threads.add(t);
    }

    long t1 = System.currentTimeMillis();
    do {
        // Ensure that there is at least MaxConcurrentThreads running
        int i = 0;
        while (i < concurrency && i < threads.size()) {
            Thread.State state = threads.elementAt(i).getState();
            if (state == Thread.State.TERMINATED) {
                // Thread already terminated, remove from the queue
                threads.remove(i);
            } else if (state == Thread.State.NEW) {
                // Start the thread and move to next one
                threads.elementAt(i++).start();
            } else {
                // Thread is still running, skip over it
                i++;
            }
        }
        if (!threads.isEmpty()) {
            try {
                // Sleep for 10 seconds or until the first thread terminates
                threads.firstElement().join(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    } while (!threads.isEmpty());
    long t2 = System.currentTimeMillis();

    if (exceptionHappened.get())
        throw new RuntimeException("Not all jobs finished correctly");
    System.out.println("Time for " + queryRanges.length + " jobs is " + (t2 - t1) + " millis");

    System.out.print("Result size: [");
    for (long result : results) {
        System.out.print(result + ", ");
    }
    System.out.println("]");
}

From source file:com.seer.datacruncher.profiler.spring.ProfilerInfoController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    @SuppressWarnings("unchecked")
    Hashtable<String, String> dbParams = (Hashtable<String, String>) request.getSession(true)
            .getAttribute("dbConnectionData");
    if (dbParams != null) {
        request.setAttribute("serverName", CommonUtil.notNullValue(dbParams.get("Database_DSN")));
    }/*from w w w .j a v a 2s  . c om*/
    String selectedValue = CommonUtil.notNullValue(request.getParameter("selectedValue"));
    request.setAttribute("selectedValue", selectedValue);
    String parentNodeValue = CommonUtil.notNullValue(request.getParameter("parent"));
    request.setAttribute("parentValue", parentNodeValue);
    ObjectMapper mapper = new ObjectMapper();
    if (CommonUtil.notNullValue(request.getParameter("action")).equals("minMaxValues")) {
        InfoBL ibl = new InfoBL();
        String data = mapper.writeValueAsString(
                ibl.generateMinMaxValueGrid(CommonUtil.notNullValue(dbParams.get("Database_DSN")),
                        parentNodeValue, selectedValue.split(":")[0]));
        PrintWriter out = response.getWriter();
        out.println(data);
        return null;
    } else if (CommonUtil.notNullValue(request.getParameter("tab")).equals("analysis")) {
        String queryString = CommonUtil.notNullValue(request.getParameter("queryString"));
        Vector vector = RdbmsConnection.getTable();
        String s = parentNodeValue;
        int i = vector.indexOf(s);
        Vector avector[] = (Vector[]) null;
        avector = TableMetaInfo.populateTable(5, i, i + 1, avector);
        QueryDialog querydialog = new QueryDialog(1, s, avector);
        List<String> listPrimaryKeys = new ArrayList<String>();

        try {
            RdbmsConnection.openConn();
            DatabaseMetaData dbmd = RdbmsConnection.getMetaData();

            ResultSet resultset = dbmd.getPrimaryKeys(null, null, s);
            while (resultset.next()) {
                listPrimaryKeys.add(resultset.getString("COLUMN_NAME"));
            }
            RdbmsConnection.closeConn();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        try {
            querydialog.executeAction(queryString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("rowCount", querydialog.getRowCount());
        GridUtil gridUtil = new GridUtil();
        gridUtil.generateGridData(querydialog.getTableGridDTO(), false, listPrimaryKeys);
        request.setAttribute("gridColumns", gridUtil.getColumnNames());
        GridUtil gridUtilEdit = new GridUtil();
        gridUtilEdit.generateGridData(querydialog.getTableGridDTO(), true, listPrimaryKeys);
        request.setAttribute("gridColumnsEdit", gridUtilEdit.getColumnNames());
        request.setAttribute("gridFields", gridUtil.getFieldNames());
        request.setAttribute("gridData", gridUtil.getData());
        request.setAttribute("systemDate", new Date(System.currentTimeMillis()).toString());
        return new ModelAndView("jsp/profiler/analysis.jsp");

    } else if (CommonUtil.notNullValue(request.getParameter("isLeaf")).equals("true")) {
        String s = dbParams.get("Database_DSN");
        String s1 = parentNodeValue;
        String s2 = selectedValue.split(":")[0];
        QueryBuilder querybuilder = new QueryBuilder(s, s1, s2, RdbmsConnection.getDBType());
        Double profileValues[] = FirstInformation.getProfileValues(querybuilder);
        Vector patternValues[] = FirstInformation.getPatternValues(querybuilder);
        Vector distValues[] = getDistributionValues(querybuilder, request);
        // showBar(ad);
        // showPatternChart(avector);
        String pieChartData = ChartUtil.getChartDataForPieChart(distValues);
        String barChartData = ChartUtil.getChartDataForBarChart(profileValues);
        String patternChartData = ChartUtil.getChartDataForPieChart(patternValues);
        request.setAttribute("pieChartData", pieChartData);
        request.setAttribute("barChartData", barChartData);
        request.setAttribute("patternChartData", patternChartData);
        return new ModelAndView("jsp/profiler/charts.jsp");
    } else {
        Vector vector = RdbmsConnection.getTable();
        String s = selectedValue;
        int i = vector.indexOf(s);
        Vector avector[] = (Vector[]) null;
        avector = TableMetaInfo.populateTable(5, i, i + 1, avector);
        QueryDialog querydialog = new QueryDialog(1, s, avector);
        try {
            querydialog.executeAction("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("rowCount", querydialog.getRowCount());
        GridUtil gridUtil = new GridUtil();
        gridUtil.generateGridData(querydialog.getTableGridDTO(), false, null);
        request.setAttribute("gridColumns", gridUtil.getColumnNames());
        request.setAttribute("colCount", querydialog.getTableGridDTO().getColumnNames().length);
        request.setAttribute("gridFields", gridUtil.getFieldNames());
        request.setAttribute("gridData", gridUtil.getData());
        return new ModelAndView("jsp/profiler/info.jsp");
    }

}

From source file:com.seer.datacruncher.profiler.spring.ProfilerInfoUpdateController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletOutputStream out = null;//from w w  w  .  j  ava  2 s.c o  m
    response.setContentType("application/json");
    out = response.getOutputStream();

    @SuppressWarnings("unchecked")
    Hashtable<String, String> dbParams = (Hashtable<String, String>) request.getSession(true)
            .getAttribute("dbConnectionData");
    if (dbParams != null) {
        request.setAttribute("serverName", CommonUtil.notNullValue(dbParams.get("Database_DSN")));
    }
    String selectedValue = CommonUtil.notNullValue(request.getParameter("selectedValue"));

    request.setAttribute("selectedValue", selectedValue);
    String tableName = CommonUtil.notNullValue(request.getParameter("parent"));

    request.setAttribute("parentValue", tableName);

    ObjectMapper mapper = new ObjectMapper();

    Vector vector = RdbmsConnection.getTable();

    int i = vector.indexOf(tableName);

    Vector avector[] = (Vector[]) null;
    avector = TableMetaInfo.populateTable(5, i, i + 1, avector);

    QueryDialog querydialog = new QueryDialog(1, tableName, avector);
    try {
        querydialog.executeAction("");
    } catch (Exception e) {
        e.printStackTrace();
    }

    String strColumnName = "";

    List<String> listPrimaryKeys = new ArrayList<String>();
    Map<String, Integer> mapColumnNames = new HashMap<String, Integer>();

    try {

        RdbmsConnection.openConn();
        DatabaseMetaData dbmd = RdbmsConnection.getMetaData();

        ResultSet resultset = dbmd.getPrimaryKeys(null, null, tableName);
        while (resultset.next()) {
            listPrimaryKeys.add(resultset.getString("COLUMN_NAME"));
        }

        resultset = dbmd.getColumns(null, null, tableName, null);

        while (resultset.next()) {
            strColumnName = resultset.getString(4);
            mapColumnNames.put(strColumnName, resultset.getInt(5));
        }

        RdbmsConnection.closeConn();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    Map<String, Integer> mapPrimaryKeys = new HashMap<String, Integer>();

    if (strColumnName.trim().length() > 0) {
        try {
            JSONArray array = new JSONArray(request.getParameter("data"));

            for (int count = 0; count < array.length(); count++) {
                JSONObject jsonObject = new JSONObject(array.get(count).toString());

                StringBuilder queryString = new StringBuilder();
                Iterator<String> keyIterator = jsonObject.keys();

                while (keyIterator.hasNext()) {
                    String strKey = keyIterator.next();

                    if (listPrimaryKeys.contains(strKey)) {
                        mapPrimaryKeys.put(strKey,
                                ((int) Double.parseDouble(jsonObject.get(strKey).toString())));
                        continue;
                    }
                    if (jsonObject.get(strKey) != null) {

                        if (mapColumnNames.get(strKey) == 4 || mapColumnNames.get(strKey) == 5
                                || mapColumnNames.get(strKey) == -6) {
                            queryString.append(
                                    strKey + "=" + Integer.parseInt(jsonObject.get(strKey).toString()) + ",");
                        } else if (mapColumnNames.get(strKey) == 2 || mapColumnNames.get(strKey) == 3
                                || mapColumnNames.get(strKey) == 7 || mapColumnNames.get(strKey) == 6
                                || mapColumnNames.get(strKey) == -5) {
                            queryString.append(strKey + "=" + jsonObject.get(strKey) + ",");
                        } else if (mapColumnNames.get(strKey) == 91 || mapColumnNames.get(strKey) == 92
                                || mapColumnNames.get(strKey) == 93) {
                            queryString.append(strKey + "=" + jsonObject.get(strKey) + ",");
                        } else if (mapColumnNames.get(strKey) == -7 || mapColumnNames.get(strKey) == 16
                                || mapColumnNames.get(strKey) == -3 || mapColumnNames.get(strKey) == -4) {
                            queryString.append(strKey + "=" + jsonObject.get(strKey) + ",");
                        } else if (mapColumnNames.get(strKey) == -1 || mapColumnNames.get(strKey) == 1
                                || mapColumnNames.get(strKey) == 12) {
                            queryString.append(strKey + "=\"" + jsonObject.get(strKey) + "\",");
                        }
                    }
                }
                StringBuilder whereClause = new StringBuilder(" where ");

                for (String primaryKey : listPrimaryKeys) {
                    whereClause.append(primaryKey + "=" + mapPrimaryKeys.get(primaryKey).intValue());
                    whereClause.append(" and ");
                }
                String strWhereClause = whereClause.toString();
                strWhereClause = strWhereClause.substring(0, strWhereClause.lastIndexOf("and"));

                queryString = new StringBuilder("UPDATE " + tableName + " SET ")
                        .append(queryString.toString().substring(0, queryString.toString().length() - 1));
                queryString.append(strWhereClause);

                RdbmsConnection.openConn();
                RdbmsConnection.executeUpdate(queryString.toString());
                RdbmsConnection.closeConn();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    Update update = new Update();
    update.setSuccess(true);

    GridUtil gridUtil = new GridUtil();
    gridUtil.generateGridData(querydialog.getTableGridDTO(), false, null);
    update.setResults(gridUtil.getData());

    out.write(mapper.writeValueAsBytes(update));
    out.flush();
    out.close();

    return null;
}

From source file:edu.ku.brc.af.ui.forms.MenuSwitcherPanel.java

/**
 * @param value/*from   w  w w .j  a va  2  s  .  c om*/
 */
public void set(final AltViewIFace altView) {
    if (cardLayout != null) {
        cardLayout.show(this, altView.getSelectorValue());
    }

    String value = isSelector ? altView.getSelectorValue() : "0";
    Vector<AltViewIFace> avList = selectorValHash.get(value);
    DropDownButtonStateful dds = switcherHash.get(value);

    if (dds != null && avList != null) {
        dds.setCurrentIndex(avList.indexOf(altView));
    }
}

From source file:net.aepik.alasca.gui.util.LoadFileFrame.java

/**
 * Load a file./* w  w  w  .ja va  2s. co m*/
 */
public boolean loadFile(String filename, String syntaxe) {
    if (!(new File(filename)).exists()) {
        this.errorMessage = "Le fichier n'existe pas.";
        return false;
    }
    try {
        SchemaSyntax syntax = Schema.getSyntax(syntaxe);
        SchemaFile schemaFile = Schema.createAndLoad(syntax, filename, true);
        Schema schema = schemaFile.getSchema();
        if (schema == null) {
            String message = "";
            if (schemaFile.isError()) {
                message += "\n\n" + "Line " + schemaFile.getErrorLine() + ":\n" + schemaFile.getErrorMessage();
            }
            this.errorMessage = "Le format du fichier est incorrect." + message;
            return false;
        }
        if (manager.isSchemaIdExists((new File(filename)).getName())) {
            this.errorMessage = "Le fichier est dj ouvert.";
            return false;
        }
        Vector<String> files = Pref.getVector(Pref.PREF_LASTOPENFILES);
        Vector<String> syntaxes = Pref.getVector(Pref.PREF_LASTOPENSYNTAXES);
        int index = files.indexOf(filename);
        if (index >= 0) {
            files.removeElementAt(index);
            syntaxes.removeElementAt(index);
        }
        files.add(filename);
        syntaxes.add(syntaxe);
        if (files.size() > 10) {
            files.removeElementAt(0);
            syntaxes.removeElementAt(0);
        }
        Pref.set(Pref.PREF_LASTOPENFILES, files.toArray(new String[0]));
        Pref.set(Pref.PREF_LASTOPENSYNTAXES, syntaxes.toArray(new String[0]));
        manager.addSchema((new File(filename)).getName(), schema);
    } catch (Exception e) {
        e.printStackTrace();
        this.errorMessage = "Une erreur inattendue est survenue.";
        return false;
    }
    return true;
}

From source file:edu.ku.brc.specify.tasks.subpane.security.UserAgentVSQBldr.java

/**
 * @param dataMap/*from  www  .j ava 2 s  .c o m*/
 * @param fieldNames
 * @return
 */
@Override
public String buildSQL(final Map<String, Object> dataMap, final List<String> fieldNames) {
    Vector<Object> disciplineIds = BasicSQLUtils
            .querySingleCol("SELECT DisciplineID FROM discipline ORDER BY Name");
    if (disciplineIds.size() > 1) {
        Vector<Object> divisionNames = BasicSQLUtils
                .querySingleCol("SELECT Name FROM discipline ORDER BY Name");
        ToggleButtonChooserDlg<Object> divDlg = new ToggleButtonChooserDlg<Object>((Dialog) null,
                UIRegistry.getResourceString("SEC_PK_SRCH"), divisionNames,
                ToggleButtonChooserPanel.Type.RadioButton);
        divDlg.setUseScrollPane(true);
        divDlg.createUI();
        divDlg.getCancelBtn().setVisible(false);

        divDlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        UIHelper.centerAndShow(divDlg);
        int inx = divisionNames.indexOf(divDlg.getSelectedObject());
        disciplineID = (Integer) disciplineIds.get(inx);

    } else {
        disciplineID = (Integer) disciplineIds.get(0);
    }

    String searchName = cbx.getSearchName();
    if (searchName != null) {
        esTblInfo = ExpressSearchConfigCache.getTableInfoByName(searchName);
        if (esTblInfo != null) {
            String sqlStr = esTblInfo.getViewSql();
            return buildSearchString(dataMap, fieldNames,
                    StringUtils.replace(sqlStr, "DSPLNID", disciplineID.toString()));
        }
    }
    return null;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetPlatformListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> values = this.ui.getValues();
    Vector<String> samples = this.ui.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File mappingFile = ((SnpData) this.dataType).getMappingFile();
    if (mappingFile == null) {
        this.ui.displayMessage("Error: no subject to sample mapping file");
    }/*from  w  w w. ja  va2  s. c  om*/
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);

        try {
            BufferedReader br = new BufferedReader(new FileReader(mappingFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String platform;
                if (samples.contains(sample)) {
                    platform = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.ui.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (mappingFile != null) {
                String fileName = mappingFile.getName();
                mappingFile.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((SnpData) this.dataType).setMappingFile(fileDest);
        } catch (IOException ioe) {
            this.ui.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.ui.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.ui.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetTissueListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> values = this.ui.getValues();
    Vector<String> samples = this.ui.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File mappingFile = ((SnpData) this.dataType).getMappingFile();
    if (mappingFile == null) {
        this.ui.displayMessage("Error: no subject to sample mapping file");
    }// ww w .java 2  s  .  c  o m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);

        try {
            BufferedReader br = new BufferedReader(new FileReader(mappingFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String tissueType;
                if (samples.contains(sample)) {
                    tissueType = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + fields[4]
                        + "\t" + tissueType + "\t" + fields[6] + "\t" + fields[7] + "\t" + "PLATFORM+TISSUETYPE"
                        + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.ui.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (mappingFile != null) {
                String fileName = mappingFile.getName();
                mappingFile.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((SnpData) this.dataType).setMappingFile(fileDest);
        } catch (IOException ioe) {
            this.ui.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.ui.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.ui.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetSiteIdListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setSiteIdUI.getValues();
    Vector<String> samples = this.setSiteIdUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setSiteIdUI.displayMessage("Error: no subject to sample mapping file");
    }// w ww.  j ava2s  .c o m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String site;
                if (samples.contains(sample)) {
                    site = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + site + "\t" + fields[2] + "\t" + sample + "\t" + fields[4] + "\t"
                        + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setSiteIdUI.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setSiteIdUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setSiteIdUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setSiteIdUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetPlatformsListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setPlatformsUI.getValues();
    Vector<String> samples = this.setPlatformsUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setPlatformsUI.displayMessage("Error: no subject to sample mapping file");
    }//from ww w  . j  a v  a  2 s. co  m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String platform;
                if (samples.contains(sample)) {
                    platform = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setPlatformsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setPlatformsUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}