List of usage examples for org.apache.commons.lang.time DateFormatUtils format
public static String format(Date date, String pattern)
Formats a date/time into a specific pattern.
From source file:org.isatools.isatab.export.sra.SraExporter.java
/** * Builds the SRA study from the ISATAB study, assuming this has some ENA assays. * * @return the SRA STUDY element that is to be used to build the corresponding XML study file. */// www. j a v a2 s . co m private STUDYDocument buildExportedStudy(Study study) { final String studyAcc = study.getAcc(); final Investigation investigation = study.getUniqueInvestigation(); STUDYDocument xstudyDoc = STUDYDocument.Factory.newInstance(); StudyType xstudy = StudyType.Factory.newInstance(); xstudy.setAlias(studyAcc); StudyType.DESCRIPTOR xdescriptor = StudyType.DESCRIPTOR.Factory.newInstance(); String description = StringUtils.trimToNull(study.getDescription()); // TODO: constant class // Commented out, need to add a test checking if there is a BII accession number //String backLink = StringUtils.trimToNull(System.getProperty("bioinvindex.converters.sra.backlink", null)); //if (backLink != null) { // backLink = backLink.replaceAll("\\$\\{study-acc\\}", studyAcc); // description = backLink + (description == null ? "" : " ") + description; //} xdescriptor.setCENTERNAME(centerName); xstudy.setCenterName(centerName); xstudy.setBrokerName(brokerName); String centerPrjName = StringUtils .trimToNull(study.getSingleAnnotationValue("comment:SRA Center Project Name")); if (centerPrjName == null) { throw new TabMissingValueException(MessageFormat.format( "The study ''{0}'' has no 'SRA Center Project Name', cannot export to SRA format", study.getAcc())); } xdescriptor.setCENTERPROJECTNAME(centerPrjName); // TODO: remove, it's deprecated. // String prjId = StringUtils.trimToNull ( study.getSingleAnnotationValue ( "comment:SRA Project ID" ) ); // if ( centerPrjName == null ) // throw new TabMissingValueException ( MessageFormat.format ( // "The study ''{0}'' has no 'SRA Project ID', cannot export to SRA format", // study.getAcc () // )); // xdescriptor.setPROJECTID ( new BigInteger ( prjId ) ); String title = StringUtils.trimToNull(study.getTitle()); if (title != null) { xdescriptor.setSTUDYTITLE(title); } STUDYATTRIBUTES xattrs = STUDYATTRIBUTES.Factory.newInstance(); STUDYLINKS xlinks = STUDYLINKS.Factory.newInstance(); Date subDate = study.getSubmissionDate(); if (subDate != null) { AttributeType xdate = buildStudyAttribute("Submission Date", DateFormatUtils.format(subDate, "dd/MM/yyyy"), null); xattrs.addNewSTUDYATTRIBUTE(); xattrs.setSTUDYATTRIBUTEArray(xattrs.sizeOfSTUDYATTRIBUTEArray() - 1, xdate); } Date relDate = study.getReleaseDate(); if (relDate != null) { AttributeType xdate = buildStudyAttribute("Release Date", DateFormatUtils.format(relDate, "dd/MM/yyyy"), null); xattrs.addNewSTUDYATTRIBUTE(); xattrs.setSTUDYATTRIBUTEArray(xattrs.sizeOfSTUDYATTRIBUTEArray() - 1, xdate); } { AttributeType xacc = buildStudyAttribute("BII Study Accession", studyAcc, null); xattrs.addNewSTUDYATTRIBUTE(); xattrs.setSTUDYATTRIBUTEArray(xattrs.sizeOfSTUDYATTRIBUTEArray() - 1, xacc); } if (investigation != null) { String invAcc = investigation.getAcc(); AttributeType xacc = buildStudyAttribute("BII Investigation Accession", invAcc, null); xattrs.addNewSTUDYATTRIBUTE(); xattrs.setSTUDYATTRIBUTEArray(xattrs.sizeOfSTUDYATTRIBUTEArray() - 1, xacc); } String studyDescr = StringUtils.trimToNull(study.getDescription()); if (studyDescr != null) { xdescriptor.setSTUDYDESCRIPTION(studyDescr); } Collection<Design> designs = study.getDesigns(); if (designs == null || designs.isEmpty()) { throw new TabMissingValueException(MessageFormat .format("Study ''{0}'' has no study design, cannot be exported to SRA format", studyAcc)); } Design design = designs.iterator().next(); // Try to see if the ISATAB study type is listed in the SRA schema, use 'other' otherwise. // TODO: ontology term // TODO: check on the assay type to determine nature of the study design. for example, // TODO: if measurement type = environmental gene survey, study design = METAGENOMICS STUDYTYPE xstudyType = STUDYTYPE.Factory.newInstance(); String designStr = design.getValue(); ExistingStudyType.Enum xdesign = ExistingStudyType.Enum.forString(designStr); if (designStr == null) { xstudyType.setExistingStudyType(xdesign); } else { xstudyType.setExistingStudyType(ExistingStudyType.OTHER); xstudyType.setNewStudyType(designStr); } xdescriptor.setSTUDYTYPE(xstudyType); xstudy.setDESCRIPTOR(xdescriptor); for (Contact contact : study.getContacts()) { buildExportedContact(contact, xattrs, false); } if (investigation != null) { for (Contact contact : investigation.getContacts()) { buildExportedContact(contact, xattrs, true); } } for (Publication contact : study.getPublications()) { buildExportedPublication(contact, xattrs, xlinks, false); } if (investigation != null) { for (Publication contact : investigation.getPublications()) { buildExportedPublication(contact, xattrs, xlinks, true); } } //TODO: BII link, protocols if (xattrs.sizeOfSTUDYATTRIBUTEArray() != 0) { xstudy.setSTUDYATTRIBUTES(xattrs); } if (xlinks.sizeOfSTUDYLINKArray() != 0) { xstudy.setSTUDYLINKS(xlinks); } if (description != null) { xdescriptor.setSTUDYDESCRIPTION(description); xstudy.setDESCRIPTOR(xdescriptor); } xstudyDoc.setSTUDY(xstudy); return xstudyDoc; }
From source file:org.jumpmind.metl.core.runtime.flow.FlowRuntime.java
public static Map<String, String> getFlowParameters(Map<String, String> params, Agent agent, AgentDeployment agentDeployment) { List<AgentDeploymentParameter> deployParameters = agentDeployment.getAgentDeploymentParameters(); List<AgentParameter> agentParameters = agent.getAgentParameters(); if (agentParameters != null) { for (AgentParameter agentParameter : agentParameters) { params.put(agentParameter.getName(), agentParameter.getValue()); }// www.j a v a2s. co m } if (deployParameters != null) { for (AgentDeploymentParameter deployParameter : deployParameters) { params.put(deployParameter.getName(), deployParameter.getValue()); } } Date date = new Date(); params.put("_agentName", agent.getName()); params.put("_deploymentName", agentDeployment.getName()); params.put("_flowName", agentDeployment.getFlow().getName()); params.put("_host", agent.getHost()); params.put("_date", DateFormatUtils.format(date, DATE_FORMAT)); params.put("_time", DateFormatUtils.format(date, TIME_FORMAT)); params.put("_startDate", DateFormatUtils.format(date, DATE_FORMAT)); params.put("_startTime", DateFormatUtils.format(date, TIME_FORMAT)); return params; }
From source file:org.jumpmind.metl.core.runtime.flow.FlowRuntime.java
protected void sendNotifications(Notification.EventType eventType) { if (notifications != null && notifications.size() > 0) { Transport transport = null;//from w w w . ja v a 2 s .c o m Date date = new Date(); flowParameters.put("_date", DateFormatUtils.format(date, DATE_FORMAT)); flowParameters.put("_time", DateFormatUtils.format(date, TIME_FORMAT)); try { for (Notification notification : notifications) { if (notification.getEventType().equals(eventType.toString())) { log.info("Sending notification '" + notification.getName() + "' of level '" + notification.getLevel() + "' and type '" + notification.getNotifyType() + "'"); transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession.getSession()); message.setSentDate(new Date()); message.setRecipients(RecipientType.BCC, notification.getRecipients()); message.setSubject( FormatUtils.replaceTokens(notification.getSubject(), flowParameters, true)); message.setText(FormatUtils.replaceTokens(notification.getMessage(), flowParameters, true)); try { transport.sendMessage(message, message.getAllRecipients()); } catch (MessagingException e) { log.error("Failure while sending notification", e); } } } } catch (MessagingException e) { log.error("Failure while preparing notification", e); } finally { mailSession.closeTransport(transport); } } }
From source file:org.jumpmind.symmetric.io.data.transform.VariableColumnTransform.java
public String transform(IDatabasePlatform platform, DataContext context, TransformColumn column, TransformedData data, Map<String, String> sourceValues, String newValue, String oldValue) throws IgnoreColumnException, IgnoreRowException { String varName = column.getTransformExpression(); if (varName != null) { if (varName.equalsIgnoreCase(OPTION_TIMESTAMP)) { return DateFormatUtils.format(System.currentTimeMillis(), TS_PATTERN); } else if (varName.equalsIgnoreCase(OPTION_DATE)) { return DateFormatUtils.format(System.currentTimeMillis(), DATE_PATTERN); } else if (varName.equalsIgnoreCase(OPTION_SOURCE_NODE_ID)) { return context.getBatch().getSourceNodeId(); } else if (varName.equalsIgnoreCase(OPTION_TARGET_NODE_ID)) { return context.getBatch().getTargetNodeId(); } else if (varName.equalsIgnoreCase(OPTION_OLD_VALUE)) { return oldValue; } else if (varName.equals(OPTION_NULL)) { return null; } else if (varName.equals(OPTION_SOURCE_TABLE_NAME)) { Data csvData = (Data) context.get(Constants.DATA_CONTEXT_CURRENT_CSV_DATA); if (csvData != null && csvData.getTriggerHistory() != null) { return csvData.getTriggerHistory().getSourceTableName(); }// www . j ava 2s .co m } else if (varName.equals(OPTION_SOURCE_CATALOG_NAME)) { Data csvData = (Data) context.get(Constants.DATA_CONTEXT_CURRENT_CSV_DATA); if (csvData != null && csvData.getTriggerHistory() != null) { return csvData.getTriggerHistory().getSourceCatalogName(); } } else if (varName.equals(OPTION_SOURCE_SCHEMA_NAME)) { Data csvData = (Data) context.get(Constants.DATA_CONTEXT_CURRENT_CSV_DATA); if (csvData != null && csvData.getTriggerHistory() != null) { return csvData.getTriggerHistory().getSourceSchemaName(); } } } return null; }
From source file:org.kuali.kfs.module.endow.businessobject.options.CurrentProcessDateValuesFinder.java
public String getValue() { // get the current date from the service Date date = SpringContext.getBean(KEMService.class).getCurrentDate(); // remove the time component date = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); // format it as expected return DateFormatUtils.format(date, "MM/dd/yyyy"); }
From source file:org.kuali.kfs.sys.businessobject.defaultvalue.CurrentDateMMDDYYYYFinder.java
public String getValue() { // get the current date from the service Date date = SpringContext.getBean(DateTimeService.class).getCurrentDate(); // remove the time component date = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); // format it as expected return DateFormatUtils.format(date, "MM/dd/yyyy"); }
From source file:org.kuali.kpme.core.kfs.sys.businessobject.defaultvalue.CurrentDateMMDDYYYYFinder.java
public String getValue() { // get the current date from the service // Date date = SpringContext.getBean(DateTimeService.class).getCurrentDate(); Date date = CoreApiServiceLocator.getDateTimeService().getCurrentDate(); // remove the time component date = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); // format it as expected return DateFormatUtils.format(date, "MM/dd/yyyy"); }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method gets ReportHeaderType from first budgetPeriod.It set all the * data for RportHeader from budgetPriod and budgetParent * // w w w .java 2s . c o m * @param budgetParent * @return reportTypeHeader */ protected ReportHeaderType getReportHeaderTypeForCumulativeReport(BudgetParent budgetParent) { ReportHeaderType reportHeaderType = ReportHeaderType.Factory.newInstance(); if (budgetParent != null) { reportHeaderType.setParentTypeName(budgetParent.getParentTypeName()); reportHeaderType.setProposalNumber(budgetParent.getParentNumber()); } if (budgetParent != null && budgetParent.getParentTitle() != null) { reportHeaderType.setProposalTitle(budgetParent.getParentTitle()); } String principleInvestigatorName = budgetParent.getParentPIName(); if (principleInvestigatorName != null) { reportHeaderType.setPIName(principleInvestigatorName); } if (budgetPeriod.getVersionNumber() != null) { reportHeaderType.setBudgetVersion(budget.getBudgetVersionNumber().intValue()); } if (budgetPeriod.getStartDate() != null) { reportHeaderType.setPeriodStartDate(DateFormatUtils.format(budgetPeriod.getStartDate(), DATE_FORMAT)); } if (budgetPeriod.getEndDate() != null) { reportHeaderType.setPeriodEndDate(DateFormatUtils.format(budgetPeriod.getEndDate(), DATE_FORMAT)); } if (budgetPeriod.getBudgetPeriod() != null) { reportHeaderType.setPeriod(budgetPeriod.getBudgetPeriod()); } reportHeaderType.setCreateDate(dateTimeService.getCurrentDate().toString()); if (budget.getComments() != null) { if (budget.getPrintBudgetCommentFlag() != null && budget.getPrintBudgetCommentFlag().equals("true")) reportHeaderType.setComments(budget.getComments()); } budget.setPrintBudgetCommentFlag(null); return reportHeaderType; }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method gets reportType for LASalary by setting data from * reportTypeVO and passed parameters//www .j a v a2 s .c o m * */ private ReportType getReportTypeForLASalary(BudgetDecimal fringe, BudgetDecimal salary, BudgetDecimal calculatedCost, BudgetDecimal calculatedCostSharing, ReportTypeVO reportTypeVO, Date startDate, Date endDate) { ReportType reportType = ReportType.Factory.newInstance(); reportType.setBudgetCategoryDescription(LAB_ALLOCATION); reportType.setPersonName(ALLOCATED_ADMIN_SUPPORT); reportType.setPercentEffort(100); reportType.setPercentCharged(100); reportType.setBudgetCategoryCode(99); reportType.setInvestigatorFlag(3); reportType.setStartDate(DateFormatUtils.format(startDate, DATE_FORMAT_MMDDYY)); reportType.setEndDate(DateFormatUtils.format(endDate, DATE_FORMAT_MMDDYY)); reportType.setCostSharingAmount(calculatedCostSharing.doubleValue()); reportType.setCalculatedCost(calculatedCost.doubleValue()); reportType.setFringe(fringe.doubleValue()); reportType.setCostElementDescription(reportTypeVO.getCostElementDesc()); reportType.setSalaryRequested(salary.doubleValue()); return reportType; }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
private ReportType getReportTypeForRateAndBase(Date startDate, Date endDate, BudgetDecimal calculatedCost, BudgetDecimal salaryRequested, ReportTypeVO reportTypeVO) { ReportType reportType = ReportType.Factory.newInstance(); reportType.setSalaryRequested(salaryRequested.doubleValue()); reportType.setCalculatedCost(calculatedCost.doubleValue()); reportType.setStartDate(DateFormatUtils.format(startDate, DATE_FORMAT)); reportType.setEndDate(DateFormatUtils.format(endDate, DATE_FORMAT)); reportType.setAppliedRate(reportTypeVO.getAppliedRate().doubleValue()); reportType.setRateClassDesc(reportTypeVO.getRateClassDesc()); reportType.setRateTypeDesc(reportTypeVO.getRateTypeDesc()); reportType.setOnOffCampus(reportTypeVO.getOnOffCampusFlag()); return reportType; }