List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:com.ibm.xsp.webdav.resource.DAVResourceDominoCategorizedDocuments.java
@SuppressWarnings("unchecked") private void fetchChildrenForNotesDocument() throws NotesException { // LOGGER.info(getCallingMethod()+":"+"Start fetchChildrenForNotesDocument; Fetching children for doc with UNID=" // + this.getDocumentUniqueID()); Document curDoc = null;/* w w w.j av a 2 s. c om*/ String docID = null; Vector<IDAVResource> resMembers = null; this.setMembers(new Vector<IDAVResource>()); String notesURL = this.getInternalAddress(); DAVRepositoryDominoCategorizedDocuments repository = (DAVRepositoryDominoCategorizedDocuments) this .getRepository(); // LOGGER.info("Internal Address is "+notesURL); // LOGGER.info("PublicHref is "+this.getPublicHref()); curDoc = DominoProxy.getDocument(notesURL); // LOGGER.info(getCallingMethod()+":"+"Currdoc not null ; OK"); if (curDoc == null) { LOGGER.error("Could not retrieve the document"); return; } boolean readOnly = this.checkReadOnlyAccess(curDoc); Date curCreationDate = curDoc.getCreated().toJavaDate(); if (curDoc.hasItem("DAVCreated")) { @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVCreated"); Object time = times.elementAt(0); if (time.getClass().getName().endsWith("DateTime")) { curCreationDate = ((DateTime) time).toJavaDate(); } } Date curChangeDate = curDoc.getLastModified().toJavaDate(); if (curDoc.hasItem("DAVModified")) { @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVModified"); Object time = times.elementAt(0); if (time.getClass().getName().endsWith("DateTime")) { curChangeDate = ((DateTime) time).toJavaDate(); } } this.setCreationDate(curCreationDate); this.setLastModified(curChangeDate); this.setReadOnly(readOnly); // Read the repository list to get the view try { LOGGER.info(getCallingMethod() + ":" + "Currdoc not null ; OK; Has UNID=" + curDoc.getUniversalID()); docID = curDoc.getUniversalID(); LOGGER.info(getCallingMethod() + ":" + "Openend document " + docID); // No children if there are no attachments if (!curDoc.hasEmbedded()) { // folder ViewEntryCollection responses = repository .getAllEntriesByKey(curDoc.getItemValueString(repository.getPubHrefField())); LOGGER.info(getCallingMethod() + ":" + "Get Responses..."); int numOfResponses = responses.getCount(); LOGGER.info(getCallingMethod() + ":" + "Current doc has " + String.valueOf(numOfResponses) + " responses"); if (numOfResponses > 1) { resMembers = new Vector<IDAVResource>(numOfResponses - 1); LOGGER.info(getCallingMethod() + ":" + "Start Process responses"); lotus.domino.ViewEntry ve = responses.getFirstEntry(); ve = responses.getNextEntry(); Document docResp = null; while (ve != null) { docResp = ve.getDocument(); // if(docResp.getUniversalID()!=docID){ LOGGER.info(getCallingMethod() + ":" + "Doc response has unid=" + docResp.getUniversalID() + "; Try find attachment(s)"); Vector<String> allEmbedded = DominoProxy.evaluate("@AttachmentNames", docResp); int numOfAttachments = allEmbedded.isEmpty() ? 0 : (allEmbedded.get(0).toString().equals("") ? 0 : allEmbedded.size()); LOGGER.info(getCallingMethod() + ":" + "Doc has " + String.valueOf(numOfAttachments) + " attachment(s)"); if (numOfAttachments == 0) { // No attachments in here! LOGGER.info(getCallingMethod() + ":" + "Doc " + docResp.getUniversalID() + " response has no attachment; is a directory; Create resource for it"); DAVResourceDominoCategorizedDocuments resAtt = new DAVResourceDominoCategorizedDocuments( this.getRepository(), this.getPublicHref() + "/" + docResp.getItemValueString( ((DAVRepositoryDominoCategorizedDocuments) (this.getRepository())) .getDirectoryField()), true); resAtt.setup(docResp); if (resAtt != null) { LOGGER.info(getCallingMethod() + ":" + "Created DavResourceDomino Attachments from getDocumentResource-OK"); if (resAtt.filter()) { this.getMembers().add(resAtt); } resMembers.add(resAtt); LOGGER.info(getCallingMethod() + ":" + "Resource successfull added"); } } else { LOGGER.info(getCallingMethod() + ":" + "Doc response " + docResp.getUniversalID() + " has attachments >0; "); String curAttName = allEmbedded.get(0).toString(); if ((curAttName != null) && (!curAttName.equals(""))) { LOGGER.info(getCallingMethod() + ":" + "Doc response fitrst attachment has name " + curAttName); DAVResourceDominoCategorizedDocuments resAtt = new DAVResourceDominoCategorizedDocuments( this.getRepository(), this.getPublicHref() + "/" + curAttName, true); resAtt.setup(docResp); if (resAtt != null) { // Now add it to the Vector LOGGER.info(getCallingMethod() + ":" + "Created DAVResourceDominoDocuments with getAttachmentResource-OK!\n Start load resource"); // resMembers.add(curAttachment); if (resAtt.filter()) { this.getMembers().add(resAtt); } LOGGER.info(getCallingMethod() + ":" + "Resource successfull added"); Date viewDate = this.getLastModified(); Date docDate = resAtt.getLastModified(); if (viewDate == null || (docDate != null && viewDate.before(docDate))) { this.setLastModified(docDate); } LOGGER.info(getCallingMethod() + ":" + "Resource successfull updated last modified"); LOGGER.info(getCallingMethod() + ":" + "Processing complete attachment:" + curAttName); } } } LOGGER.info(getCallingMethod() + ":" + "Start recycling.."); // Document docTmp=docResp; // } //end // if(docResp.getUniversalID()!=curDoc.getUniversalID()){ ve = responses.getNextEntry(); // docTmp.recycle(); LOGGER.info(getCallingMethod() + ":" + "Recycling OK!"); } // end while } // end if numresp>0 try { LOGGER.info(getCallingMethod() + ":" + "Final recycling.."); if (curDoc != null) { curDoc.recycle(); } LOGGER.info(getCallingMethod() + ":" + "End FINAL recycling OK!"); } catch (Exception e) { LOGGER.error(e); } // Now save back the members to the main object LOGGER.info(getCallingMethod() + ":" + "Finish processing current doc as a directory; No more attachment(s) in it; Return!"); return; } // Get all attachments LOGGER.info(getCallingMethod() + ":" + "Current doc has attachments!"); @SuppressWarnings("rawtypes") Vector allEmbedded = DominoProxy.evaluate("@AttachmentNames", curDoc); int numOfAttchments = allEmbedded.size(); if (numOfAttchments == 0) { // No attachments in here! LOGGER.info(getCallingMethod() + ":" + "Something wrong: Doc + " + docID + " has no attachments (@AttachmentNames)"); return; } LOGGER.info(getCallingMethod() + ":" + docID + " has " + new Integer(numOfAttchments).toString() + " attachment(s)"); // Initialize an empty vector at the right size // We might need to enlarge it if we have more attachments resMembers = new Vector<IDAVResource>(numOfAttchments); LOGGER.info(getCallingMethod() + ":" + "Start processing attachment(s).."); for (int i = 0; i < numOfAttchments; i++) { String curAttName = allEmbedded.get(i).toString(); DAVResourceDominoCategorizedDocuments curAttachment = getDocumentResource(curDoc); if (curAttachment != null) { // Now add it to the Vector LOGGER.info(getCallingMethod() + ":" + "Resource attachment successfully created!"); // resMembers.add(curAttachment); if (curAttachment.filter()) { this.getMembers().add(curAttachment); } LOGGER.info("Resource attachment successfully added: " + curAttName + "; OK!"); } else { LOGGER.error("Could not load attachment#" + curAttName + "#"); } } } catch (NotesException ne) { LOGGER.error(ne); } catch (Exception e) { LOGGER.error(e); } finally { try { LOGGER.info(getCallingMethod() + ":" + "Final block; Start Recycling!"); if (curDoc != null) { curDoc.recycle(); } } catch (Exception e) { LOGGER.error(e); } // Now save back the members to the main object // this.setMembers(resMembers); LOGGER.info("Completed reading attachments resources from Notes document; OK!"); } }
From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java
/** * @param isInitial/* w w w. j a va 2s.c o m*/ */ private void loadData(final boolean isInitial) { label.setText(""); String hostName = properties.getProperty("hostName"); String dbUserName = properties.getProperty("dbUserName"); String dbPassword = properties.getProperty("dbPassword"); int index = 0; List<String> dbNamesList = masterPanel.getDbNamesForMaster(); List<String> otherNamesList = masterPanel.getDbNameList(); if (dbNamesList == null || dbNamesList.size() == 0) { return; } //dbNamesList.clear(); //otherNamesList.clear(); //dbNamesList.add("testfish"); Vector<String> items = new Vector<String>(dbNamesList); Collections.sort(items); if (!isInitial) { index = dbList.getSelectedIndex(); if (index == -1) { return; } } databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); DBMSUserMgr mgr = DBMSUserMgr.getInstance(); do { if (mgr.connect(dbUserName, dbPassword, hostName, databaseName)) { if (isInitial) { HashSet<String> dbNameHashSet = new HashSet<String>(); DefaultListModel model = new DefaultListModel(); for (String nm : items) { model.addElement(nm); dbNameHashSet.add(nm); } dbList.setModel(model); model = new DefaultListModel(); for (String nm : otherNamesList) { if (!dbNameHashSet.contains(nm)) { model.addElement(nm); } } otherDBList.setModel(model); } label.setText(getFormattedResStr("MSTR_USR_DB", databaseName)); if (!mgr.doesDBHaveTable(databaseName, "specifyuser")) { items.remove(0); databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); continue; } Vector<UserData> userDataList = new Vector<UserData>(); String sql = "SELECT SpecifyUserId, Name, Password, EMail FROM specifyuser"; Vector<Object[]> data = BasicSQLUtils.query(mgr.getConnection(), sql); for (Object[] c : data) { UserData ud = new UserData((Integer) c[0], (String) c[1], (String) c[2], "(On user's machine)", (String) c[3]); userDataList.add(ud); sql = String.format( "SELECT LastName, FirstName, EMail FROM agent WHERE SpecifyUserID = %d ORDER BY TimestampModified, TimestampCreated LIMIT 0,1", ud.getId()); Vector<Object[]> uData = BasicSQLUtils.query(mgr.getConnection(), sql); if (uData.size() > 0) { Object[] d = uData.get(0); ud.setLastName((String) d[0]); ud.setFirstName((String) d[1]); String email = (String) d[2]; if (StringUtils.isNotEmpty(email) && StringUtils.isEmpty(ud.getEmail())) { ud.setEmail(email); } } else { // error } } mgr.close(); userModel.setUserData(userDataList); UIHelper.calcColumnWidths(userTable); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Window window = getTopWindow(); Insets screenInsets = Toolkit.getDefaultToolkit() .getScreenInsets(window.getGraphicsConfiguration()); Rectangle screenRect = window.getGraphicsConfiguration().getBounds(); screenRect.height -= screenInsets.top + screenInsets.bottom; screenRect.width -= screenInsets.left + screenInsets.right; Rectangle rect = window.getBounds(); Dimension size = window.getPreferredSize(); // Make sure the window isn't larger than the screen size.width = Math.min(size.width, screenRect.width); size.height = Math.min(size.height, screenRect.height); if (size.height > rect.height || size.width > rect.width) { window.setBounds(rect.x, rect.y, size.width, size.height); UIHelper.centerWindow(getTopWindow()); } } }); if (isInitial && items.size() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dbList.setSelectedIndex(0); } }); } break; } else if (items.size() > 1) { items.remove(0); databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); } else { break; } } while (true); }
From source file:com.ichi2.libanki.Stats.java
/** * Answer Buttons/* www. j a v a 2 s . c om*/ */ public boolean calculateAnswerButtons(int type) { mHasColoredCumulative = true; mTitle = R.string.stats_answer_buttons; mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage }; mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_young, R.string.statistics_mature }; mColors = new int[] { R.color.stats_learn, R.color.stats_young, R.color.stats_mature }; mType = type; String lim = _revlogLimit().replaceAll("[\\[\\]]", ""); Vector<String> lims = new Vector<String>(); int days = 0; if (lim.length() > 0) lims.add(lim); if (type == TYPE_MONTH) days = 30; else if (type == TYPE_YEAR) days = 365; else days = -1; if (days > 0) lims.add("id > " + ((mCol.getSched().getDayCutoff() - (days * 86400)) * 1000)); if (lims.size() > 0) { lim = "where " + lims.get(0); for (int i = 1; i < lims.size(); i++) lim += " and " + lims.get(i); } else lim = ""; ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "select (case " + " when type in (0,2) then 0 " + " when lastIvl < 21 then 1 " + " else 2 end) as thetype, " + " (case when type in (0,2) and ease = 4 then 3 else ease end), count() from revlog " + lim + " " + " group by thetype, ease " + " order by thetype, ease"; Timber.d("AnswerButtons query: %s", query); try { cur = mCol.getDb().getDatabase().rawQuery(query, null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for AnswerButton, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine if (list.size() == 0) { list.add(0, new double[] { 0, 1, 0 }); } double[] totals = new double[3]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int currentType = (int) data[0]; double ease = data[1]; double cnt = data[2]; totals[currentType] += cnt; } int badNew = 0; int badYoung = 0; int badMature = 0; mSeriesList = new double[4][list.size() + 1]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int currentType = (int) data[0]; double ease = data[1]; double cnt = data[2]; if (currentType == 1) ease += 5; else if (currentType == 2) ease += 10; if ((int) ease == 1) { badNew = i; } if ((int) ease == 6) { badYoung = i; } if ((int) ease == 11) { badMature = i; } mSeriesList[0][i] = ease; mSeriesList[1 + currentType][i] = cnt; if (cnt > mMaxCards) mMaxCards = (int) cnt; } mSeriesList[0][list.size()] = 15; mCumulative = new double[4][]; mCumulative[0] = mSeriesList[0]; mCumulative[1] = createCumulativeInPercent(mSeriesList[1], totals[0], badNew); mCumulative[2] = createCumulativeInPercent(mSeriesList[2], totals[1], badYoung); mCumulative[3] = createCumulativeInPercent(mSeriesList[3], totals[2], badMature); mFirstElement = 0.5; mLastElement = 14.5; mMcount = 100; mMaxElements = 15; //bars are positioned from 1 to 14 if (mMaxCards == 0) mMaxCards = 10; return list.size() > 0; }
From source file:com.ibm.xsp.webdav.resource.DAVResourceDominoDocuments.java
@SuppressWarnings("unchecked") private void fetchChildrenForNotesDocument() throws NotesException { // LOGGER.info(getCallingMethod()+":"+"Start fetchChildrenForNotesDocument; Fetching children for doc with UNID=" // + this.getDocumentUniqueID()); Document curDoc = null;//from w ww. ja v a 2s. co m // String docID = null; Vector<IDAVResource> resMembers = new Vector<IDAVResource>(); this.setMembers(resMembers); String notesURL = this.getInternalAddress(); // LOGGER.info("Internal Address is "+notesURL); // LOGGER.info("PublicHref is "+this.getPublicHref()); curDoc = DominoProxy.getDocument(notesURL); // LOGGER.info(getCallingMethod()+":"+"Currdoc not null ; OK"); if (curDoc == null) { LOGGER.error("Could not retrieve the document"); return; } boolean readOnly = this.checkReadOnlyAccess(curDoc); Date curCreationDate = curDoc.getCreated().toJavaDate(); if (curDoc.hasItem("DAVCreated")) { @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVCreated"); Object time = times.elementAt(0); if (time.getClass().getName().endsWith("DateTime")) { curCreationDate = ((DateTime) time).toJavaDate(); } } Date curChangeDate = curDoc.getLastModified().toJavaDate(); if (curDoc.hasItem("DAVModified")) { @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVModified"); Object time = times.elementAt(0); if (time.getClass().getName().endsWith("DateTime")) { curChangeDate = ((DateTime) time).toJavaDate(); } } this.setCreationDate(curCreationDate); this.setLastModified(curChangeDate); this.setReadOnly(readOnly); // Read the repository list to get the view try { // LOGGER.info(getCallingMethod()+":"+"Currdoc not null ; OK; Has UNID="+curDoc.getUniversalID()); // docID = curDoc.getUniversalID(); // LOGGER.info(getCallingMethod()+":"+"Openend document " + docID); // No children if there are no attachments if (!curDoc.hasEmbedded()) { // if(1==1){return;} // E.C. It is a directory, so fetch the children documents as // resources // LOGGER.info(getCallingMethod()+":"+"Current doc with unid="+curDoc.getUniversalID()+" has no embedded files. Try to find children"); DocumentCollection responses = curDoc.getResponses(); // LOGGER.info(getCallingMethod()+":"+"Get Responses..."); int numOfResponses = responses.getCount(); // LOGGER.info(getCallingMethod()+":"+"Current doc has "+String.valueOf(numOfResponses) // + " responses"); if (numOfResponses > 0) { resMembers = new Vector<IDAVResource>(numOfResponses); // LOGGER.info(getCallingMethod()+":"+"Start Process responses"); Document docResp = responses.getFirstDocument(); while (docResp != null) { // LOGGER.info(getCallingMethod()+":"+"Doc response has unid="+docResp.getUniversalID()+ // "; Try find attachment(s)"); Vector<String> allEmbedded = DominoProxy.evaluate("@AttachmentNames", docResp); int numOfAttachments = allEmbedded.isEmpty() ? 0 : (allEmbedded.get(0).toString().equals("") ? 0 : allEmbedded.size()); // LOGGER.info(getCallingMethod()+":"+"Doc has "+ // String.valueOf(numOfAttachments)+" attachment(s)"); if (numOfAttachments == 0) { // No attachments in here! // LOGGER.info(getCallingMethod()+":"+"Doc "+docResp.getUniversalID()+" response has no attachment; is a directory; Create resource for it"); DAVResourceDominoDocuments resAtt = new DAVResourceDominoDocuments(this.getRepository(), this.getPublicHref() + "/" + docResp.getItemValueString( ((DAVRepositoryDominoDocuments) (this.getRepository())) .getDirectoryField()), true); resAtt.setup(docResp); LOGGER.info(getCallingMethod() + ":" + "Created DavResourceDomino Attachments from getDocumentResource-OK"); this.getMembers().add(resAtt); // resMembers.add(resAtt); LOGGER.info(getCallingMethod() + ":" + "Resource successfull added"); } else { // LOGGER.info(getCallingMethod()+":"+"Doc response "+docResp.getUniversalID()+" has attachments >0; "); String curAttName = allEmbedded.get(0).toString(); if ((curAttName != null) && (!curAttName.equals(""))) { // LOGGER.info(getCallingMethod()+":"+"Doc response fitrst attachment has name "+curAttName); DAVResourceDominoDocuments resAtt = new DAVResourceDominoDocuments( this.getRepository(), this.getPublicHref() + "/" + curAttName, true); resAtt.setup(docResp); if (resAtt != null) { // Now add it to the Vector // LOGGER.info(getCallingMethod()+":"+"Created DAVResourceDominoDocuments with getAttachmentResource-OK!\n Start load resource"); // resMembers.add(curAttachment); this.getMembers().add(resAtt); // LOGGER.info(getCallingMethod()+":"+"Resource successfull added"); Date viewDate = this.getLastModified(); Date docDate = resAtt.getLastModified(); if (viewDate == null || (docDate != null && viewDate.before(docDate))) { this.setLastModified(docDate); } LOGGER.info(getCallingMethod() + ":" + "Resource successfull updated last modified"); // LOGGER.info(getCallingMethod()+":"+"Processing complete attachment:" // + curAttName); } } } // LOGGER.info(getCallingMethod()+":"+"Start recycling.."); docResp = responses.getNextDocument(docResp); // LOGGER.info(getCallingMethod()+":"+"Recycling OK!"); } // end while } // end if numresp>0 try { // LOGGER.info(getCallingMethod()+":"+"Final recycling.."); if (curDoc != null) { // curDoc.recycle(); } // LOGGER.info(getCallingMethod()+":"+"End FINAL recycling OK!"); } catch (Exception e) { LOGGER.error(e); } // Now save back the members to the main object // LOGGER.info(getCallingMethod()+":"+"Finish processing current doc as a directory; No more attachment(s) in it; Return!"); return; } // Get all attachments // LOGGER.info(getCallingMethod()+":"+"Current doc has attachments!"); @SuppressWarnings("rawtypes") Vector allEmbedded = DominoProxy.evaluate("@AttachmentNames", curDoc); int numOfAttchments = allEmbedded.size(); if (numOfAttchments == 0) { // No attachments in here! // LOGGER.info(getCallingMethod()+":"+"Something wrong: Doc + "+docID // + " has no attachments (@AttachmentNames)"); return; } // LOGGER.info(getCallingMethod()+":"+docID + " has " + new // Integer(numOfAttchments).toString() + " attachment(s)"); // Initialize an empty vector at the right size // We might need to enlarge it if we have more attachments resMembers = new Vector<IDAVResource>(numOfAttchments); // LOGGER.info(getCallingMethod()+":"+"Start processing attachment(s).."); for (int i = 0; i < numOfAttchments; i++) { String curAttName = allEmbedded.get(i).toString(); DAVResourceDominoDocuments curAttachment = getDocumentResource(curDoc); if (curAttachment != null) { // Now add it to the Vector // LOGGER.info(getCallingMethod()+":"+"Resource attachment successfully created!"); // resMembers.add(curAttachment); this.getMembers().add(curAttachment); // LOGGER.info("Resource attachment successfully added: " + // curAttName+"; OK!"); } else { LOGGER.error("Could not load attachment#" + curAttName + "#"); } } } catch (NotesException ne) { LOGGER.error(ne); } catch (Exception e) { LOGGER.error(e); } finally { try { // LOGGER.info(getCallingMethod()+":"+"Final block; Start Recycling!"); if (curDoc != null) { // curDoc.recycle(); } } catch (Exception e) { LOGGER.error(e); } // Now save back the members to the main object // this.setMembers(resMembers); // LOGGER.info("Completed reading attachments resources from Notes document; OK!"); } }
From source file:com.jsystem.j2autoit.AutoItAgent.java
public Map<String, Comparable<?>> executeAutoitFile(String fullPath, String workDir, String autoItLocation, int timeout, Vector<Object> params) { Exception threwOne = null;/*from ww w . j a v a 2 s . c om*/ Hashtable<String, Comparable<?>> result = new Hashtable<String, Comparable<?>>(); File sfile = new File(fullPath); if (!sfile.exists()) { System.out.println(agentWorkDir.getAbsolutePath()); System.out.println("Couldn't find " + sfile); return result; } Command cmd = new Command(); cmd.setTimeout(timeout); String[] commandParams = new String[3 + params.size()]; commandParams[0] = getAutoExecuterItLocation(autoItLocation); ; commandParams[1] = "/ErrorStdOut"; commandParams[2] = sfile.getAbsolutePath(); Log.info("Parameters:\n"); for (int index = 0; index < params.size(); index++) { Log.info(params.get(index).toString() + NEW_LINE); commandParams[index + 3] = params.get(index).toString(); } cmd.setCmd(commandParams); File workingDirectory = new File(workDir); cmd.setDir(workingDirectory.exists() ? workingDirectory : agentWorkDir); try { Execute.execute(cmd, true); } catch (Exception e) { threwOne = e; } Log.info(" \n"); Log.info(" \n"); String scriptText = ""; try { scriptText = FileUtils.read(sfile); Pattern pattern = Pattern.compile("^Local \\$var = ([\\w\\d\\p{Punct} ]+)$", Pattern.MULTILINE); Matcher matcher = pattern.matcher(scriptText); if (matcher.find()) { Log.info("AutoIt Command : " + matcher.group(matcher.groupCount()) + NEW_LINE); } } catch (IOException ioException) { Log.throwable(ioException.getMessage(), ioException); } String stdoutText = cmd.getStdout().toString(); int returnCodeValue = cmd.getReturnCode(); String stderrText = cmd.getStderr().toString(); if (isUseScreenShot || threwOne != null || !stderrText.isEmpty()) { String windowName = UUID.randomUUID().toString(); new ScreenShotThread(windowName).start(); Log.infoLog("A screenshot with the uuid : " + windowName + NEW_LINE); } Log.messageLog(SCRIPT + ":\n" + scriptText + NEW_LINE); Log.messageLog(STDOUT + ":\n" + stdoutText + NEW_LINE); Log.messageLog(RETURN + ":\n" + returnCodeValue + NEW_LINE); Log.messageLog(STDERR + ":\n" + stderrText + NEW_LINE); result.put(SCRIPT, scriptText); result.put(STDOUT, stdoutText); result.put(RETURN, returnCodeValue); result.put(STDERR, stderrText); if (isDebug) { if (isAutoDeleteFiles) { HistoryFile.addFile(sfile); Log.infoLog("Adding " + sfile.getAbsolutePath() + " to \"For deletion files list\"\n"); } } else { sfile.deleteOnExit(); } return result; }
From source file:eionet.gdem.dcm.business.SchemaManager.java
/** * Get XML Schema and related stylesheets information. * @param schema XML Schema URL or database ID. * @return StylesheetListHolder object holding schema stylesheet and user permission information * @throws DCMException in case of database error occurs. *//*from ww w . j a va2 s . c om*/ public StylesheetListHolder getSchemaStylesheetsList(String schema) throws DCMException { StylesheetListHolder st = new StylesheetListHolder(); ArrayList<Schema> schemas; try { schemas = new ArrayList<Schema>(); String schemaId = schemaDao.getSchemaID(schema); if (schemaId == null) { st.setHandcoded(false); } else { st.setHandcoded(true); } ConversionServiceIF cs = new ConversionService(); Vector stylesheets = cs.listConversions(schema); ArrayList<Stylesheet> stls = new ArrayList<Stylesheet>(); Schema sc = new Schema(); sc.setId(schemaId); sc.setSchema(schema); for (int i = 0; i < stylesheets.size(); i++) { Hashtable hash = (Hashtable) stylesheets.get(i); String xsl = (String) hash.get("xsl"); String type; String lastModified = ""; boolean ddConv = false; String xslUrl; if (!xsl.startsWith(Properties.gdemURL + "/do/getStylesheet?id=")) { File f = new File(Properties.xslFolder + File.separatorChar + xsl); if (f != null && f.exists()) { lastModified = Utils.getDateTime(new Date(f.lastModified())); } // DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(f.lastModified())); xslUrl = Names.XSL_FOLDER + (String) hash.get("xsl"); type = (String) hash.get("result_type"); } else { xslUrl = (String) hash.get("xsl"); ddConv = true; type = (String) hash.get("result_type"); } Stylesheet stl = new Stylesheet(); // st.setConvId(1); stl.setType(type); stl.setXsl(xslUrl); stl.setXslFileName(xsl); stl.setDescription((String) hash.get("description")); stl.setModified(lastModified); stl.setConvId((String) hash.get("convert_id")); stl.setDdConv(ddConv); stls.add(stl); } if (stls.size() > 0) { sc.setStylesheets(stls); } schemas.add(sc); st.setHandCodedStylesheets(schemas); } catch (Exception e) { LOGGER.debug("Errror getting schema stylesheets", e); throw new DCMException(BusinessConstants.EXCEPTION_GENERAL); } return st; }
From source file:gov.nih.nci.caintegrator.analysis.server.GeneralizedLinearModelTaskR.java
public void run() { logger.debug("starting glm with " + this.getDebugRcommands()); GeneralizedLinearModelRequest glmRequest = (GeneralizedLinearModelRequest) getRequest(); glmResult = new GeneralizedLinearModelResult(glmRequest.getSessionId(), glmRequest.getTaskId()); logger.info(getExecutingThreadName() + ": processing generalized linear model request=" + glmRequest); // Validate that all the groups are correct and not overlapping List<GLMSampleGroup> groups = glmRequest.getComparisonGroups(); //groups.add((GLMSampleGroup) glmRequest.getBaselineGroup()); boolean errorCondition = false; SampleGroup idsSeen = new SampleGroup(); String errorMsg = null;/* w w w . ja v a2 s . c o m*/ for (SampleGroup group : groups) { if (group.size() < 2) { errorMsg = "Group: " + group.getGroupName() + " has less than two members. Sending exception."; logger.error(errorMsg); errorCondition = true; break; } if (idsSeen.containsAny(group)) { errorMsg = "Group: " + group.getGroupName() + " contains overlapping ids. Sending exception."; logger.error(errorMsg); errorCondition = true; break; } idsSeen.addAll(group); } if (errorCondition) { AnalysisServerException ex = new AnalysisServerException( "One or more groups have overlapping members or contain less than 3 entries."); ex.setFailedRequest(glmRequest); logger.error("Groups have overlapping members or less than 3 entries."); setException(ex); return; } // set the data file // check to see if the data file on the compute connection is the // same as that for the analysis task try { setDataFile(glmRequest.getDataFileName()); } catch (AnalysisServerException e) { e.setFailedRequest(glmRequest); logger.error("Internal Error. Error setting data file to fileName for generalized linear model =" + glmRequest.getDataFileName()); setException(e); return; } // Execute the tasks to perform the GLM analysis try { SampleGroup baselineGroup = glmRequest.getBaselineGroup(); List<GLMSampleGroup> sampleGroups = glmRequest.getComparisonGroups(); String glmPatients = "GLMPATIENTS"; String glmGroups = "GLMGROUPS"; logger.debug("building"); List<String> allPatients = null; allPatients = createPatientList(baselineGroup, sampleGroups); String groupPatientCmd = getGlmPatientGroupCommand(glmPatients, allPatients); String groupNameCommand = getGlmGroupNameCommand(glmGroups, allPatients, baselineGroup, sampleGroups); logger.debug("about to invoke r"); doRvoidEval(groupPatientCmd); doRvoidEval(groupNameCommand); logger.debug("invoking r"); // Filter by gene variance to invrease performance Double geneVariance = glmRequest.getGeneVariance(); String varianceCommand = "subMatrix<-GeneFilterVariance(dataMatrix," + geneVariance.toString() + ")"; doRvoidEval(varianceCommand); String glmCommand = null; String commandName = null; StatisticalMethodType method = glmRequest.getStatisticalMethod(); if (StatisticalMethodType.ANOVA.equals(method)) { commandName = "eagle.anova.array"; } else if (StatisticalMethodType.GLM.equals(method)) { commandName = "eagle.glm.array"; } else { throw new AnalysisServerException("Invalid Statistical Method"); } List<CoVariateType> coVariateTypes = glmRequest.getCoVariateTypes(); if (coVariateTypes == null || coVariateTypes.size() == 0) { glmCommand = "glmResult<-" + commandName + "(subMatrix, " + glmPatients + ", " + glmGroups + ", FALSE, " + "null" + ")"; } else { String matrixName = constructDataMatrix(allPatients, (GLMSampleGroup) baselineGroup, sampleGroups); glmCommand = "glmResult<-" + commandName + "(subMatrix, " + glmPatients + ", " + glmGroups + ", TRUE, " + matrixName + ")"; } doRvoidEval(glmCommand); // get the labels Vector reporterIds = doREval("glmReporters <- dimnames(glmResult)[[1]]").asVector(); List<SampleGroup> resultSampleGroups = new ArrayList<SampleGroup>(); if (glmRequest.getComparisonGroups().size() < 2 && (glmRequest.getCoVariateTypes() == null || glmRequest.getCoVariateTypes().size() < 1)) { String groupId = doREval("glmGroups <- dimnames(glmResult)[[2]]").asString(); resultSampleGroups.add(new SampleGroup(groupId)); } else { Vector groupIds = new Vector(); groupIds = doREval("glmGroups <- dimnames(glmResult)[[2]]").asVector(); for (Object groupId : groupIds) { resultSampleGroups.add(new SampleGroup(((REXP) groupId).asString())); } } glmResult.setSampleGroups(resultSampleGroups); List<GeneralizedLinearModelResultEntry> entries = new ArrayList<GeneralizedLinearModelResultEntry>(); for (int i = 0; i < reporterIds.size(); i++) { GeneralizedLinearModelResultEntry entry = new GeneralizedLinearModelResultEntry(); String reporter = ((REXP) reporterIds.get(i)).asString(); entry.setReporterId(reporter); double[] pvals = doREval("pval <- glmResult[" + (i + 1) + ",]").asDoubleArray(); entry.setGroupPvalues(pvals); entries.add(entry); } glmResult.setGlmResultEntries(entries); logger.debug("reporterIds.size=" + reporterIds.size()); logger.debug("groupIds.size=" + resultSampleGroups.size()); // glmResult.setSampleGroups(sampleGroups); } catch (AnalysisServerException asex) { AnalysisServerException aex = new AnalysisServerException( "Problem computing GLM. Caught AnalysisServerException in FTestTaskR." + asex.getMessage()); aex.setFailedRequest(glmRequest); setException(aex); logger.error("Caught AnalysisServerException in GLM"); logStackTrace(logger, asex); return; } catch (Exception ex) { AnalysisServerException asex = new AnalysisServerException( "Internal Error. Caught Exception in GLM exClass=" + ex.getClass() + " msg=" + ex.getMessage()); asex.setFailedRequest(glmRequest); setException(asex); logger.error("Caught Exception in GLM"); logStackTrace(logger, ex); return; } }
From source file:com.ibm.xsp.webdav.resource.DAVResourceDominoDocuments.java
@SuppressWarnings("deprecation") private void setup(Document curDoc) { try {//from w ww. ja v a2s .c om // LOGGER.info(getCallingMethod()+":"+"Start setup..."); @SuppressWarnings("rawtypes") Vector allEmbedded = DominoProxy.evaluate("@AttachmentNames", curDoc); // LOGGER.info(getCallingMethod()+":"+"All Embedded computed"); int numOfAttachments = allEmbedded.isEmpty() ? 0 : (allEmbedded.get(0).equals("") ? 0 : allEmbedded.size()); String docID = curDoc.getUniversalID(); this.setDocumentUniqueID(docID); // LOGGER.info("Num of attachments="+new // Integer(numOfAttachments).toString()); boolean readOnly = this.checkReadOnlyAccess(curDoc); this.setReadOnly(readOnly); LOGGER.info("Creation date for " + curDoc.getUniversalID() + " =" + curDoc.getCreated().toString() + "; Time zone=" + curDoc.getCreated().getZoneTime() + "; Local time=" + curDoc.getCreated().getLocalTime()); Date curCreationDate = curDoc.getCreated().toJavaDate(); LOGGER.info("Current date in Java is " + curCreationDate.toString() + "Time zone=" + new Integer(curCreationDate.getTimezoneOffset()).toString() + "; Locale time is:" + curCreationDate.toLocaleString()); if (curDoc.hasItem("DAVCreated")) { // Item davCreated=curDoc.getFirstItem("DAVCreated"); @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVCreated"); if (times != null) { if (times.size() > 0) { Object time = times.elementAt(0); if (time != null) { if (time.getClass().getName().endsWith("DateTime")) { curCreationDate = ((DateTime) time).toJavaDate(); if (curCreationDate == null) { curCreationDate = curDoc.getCreated().toJavaDate(); } } } } } } Date curChangeDate = curDoc.getLastModified().toJavaDate(); if (curDoc.hasItem("DAVModified")) { @SuppressWarnings("rawtypes") Vector times = curDoc.getItemValueDateTimeArray("DAVModified"); if (times != null) { if (times.size() > 0) { Object time = times.elementAt(0); if (time != null) { if (time.getClass().getName().endsWith("DateTime")) { curChangeDate = ((DateTime) time).toJavaDate(); if (curChangeDate == null) { curChangeDate = curDoc.getLastModified().toJavaDate(); } } } } } } this.setCreationDate(curCreationDate); this.setLastModified(curChangeDate); LOGGER.info("Creation date is set to " + this.getCreationDate().toString()); LOGGER.info("Last modified date is set to " + this.getLastModified().toString()); String pubHRef = ((IDAVAddressInformation) this.getRepository()).getPublicHref(); // LOGGER.info("THIS getpublichref="+this.getPublicHref()); String curAttName = null; if (numOfAttachments == 0) { // LOGGER.info(getCallingMethod()+":"+"Start setting resource"); this.setName(docID); String name = curDoc.getItemValueString( ((DAVRepositoryDominoDocuments) (this.getRepository())).getDirectoryField()); this.setName(name); if (this.getPublicHref().equals("")) { // try{ this.setPublicHref(pubHRef + "/" + name); // URLEncoder.encode(name, "UTF-8")); // }catch(UnsupportedEncodingException e){ // LOGGER.error(e); // } } this.setCollection(true); this.setInternalAddress( ((IDAVAddressInformation) this.getRepository()).getInternalAddress() + "/" + docID); this.setResourceType("NotesDocument"); this.setMember(false); this.setContentLength(0L); // this.fetchChildren(); } else { curAttName = allEmbedded.get(0).toString(); // LOGGER.info("Attachment name is "+curAttName); this.setMember(true); this.setResourceType("NotesAttachment"); if (this.getPublicHref().equals("")) { try { this.setPublicHref(pubHRef + "/" + URLEncoder.encode(curAttName, "UTF-8")); } catch (UnsupportedEncodingException e) { LOGGER.error(e); } // this.setPublicHref( pubHRef+"/"+curAttName); } this.setInternalAddress(((IDAVAddressInformation) this.getRepository()).getInternalAddress() + "/" + docID + "/$File/" + curAttName); this.setCollection(false); this.setName(curAttName); EmbeddedObject curAtt = curDoc.getAttachment(curAttName); if (curAtt == null) { // LOGGER.info("Error! Current Embedded is null"); return; } else { // LOGGER.info("Embedded is not null. OK! "); } Long curSize = new Long(curAtt.getFileSize()); this.setContentLength(curSize); } // LOGGER.info("Current res realized! pubHREF="+this.getPublicHref()+"; Internal Address="+this.getInternalAddress()+"; "); } catch (NotesException ne) { LOGGER.error("ERROR! Can not set; " + ne.getMessage()); } }
From source file:edu.ku.brc.specify.config.Scriptlet.java
/** * Retrieves info about agents associated with interactions tables. * See getByLoanAgentRole for example of usage. * // w w w. j av a 2 s . c o m * @param transTbl the name of the interaction table * @param transNumberFld the name of the visible id for the table * @param transNumber the current value of transNumberFld * @param roleTbl the name of the role table * @param role - the current role * @param fld - the field to retrieve. e.g. "Remarks", "agent.LastName", * "address.City". * @return the value of 'fld' for the given value of transNumber and role. * @throws Exception */ public String getByRole(final String transTbl, final String transNumberFld, final String transNumber, final String roleTbl, final String role, final String fld) throws Exception { String fldTbl = roleTbl; String fldName = fld; String[] chunks = fld.split("\\."); if (chunks.length > 1) { fldTbl = chunks[0]; fldName = chunks[1]; } if (!fldTbl.equals("address") && !fldTbl.equals("agent") && !fldTbl.equals(roleTbl)) { throw new Exception("unsupported table: " + fldTbl); } DBTableInfo transInfo = DBTableIdMgr.getInstance().getInfoByTableName(transTbl); if (transInfo == null) { throw new Exception("unrecognized table: " + transTbl); } if (transInfo.getFieldByColumnName(transNumberFld, true) == null) { throw new Exception("unrecognized field: " + transTbl + "." + transNumberFld); } DBTableInfo tblInfo = DBTableIdMgr.getInstance().getInfoByTableName(fldTbl); if (tblInfo == null) { throw new Exception("unrecognized table: " + roleTbl); } if (tblInfo.getFieldByColumnName(fldName, true) == null) { throw new Exception("unrecognized field: " + fldTbl + "." + fldName); } //hoping that roleTbl's foreign key name is the same as transTbl's primaryKey //could/should use relationship info String sql = "select " + fldTbl + "." + fldName + " from " + transTbl + " inner join " + roleTbl + " on " + roleTbl + "." + transInfo.getPrimaryKeyName() + " = " + transTbl + "." + transInfo.getPrimaryKeyName(); if (!fldTbl.equals(roleTbl)) { sql += " inner join agent on agent.AgentID = " + roleTbl + ".AgentID"; //But which address? ... Current?, Primary?, Shipping? ?? if (!fldTbl.equals("agent")) { sql += " inner join address on address.AgentID = agent.AgentID"; } } //Also assuming the name of the 'Role' field sql += " where " + transTbl + "." + transNumberFld + " = '" + transNumber + "' and " + roleTbl + ".Role = '" + role + "'"; Vector<Object> match = BasicSQLUtils.querySingleCol(sql); if (match == null || match.size() == 0) { return ""; } return match.get(0) == null ? "" : match.get(0).toString(); }
From source file:edu.ku.brc.specify.toycode.RegPivot.java
/** * @param hash/*w w w . j av a 2 s .c o m*/ * @param recordType * @param pStmt * @param dbFieldTypes * @param dbFieldNames * @param inxToName * @throws SQLException */ private void writeHash(final HashMap<String, HashMap<String, Object>> hash, final Integer recordType, final PreparedStatement pStmt, final Vector<Integer> dbFieldTypes, final Vector<String> dbFieldNames, final HashMap<Integer, String> inxToName) throws SQLException { int totalCnt = hash.size(); int cnt = 0; for (String idKey : hash.keySet()) { cnt++; if (cnt % 500 == 0) System.out.println(cnt + " / " + totalCnt); HashMap<String, Object> nameToVals = hash.get(idKey); if (recordType != null) { pStmt.setInt(dbFieldNames.size() + 1, (Integer) recordType); } for (int i = 0; i < dbFieldNames.size(); i++) { int fInx = i + 1; String name = inxToName.get(i); Object value = nameToVals.get(name); pStmt.setObject(fInx, null); int typ = dbFieldTypes.get(i); if (value != null) { if (value instanceof Integer) { pStmt.setInt(fInx, (Integer) value); } else if (value instanceof String) { pStmt.setString(fInx, (String) value); } else if (value instanceof Timestamp) { pStmt.setTimestamp(fInx, (Timestamp) value); } else { System.err.println("Unhandled class: " + value.getClass().getName()); } } else { pStmt.setObject(fInx, null); } } pStmt.executeUpdate(); } }