public ExtractPropertyBean findExtractPropertyBeanById(int id, String datasetId) { boolean notDone = true; ArrayList<ExtractPropertyBean> epBeans = findExtractProperties(); ExtractPropertyBean returnBean = null; for (ExtractPropertyBean epbean : epBeans) { if (epbean.getId() == id) { epbean.setDatasetId(datasetId); notDone = false; // returnBean = epbean; return epbean; } } return returnBean; }
@RequestMapping("/listCurrentScheduledJobs") public ModelMap listScheduledJobs(HttpServletRequest request, HttpServletResponse response) throws SchedulerException { Locale locale = LocaleResolver.getLocale(request); ResourceBundleProvider.updateLocale(locale); ModelMap gridMap = new ModelMap(); String[] triggerNames; boolean showMoreLink = false; if (request.getParameter("showMoreLink") != null) { showMoreLink = Boolean.parseBoolean(request.getParameter("showMoreLink").toString()); } else { showMoreLink = true; } request.setAttribute("showMoreLink", showMoreLink + ""); // request.setAttribute("studySubjectId",studySubjectId); /*SubjectIdSDVFactory tableFactory = new SubjectIdSDVFactory(); * @RequestParam("studySubjectId") int studySubjectId,*/ request.setAttribute("imagePathPrefix", "../"); ArrayList<String> pageMessages = (ArrayList<String>) request.getAttribute("pageMessages"); if (pageMessages == null) { pageMessages = new ArrayList<String>(); } request.setAttribute("pageMessages", pageMessages); List<JobExecutionContext> listCurrentJobs = new ArrayList<JobExecutionContext>(); listCurrentJobs = scheduler.getCurrentlyExecutingJobs(); Iterator<JobExecutionContext> itCurrentJobs = listCurrentJobs.iterator(); List<String> currentJobList = new ArrayList<String>(); while (itCurrentJobs.hasNext()) { JobExecutionContext temp = itCurrentJobs.next(); currentJobList.add(temp.getTrigger().getJobName() + temp.getTrigger().getGroup()); } String[] triggerGroups = scheduler.getTriggerGroupNames(); List<SimpleTrigger> simpleTriggers = new ArrayList<SimpleTrigger>(); int index1 = 0; for (String triggerGroup : triggerGroups) { logger.debug("Group: " + triggerGroup + " contains the following triggers"); triggerNames = scheduler.getTriggerNames(triggerGroup); for (String triggerName : triggerNames) { int state = scheduler.getTriggerState(triggerName, triggerGroup); logger.debug("- " + triggerName); if (state != Trigger.STATE_PAUSED) { simpleTriggers.add( index1, (SimpleTrigger) scheduler.getTrigger(triggerName, triggerGroup)); index1++; } } } List<ScheduledJobs> jobsScheduled = new ArrayList<ScheduledJobs>(); int index = 0; for (SimpleTrigger st : simpleTriggers) { boolean isExecuting = currentJobList.contains(st.getJobName() + st.getGroup()); ScheduledJobs jobs = new ScheduledJobs(); ExtractPropertyBean epBean = null; if (st.getJobDataMap() != null) { epBean = (ExtractPropertyBean) st.getJobDataMap().get(EP_BEAN); } if (epBean != null) { StringBuilder checkbox = new StringBuilder(); checkbox.append("<input style='margin-right: 5px' type='checkbox'/>"); StringBuilder actions = new StringBuilder("<table><tr><td>"); if (isExecuting) { actions.append(" "); } else { String contextPath = request.getContextPath(); StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='") .append(contextPath) .append("/pages/cancelScheduledJob") .append("';") .append("this.form.theJobName.value='") .append(st.getJobName()) .append("';") .append("this.form.theJobGroupName.value='") .append(st.getJobGroup()) .append("';") .append("this.form.theTriggerName.value='") .append(st.getName()) .append("';") .append("this.form.theTriggerGroupName.value='") .append(st.getGroup()) .append("';") .append("this.form.submit();"); actions .append("<td><input type=\"submit\" class=\"button\" value=\"Cancel Job\" ") .append("name=\"cancelJob\" onclick=\"") .append(jsCodeString.toString()) .append("\" />"); } actions.append("</td></tr></table>"); jobs.setCheckbox(checkbox.toString()); jobs.setDatasetId(epBean.getDatasetName()); String fireTime = st.getStartTime() != null ? longFormat(locale).format(st.getStartTime()) : ""; jobs.setFireTime(fireTime); if (st.getNextFireTime() != null) { jobs.setScheduledFireTime(longFormat(locale).format(st.getNextFireTime())); } jobs.setExportFileName(epBean.getExportFileName()[0]); jobs.setAction(actions.toString()); jobs.setJobStatus(isExecuting ? "Currently Executing" : "Scheduled"); jobsScheduled.add(index, jobs); index++; } } logger.debug("totalRows" + index); request.setAttribute("totalJobs", index); request.setAttribute("jobs", jobsScheduled); TableFacade facade = scheduledJobTableFactory.createTable(request, response); String sdvMatrix = facade.render(); gridMap.addAttribute(SCHEDULED_TABLE_ATTRIBUTE, sdvMatrix); return gridMap; }
private ArrayList<ExtractPropertyBean> findExtractProperties() throws OpenClinicaSystemException { ArrayList<ExtractPropertyBean> ret = new ArrayList<ExtractPropertyBean>(); // ExtractPropertyBean epbean = new ExtractPropertyBean(); int i = 1; while (!getExtractField("extract." + i + ".file").equals("")) { ExtractPropertyBean epbean = new ExtractPropertyBean(); epbean.setId(i); // we will implement a find by id function in the front end // check to make sure the file exists, if not throw an exception and system will abort to // start. checkForFile(getExtractFields("extract." + i + ".file")); epbean.setFileName(getExtractFields("extract." + i + ".file")); // file name of the xslt stylesheet epbean.setFiledescription(getExtractField("extract." + i + ".fileDescription")); // description of the choice of format epbean.setHelpText(getExtractField("extract." + i + ".helptext")); // help text, currently in the alt-text of the link epbean.setLinkText(getExtractField("extract." + i + ".linkText")); // link text of the choice of format // epbean.setRolesAllowed(getExtractField("xsl.allowed." + i).split(",")); // which roles are allowed to see the choice? epbean.setFileLocation(getExtractField("extract." + i + ".location")); // destination of the copied files // epbean.setFormat(getExtractField("xsl.format." + i)); // if (("").equals(epbean.getFormat())) { // } // formatting choice. currently permenantly set at oc1.3 /* * String clinica = getExtractField("extract."+i+".odmType"); if(clinica!=null) { * if(clinica.equalsIgnoreCase("clinical_data")) epbean.setFormat("occlinical_data"); else * epbean.setFormat("oc1.3"); } else */ epbean.setOdmType(getExtractField("extract." + i + ".odmType")); epbean.setFormat("oc1.3"); // destination file name of the copied files epbean.setExportFileName(getExtractFields("extract." + i + ".exportname")); // post-processing event after the creation // System.out.println("found post function: " + whichFunction); String whichFunction = getExtractField("extract." + i + ".post").toLowerCase(); // added by JN: Zipformat comes from extract properties returns true by default epbean.setZipFormat(getExtractFieldBoolean("extract." + i + ".zip")); epbean.setDeleteOld(getExtractFieldBoolean("extract." + i + ".deleteOld")); epbean.setSuccessMessage(getExtractField("extract." + i + ".success")); epbean.setFailureMessage(getExtractField("extract." + i + ".failure")); epbean.setZipName(getExtractField("extract." + i + ".zipName")); if (epbean.getFileName().length != epbean.getExportFileName().length) throw new OpenClinicaSystemException( "The comma seperated values of file names and export file names should correspond 1 on 1 for the property number" + i); if ("sql".equals(whichFunction)) { // set the bean within, so that we can access the file locations etc SqlProcessingFunction function = new SqlProcessingFunction(epbean); String whichSettings = getExtractField("xsl.post." + i + ".sql"); if (!"".equals(whichSettings)) { function.setDatabaseType(getExtractFieldNoRep(whichSettings + ".dataBase").toLowerCase()); function.setDatabaseUrl(getExtractFieldNoRep(whichSettings + ".url")); function.setDatabaseUsername(getExtractFieldNoRep(whichSettings + ".username")); function.setDatabasePassword(getExtractFieldNoRep(whichSettings + ".password")); } else { // set default db settings here function.setDatabaseType(getField("dataBase")); function.setDatabaseUrl(getField("url")); function.setDatabaseUsername(getField("username")); function.setDatabasePassword(getField("password")); } // also pre-set the database connection stuff epbean.setPostProcessing(function); // System.out.println("found db password: "******"pdf".equals(whichFunction)) { // TODO add other functions here epbean.setPostProcessing(new PdfProcessingFunction()); } else if ("sas".equals(whichFunction)) { epbean.setPostProcessing(new SasProcessingFunction()); } else if (!whichFunction.isEmpty()) { String postProcessorName = getExtractField(whichFunction + ".postProcessor"); if (postProcessorName.equals("pdf")) { epbean.setPostProcessing(new PdfProcessingFunction()); epbean.setPostProcDeleteOld(getExtractFieldBoolean(whichFunction + ".deleteOld")); epbean.setPostProcZip(getExtractFieldBoolean(whichFunction + ".zip")); epbean.setPostProcLocation(getExtractField(whichFunction + ".location")); epbean.setPostProcExportName(getExtractField(whichFunction + ".exportname")); } // since the database is the last option TODO: think about custom post processing options else { SqlProcessingFunction function = new SqlProcessingFunction(epbean); function.setDatabaseType(getExtractFieldNoRep(whichFunction + ".dataBase").toLowerCase()); function.setDatabaseUrl(getExtractFieldNoRep(whichFunction + ".url")); function.setDatabaseUsername(getExtractFieldNoRep(whichFunction + ".username")); function.setDatabasePassword(getExtractFieldNoRep(whichFunction + ".password")); epbean.setPostProcessing(function); } } else { // add a null here epbean.setPostProcessing(null); } ret.add(epbean); i++; } // tbh change to print out properties // System.out.println("found " + ret.size() + " records in extract.properties"); return ret; }