List of usage examples for java.text DecimalFormat applyPattern
public void applyPattern(String pattern)
From source file:org.openmrs.Obs.java
/** * Convenience method for obtaining the observation's value as a string If the Obs is complex, * returns the title of the complexData denoted by the section of getValueComplex() before the * first bar '|' character; or returns the entire getValueComplex() if the bar '|' character is * missing./*w w w. j av a2 s. co m*/ * * @param locale locale for locale-specific depictions of value * @should return first part of valueComplex for complex obs * @should return first part of valueComplex for non null valueComplexes * @should return non precise values for NumericConcepts * @should return date in correct format * @should not return long decimal numbers as scientific notation * @should use commas or decimal places depending on locale * @should not use thousand separator * @should return regular number for size of zero to or greater than ten digits * @should return regular number if decimal places are as high as six */ public String getValueAsString(Locale locale) { // formatting for the return of numbers of type double NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyPattern("#0.0#####"); // formatting style up to 6 digits //branch on hl7 abbreviations if (getConcept() != null) { String abbrev = getConcept().getDatatype().getHl7Abbreviation(); if ("BIT".equals(abbrev)) { return getValueAsBoolean() == null ? "" : getValueAsBoolean().toString(); } else if ("CWE".equals(abbrev)) { if (getValueCoded() == null) { return ""; } if (getValueDrug() != null) { return getValueDrug().getFullName(locale); } else { ConceptName valueCodedName = getValueCodedName(); if (valueCodedName != null) { return getValueCoded().getName(locale, false).getName(); } else { ConceptName fallbackName = getValueCoded().getName(); if (fallbackName != null) { return fallbackName.getName(); } else { return ""; } } } } else if ("NM".equals(abbrev) || "SN".equals(abbrev)) { if (getValueNumeric() == null) { return ""; } else { if (getConcept() instanceof ConceptNumeric) { ConceptNumeric cn = (ConceptNumeric) getConcept(); if (!cn.isPrecise()) { double d = getValueNumeric(); int i = (int) d; return Integer.toString(i); } else { df.format(getValueNumeric()); } } } } else if ("DT".equals(abbrev)) { DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN); return (getValueDatetime() == null ? "" : dateFormat.format(getValueDatetime())); } else if ("TM".equals(abbrev)) { return (getValueDatetime() == null ? "" : Format.format(getValueDatetime(), locale, FORMAT_TYPE.TIME)); } else if ("TS".equals(abbrev)) { return (getValueDatetime() == null ? "" : Format.format(getValueDatetime(), locale, FORMAT_TYPE.TIMESTAMP)); } else if ("ST".equals(abbrev)) { return getValueText(); } else if ("ED".equals(abbrev) && getValueComplex() != null) { String[] valueComplex = getValueComplex().split("\\|"); for (int i = 0; i < valueComplex.length; i++) { if (StringUtils.isNotEmpty(valueComplex[i])) { return valueComplex[i].trim(); } } } } // if the datatype is 'unknown', default to just returning what is not null if (getValueNumeric() != null) { return df.format(getValueNumeric()); } else if (getValueCoded() != null) { if (getValueDrug() != null) { return getValueDrug().getFullName(locale); } else { ConceptName valudeCodedName = getValueCodedName(); if (valudeCodedName != null) { return valudeCodedName.getName(); } else { return ""; } } } else if (getValueDatetime() != null) { return Format.format(getValueDatetime(), locale, FORMAT_TYPE.DATE); } else if (getValueText() != null) { return getValueText(); } else if (hasGroupMembers()) { // all of the values are null and we're an obs group...so loop // over the members and just do a getValueAsString on those // this could potentially cause an infinite loop if an obs group // is a member of its own group at some point in the hierarchy StringBuilder sb = new StringBuilder(); for (Obs groupMember : getGroupMembers()) { if (sb.length() > 0) { sb.append(", "); } sb.append(groupMember.getValueAsString(locale)); } return sb.toString(); } // returns the title portion of the valueComplex // which is everything before the first bar '|' character. if (getValueComplex() != null) { String[] valueComplex = getValueComplex().split("\\|"); for (int i = 0; i < valueComplex.length; i++) { if (StringUtils.isNotEmpty(valueComplex[i])) { return valueComplex[i].trim(); } } } return ""; }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java
@Override public DecimalFormat getDecimalFormatter() { BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext(); Locale locale = brc.getJavaLocale(); DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.applyPattern("0.########"); format.setGroupingUsed(false);//from w w w . j a v a 2 s . c om return format; }
From source file:org.sakaiproject.tool.podcasts.podHomeBean.java
/** * Receives a particular podcast and packages it as a DecoratedPodcastBean * // w ww. j a va 2s . c o m * @param podcastProperties * Contains the ResourceProperties object of a podcast resource * @param resourceId * The resource ID for the podcast * * @return DecoratedPodcastBean * The packaged podcast or null and exception if problems * * @throws EntityPropertyNotDefinedException * The property wanted was not found * @throws EntityPropertyTypeException * The property (Date/Time) was not a valid one */ public DecoratedPodcastBean getAPodcast(ContentResource podcastResource, boolean folderHidden) throws EntityPropertyNotDefinedException, EntityPropertyTypeException { ResourceProperties podcastProperties = podcastResource.getProperties(); DecoratedPodcastBean podcastInfo = null; // first check if hidden. // if instructor or has hidden property, set hidden property of decorated bean // if not, return null since user cannot see Date tempDate = null; final SimpleDateFormat formatter = new SimpleDateFormat(getErrorMessageString(PUBLISH_DATE_FORMAT), rb.getLocale()); formatter.setTimeZone(TimeService.getLocalTimeZone()); // get release/publish date - else part needed for podcasts created before release/retract dates // feature implemented if (podcastResource.getReleaseDate() == null) { tempDate = podcastService .getGMTdate(podcastProperties.getTimeProperty(PodcastService.DISPLAY_DATE).getTime()); } else { tempDate = new Date(podcastResource.getReleaseDate().getTime()); } // store result of hidden property OR after retract date OR before release date final boolean uiHidden = folderHidden || hiddenInUI(podcastResource, tempDate); if (!uiHidden || getHasHidden()) { podcastInfo = new DecoratedPodcastBean(); podcastInfo.setDisplayDate(formatter.format(tempDate)); // store resourceId podcastInfo.setResourceId(podcastResource.getId()); // store Title and Description podcastInfo.setTitle(podcastProperties.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME)); podcastInfo.setDescription(podcastProperties.getPropertyFormatted(ResourceProperties.PROP_DESCRIPTION)); podcastInfo.setHidden(uiHidden); // if podcast should be hidden, set style class to 'inactive' if (uiHidden) { podcastInfo.setStyleClass("inactive"); } String filename = null; try { String url = podcastService.getPodcastFileURL(podcastResource.getId()); filename = url.substring(url.lastIndexOf("/") + 1); } catch (PermissionException e) { LOG.warn("PermissionException getting podcast with id " + podcastResource.getId() + " while constructing DecoratedPodcastBean for site " + podcastService.getSiteId() + ". " + e.getMessage(), e); } catch (IdUnusedException e) { LOG.warn("IdUnusedException getting podcast with id " + podcastResource.getId() + " while constructing DecoratedPodcastBean for site " + podcastService.getSiteId() + ". " + e.getMessage(), e); } // if user puts URL instead of file, this is result of retrieving filename if (filename == null) return null; podcastInfo.setFilename(filename); // get content type podcastInfo.setFileContentType(podcastProperties.getProperty(ResourceProperties.PROP_CONTENT_TYPE)); // store actual and formatted file size // determine whether to display filesize as bytes or MB final long size = Long.parseLong(podcastProperties.getProperty(ResourceProperties.PROP_CONTENT_LENGTH)); podcastInfo.setFileSize(size); final double sizeMB = size / (1024.0 * 1024.0); final DecimalFormat df = new DecimalFormat(MB_NUMBER_FORMAT); String sizeString; if (sizeMB > 0.3) { sizeString = df.format(sizeMB) + MB; } else { df.applyPattern(BYTE_NUMBER_FORMAT); sizeString = "" + df.format(size) + " " + BYTES; } podcastInfo.setSize(sizeString); final String extn = Validator.getFileExtension(filename); if (!"".equals(extn)) { podcastInfo.setType(Validator.getFileExtension(filename).toUpperCase()); } else { podcastInfo.setType("UNK"); } // get and format last modified time formatter.applyPattern(LAST_MODIFIED_TIME_FORMAT); tempDate = new Date(podcastProperties.getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE).getTime()); podcastInfo.setPostedTime(formatter.format(tempDate)); // get and format last modified date formatter.applyPattern(LAST_MODIFIED_DATE_FORMAT); tempDate = new Date(podcastProperties.getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE).getTime()); podcastInfo.setPostedDate(formatter.format(tempDate)); // get author podcastInfo.setAuthor(podcastProperties.getPropertyFormatted(ResourceProperties.PROP_CREATOR)); } return podcastInfo; }
From source file:be.ibridge.kettle.trans.step.textfileinput.TextFileInput.java
public static final Value convertValue(String pol, String field_name, int field_type, String field_format, int field_length, int field_precision, String num_group, String num_decimal, String num_currency, String nullif, String ifNull, int trim_type, DecimalFormat ldf, DecimalFormatSymbols ldfs, SimpleDateFormat ldaf, DateFormatSymbols ldafs) throws Exception { Value value = new Value(field_name, field_type); // build a value! // If no nullif field is supplied, take the default. String null_value = nullif;//from w ww .j av a2s. c o m if (null_value == null) { switch (field_type) { case Value.VALUE_TYPE_BOOLEAN: null_value = Const.NULL_BOOLEAN; break; case Value.VALUE_TYPE_STRING: null_value = Const.NULL_STRING; break; case Value.VALUE_TYPE_BIGNUMBER: null_value = Const.NULL_BIGNUMBER; break; case Value.VALUE_TYPE_NUMBER: null_value = Const.NULL_NUMBER; break; case Value.VALUE_TYPE_INTEGER: null_value = Const.NULL_INTEGER; break; case Value.VALUE_TYPE_DATE: null_value = Const.NULL_DATE; break; case Value.VALUE_TYPE_BINARY: null_value = Const.NULL_BINARY; break; default: null_value = Const.NULL_NONE; break; } } String null_cmp = Const.rightPad(new StringBuffer(null_value), pol.length()); if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { if (ifNull != null && ifNull.length() != 0) pol = ifNull; } if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { value.setNull(); } else { if (value.isNumeric()) { try { StringBuffer strpol = new StringBuffer(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; case TextFileInputMeta.TYPE_TRIM_BOTH: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; default: break; } pol = strpol.toString(); if (value.isNumber()) { if (field_format != null) { ldf.applyPattern(field_format); if (num_decimal != null && num_decimal.length() >= 1) ldfs.setDecimalSeparator(num_decimal.charAt(0)); if (num_group != null && num_group.length() >= 1) ldfs.setGroupingSeparator(num_group.charAt(0)); if (num_currency != null && num_currency.length() >= 1) ldfs.setCurrencySymbol(num_currency); ldf.setDecimalFormatSymbols(ldfs); } value.setValue(ldf.parse(pol).doubleValue()); } else { if (value.isInteger()) { value.setValue(Long.parseLong(pol)); } else { if (value.isBigNumber()) { value.setValue(new BigDecimal(pol)); } else { throw new KettleValueException("Unknown numeric type: contact vendor!"); } } } } catch (Exception e) { throw (e); } } else { if (value.isString()) { value.setValue(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: value.ltrim(); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: value.rtrim(); break; case TextFileInputMeta.TYPE_TRIM_BOTH: value.trim(); break; default: break; } if (pol.length() == 0) value.setNull(); } else { if (value.isDate()) { try { if (field_format != null) { ldaf.applyPattern(field_format); ldaf.setDateFormatSymbols(ldafs); } value.setValue(ldaf.parse(pol)); } catch (Exception e) { throw (e); } } else { if (value.isBinary()) { value.setValue(pol.getBytes()); } } } } } value.setLength(field_length, field_precision); return value; }
From source file:ispyb.client.mx.results.ViewResultsAction.java
@SuppressWarnings("unchecked") public void getAutoprocessingDetails(ActionMapping mapping, ActionForm actForm, HttpServletRequest request, HttpServletResponse response) {//from w w w. jav a 2 s. c o m LOG.debug("getAutoprocessingDetails"); try { String autoProcIdS = request.getParameter("autoProcId"); AutoProcessingDetail autoProcDetail = new AutoProcessingDetail(); try { DecimalFormat df1 = (DecimalFormat) NumberFormat.getInstance(Locale.US); df1.applyPattern("#####0.0"); Integer autoProcId = Integer.parseInt(autoProcIdS); AutoProc3VO apv = apService.findByPk(autoProcId); autoProcDetail.setAutoProcId(autoProcId); AutoProcScalingStatistics3VO apssv_overall = apssService .getBestAutoProcScalingStatistic(apssService.findByAutoProcId(autoProcId, "overall")); AutoProcScalingStatistics3VO apssv_outer = apssService .getBestAutoProcScalingStatistic(apssService.findByAutoProcId(autoProcId, "outerShell")); if (apssv_overall != null) { autoProcDetail.setOverallCompleteness("" + apssv_overall.getCompleteness() + "%"); autoProcDetail.setOverallResolution("" + apssv_overall.getResolutionLimitLow() + "-" + apssv_overall.getResolutionLimitHigh() + " Å"); autoProcDetail.setOverallIOverSigma("" + apssv_overall.getMeanIoverSigI()); if (apssv_overall.getRmerge() == null) autoProcDetail.setOverallRsymm(""); else { autoProcDetail.setOverallRsymm("" + apssv_overall.getRmerge() + "%"); } autoProcDetail.setOverallMultiplicity("" + (apssv_overall.getMultiplicity() == null ? "" : new Double(df1.format(apssv_overall.getMultiplicity())))); } if (apssv_outer != null) { autoProcDetail.setOuterCompleteness("" + apssv_outer.getCompleteness() + "%"); autoProcDetail.setOuterResolution("" + apssv_outer.getResolutionLimitLow() + "-" + apssv_overall.getResolutionLimitHigh() + " Å"); autoProcDetail.setOuterIOverSigma("" + apssv_outer.getMeanIoverSigI()); autoProcDetail.setOuterRsymm("" + apssv_outer.getRmerge() + "%"); autoProcDetail.setOuterMultiplicity("" + (apssv_outer.getMultiplicity() == null ? "" : (new Double(df1.format(apssv_outer.getMultiplicity()))))); } double refinedCellA = ((double) ((int) (apv.getRefinedCellA() * 10))) / 10; double refinedCellB = ((double) ((int) (apv.getRefinedCellB() * 10))) / 10; double refinedCellC = ((double) ((int) (apv.getRefinedCellC() * 10))) / 10; autoProcDetail.setUnitCellA("" + refinedCellA + " Å"); // angstrom symbol autoProcDetail.setUnitCellB("" + refinedCellB + " Å"); autoProcDetail.setUnitCellC("" + refinedCellC + " Å"); autoProcDetail.setUnitCellAlpha("" + apv.getRefinedCellAlpha() + " °"); // degree symbol autoProcDetail.setUnitCellBeta("" + apv.getRefinedCellBeta() + " °"); autoProcDetail.setUnitCellGamma("" + apv.getRefinedCellGamma() + " °"); // List<AutoProcStatus3VO> autoProcEvents = new ArrayList<AutoProcStatus3VO>(); if (autoProcId != null) { List<AutoProcIntegration3VO> autoProcIntegrations = autoProcIntegrationService .findByAutoProcId(autoProcId); if (!autoProcIntegrations.isEmpty()) { autoProcEvents = (autoProcIntegrations.iterator().next()).getAutoProcStatusList(); } } autoProcDetail.setAutoProcEvents(autoProcEvents); // attachments List<IspybAutoProcAttachment3VO> listOfAutoProcAttachment = (List<IspybAutoProcAttachment3VO>) request .getSession().getAttribute(Constants.ISPYB_AUTOPROC_ATTACH_LIST); Integer autoProcProgramId = null; if (apv != null) autoProcProgramId = apv.getAutoProcProgramVOId(); if (autoProcId != null) { List<AutoProcIntegration3VO> autoProcIntegrations = autoProcIntegrationService .findByAutoProcId(autoProcId); if (!autoProcIntegrations.isEmpty()) { autoProcProgramId = (autoProcIntegrations.iterator().next()).getAutoProcProgramVOId(); } } List<AutoProcProgramAttachment3VO> attachments = null; List<AutoProcAttachmentWebBean> autoProcProgAttachmentsWebBeans = new ArrayList<AutoProcAttachmentWebBean>(); LOG.debug("autoProcProgramId = " + autoProcProgramId); if (autoProcProgramId != null) { attachments = new ArrayList<AutoProcProgramAttachment3VO>( appService.findByPk(autoProcProgramId, true).getAttachmentVOs()); if (!attachments.isEmpty()) { // attachmentWebBeans = new AutoProcAttachmentWebBean[attachments.size()]; LOG.debug("nb attachments = " + attachments.size()); for (Iterator<AutoProcProgramAttachment3VO> iterator = attachments.iterator(); iterator .hasNext();) { AutoProcProgramAttachment3VO att = iterator.next(); AutoProcAttachmentWebBean attBean = new AutoProcAttachmentWebBean(att); // gets the ispyb auto proc attachment file IspybAutoProcAttachment3VO aAutoProcAttachment = getAutoProcAttachment( attBean.getFileName(), listOfAutoProcAttachment); if (aAutoProcAttachment == null) { // by default in XDS tab and output files aAutoProcAttachment = new IspybAutoProcAttachment3VO(null, attBean.getFileName(), "", "XDS", "output", false); } attBean.setIspybAutoProcAttachment(aAutoProcAttachment); autoProcProgAttachmentsWebBeans.add(attBean); } } else LOG.debug("attachments is empty"); } // Issue 1507: Correction files for ID29 & ID23-1 if (Constants.SITE_IS_ESRF()) { Integer dataCollectionId = null; if (BreadCrumbsForm.getIt(request).getSelectedDataCollection() != null) dataCollectionId = BreadCrumbsForm.getIt(request).getSelectedDataCollection() .getDataCollectionId(); if (dataCollectionId != null) { DataCollection3VO dataCollection = dataCollectionService.findByPk(dataCollectionId, false, false); String beamLineName = dataCollection.getDataCollectionGroupVO().getSessionVO() .getBeamlineName(); String[] correctionFiles = ESRFBeamlineEnum .retrieveCorrectionFilesNameWithName(beamLineName); if (correctionFiles != null) { for (int k = 0; k < correctionFiles.length; k++) { String correctionFileName = correctionFiles[k]; String dir = ESRFBeamlineEnum.retrieveDirectoryNameWithName(beamLineName); if (dir != null) { String correctionFilePath = "/data/pyarch/" + dir + "/" + correctionFileName; String fullFilePath = PathUtils.FitPathToOS(correctionFilePath); File f = new File(fullFilePath); if (f != null && f.exists()) { // fake attachment AutoProcProgramAttachment3VO att = new AutoProcProgramAttachment3VO(-1, null, "Correction File", correctionFileName, correctionFilePath, null); AutoProcAttachmentWebBean attBean = new AutoProcAttachmentWebBean(att); IspybAutoProcAttachment3VO aAutoProcAttachment = new IspybAutoProcAttachment3VO( null, correctionFileName, "correction file", "XDS", "correction", false); attBean.setIspybAutoProcAttachment(aAutoProcAttachment); autoProcProgAttachmentsWebBeans.add(attBean); attachments.add(attBean); } } } // end for } } } autoProcDetail.setAutoProcProgAttachmentsWebBeans(autoProcProgAttachmentsWebBeans); } catch (NumberFormatException e) { } request.getSession().setAttribute("lastAutoProcIdSelected", autoProcDetail.getAutoProcId()); // HashMap<String, Object> data = new HashMap<String, Object>(); // context path data.put("contextPath", request.getContextPath()); // autoProcDetail data.put("autoProcDetail", autoProcDetail); // data => Gson GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss"); } catch (Exception e) { e.printStackTrace(); } }
From source file:ispyb.client.mx.results.ViewResultsAction.java
public void getResultData(ActionMapping mapping, ActionForm actForm, HttpServletRequest request, HttpServletResponse response) {//ww w .j a va 2 s . co m LOG.debug("getResultData"); List<String> errors = new ArrayList<String>(); try { List<AutoProcessingInformation> autoProcList = new ArrayList<AutoProcessingInformation>(); BreadCrumbsForm bar = BreadCrumbsForm.getIt(request); boolean displayOutputParam = false; boolean displayDenzoContent = false; // booleans to fix which tab will be selected by default boolean isEDNACharacterisation = false; boolean isAutoprocessing = false; String rMerge = (String) request.getSession().getAttribute(Constants.RSYMM); String iSigma = (String) request.getSession().getAttribute(Constants.ISIGMA); double rMerge_d = DEFAULT_RMERGE; double iSigma_d = DEFAULT_ISIGMA; int nbRemoved = 0; try { if (rMerge != null && !rMerge.equals("undefined") && !rMerge.equals("")) rMerge_d = Double.parseDouble(rMerge); if (iSigma != null && !iSigma.equals("undefined") && !iSigma.equals("")) iSigma_d = Double.parseDouble(iSigma); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } Integer dataCollectionId = null; List<List<AutoProcStatus3VO>> interruptedAutoProcEvents1 = new ArrayList<List<AutoProcStatus3VO>>(); DataCollection3VO dc = null; // Just one of them could be visible on the bar if (bar.getSelectedDataCollection() != null) { dataCollectionId = bar.getSelectedDataCollection().getDataCollectionId(); } if (dataCollectionId == null && request.getParameter(Constants.DATA_COLLECTION_ID) != null) dataCollectionId = new Integer(request.getParameter(Constants.DATA_COLLECTION_ID)); if (dataCollectionId == null && request.getSession().getAttribute(Constants.DATA_COLLECTION_ID) != null) dataCollectionId = new Integer( (Integer) request.getSession().getAttribute(Constants.DATA_COLLECTION_ID)); if (dataCollectionId == null) { errors.add("dataCollectionId is null"); HashMap<String, Object> data = new HashMap<String, Object>(); data.put("errors", errors); // data => Gson GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss"); return; } dc = dataCollectionService.findByPk(dataCollectionId, false, true); // interrupted autoProc if (dc != null) { List<AutoProcIntegration3VO> autoProcIntegrationList = dc.getAutoProcIntegrationsList(); if (autoProcIntegrationList != null) { for (Iterator<AutoProcIntegration3VO> au = autoProcIntegrationList.iterator(); au.hasNext();) { AutoProcIntegration3VO autoProcIntegration = au.next(); if (autoProcIntegration.getAutoProcProgramVO() == null && autoProcIntegration.getAutoProcStatusList() != null) { List<AutoProcStatus3VO> events = autoProcIntegration.getAutoProcStatusList(); interruptedAutoProcEvents1.add(events); } } } } for (int i = 0; i < 2; i++) { boolean anomalous = (i > 0); List<AutoProc3VO> autoProcsAnomalous = apService .findByAnomalousDataCollectionIdAndOrderBySpaceGroupNumber(dataCollectionId, anomalous); if (autoProcsAnomalous != null) { nbRemoved = 0; LOG.debug("..nbAutoProc " + anomalous + " found before rMerge =" + autoProcsAnomalous.size()); for (Iterator<AutoProc3VO> a = autoProcsAnomalous.iterator(); a.hasNext();) { AutoProc3VO apv = a.next(); List<AutoProcScalingStatistics3VO> scalingStatistics = apssService .findByAutoProcId(apv.getAutoProcId(), "innerShell"); boolean existsUnderRmergeAndOverSigma = false; for (Iterator<AutoProcScalingStatistics3VO> j = scalingStatistics.iterator(); j .hasNext();) { AutoProcScalingStatistics3VO stats = j.next(); if (stats.getRmerge() != null && stats.getRmerge() < rMerge_d && stats.getMeanIoverSigI() > iSigma_d) existsUnderRmergeAndOverSigma = true; } if (!existsUnderRmergeAndOverSigma) { a.remove(); nbRemoved = nbRemoved + 1; } } LOG.debug("..nbAutoProc " + anomalous + " found=" + autoProcsAnomalous.size()); for (Iterator<AutoProc3VO> iterator = autoProcsAnomalous.iterator(); iterator.hasNext();) { AutoProc3VO o = iterator.next(); String cmdLine = ""; if (o.getAutoProcProgramVO() != null && o.getAutoProcProgramVO().getProcessingPrograms() != null) { cmdLine = o.getAutoProcProgramVO().getProcessingPrograms(); } float refinedCellA = ((float) ((int) (o.getRefinedCellA() * 10))) / 10; // round to 1 dp float refinedCellB = ((float) ((int) (o.getRefinedCellB() * 10))) / 10; // round to 1 dp float refinedCellC = ((float) ((int) (o.getRefinedCellC() * 10))) / 10; // round to 1 dp float refinedCellAlpha = ((float) ((int) (o.getRefinedCellAlpha() * 10))) / 10; // round to 1 dp float refinedCellBeta = ((float) ((int) (o.getRefinedCellBeta() * 10))) / 10; // round to 1 dp float refinedCellGamma = ((float) ((int) (o.getRefinedCellGamma() * 10))) / 10; // round to 1 dp String anoTxt = "OFF (Friedel pairs merged)"; // false if (anomalous) { anoTxt = "ON (Friedel pairs unmerged)"; // true } // String anomalousS = anomalous+"= "+anoTxt; AutoProcessingInformation info = new AutoProcessingInformation(o.getAutoProcId(), cmdLine, o.getSpaceGroup(), anoTxt, refinedCellA, refinedCellB, refinedCellC, refinedCellAlpha, refinedCellBeta, refinedCellGamma); autoProcList.add(info); } } } Integer autoProcIdSelected = (Integer) request.getSession().getAttribute("lastAutoProcIdSelected"); // check if autoProcIdSelected is in the list boolean idExists = false; if (autoProcIdSelected != null) { for (Iterator<AutoProcessingInformation> iterator = autoProcList.iterator(); iterator.hasNext();) { AutoProcessingInformation info = iterator.next(); if (info.getAutoProcId().equals(autoProcIdSelected)) { idExists = true; break; } } } if (!idExists) { autoProcIdSelected = null; } List<DataCollection3VO> listLastCollectVO = new ArrayList<DataCollection3VO>(); if (dc != null) listLastCollectVO.add(dc); AutoProcShellWrapper wrapper = ViewDataCollectionAction.getAutoProcStatistics(listLastCollectVO, rMerge_d, iSigma_d); int dcIndex = 0; // is autoproc ? List<AutoProc3VO> autoProcs = apService.findByDataCollectionId(dataCollectionId); if (autoProcs != null && autoProcs.size() > 0) isAutoprocessing = true; String beamLineName = ""; String proposal = ""; String proteinAcronym = ""; String pdbFileName = ""; String experimentType = ""; if (dc != null) { beamLineName = dc.getDataCollectionGroupVO().getSessionVO().getBeamlineName(); proposal = dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getCode() + dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getNumber(); BLSample3VO sample = dc.getDataCollectionGroupVO().getBlSampleVO(); if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().getProteinVO() != null) proteinAcronym = sample.getCrystalVO().getProteinVO().getAcronym(); if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().hasPdbFile()) { pdbFileName = sample.getCrystalVO().getPdbFileName(); } experimentType = dc.getDataCollectionGroupVO().getExperimentType(); } AutoProc3VO autoProc = null; AutoProcScalingStatistics3VO autoProcStatisticsOverall = null; AutoProcScalingStatistics3VO autoProcStatisticsInner = null; AutoProcScalingStatistics3VO autoProcStatisticsOuter = null; ScreeningOutputLattice3VO lattice = null; ScreeningOutput3VO screeningOutput = null; String snapshotFullPath = ""; boolean hasSnapshot = false; Screening3VO[] tabScreening = null; if (dc != null) { snapshotFullPath = dc.getXtalSnapshotFullPath1(); snapshotFullPath = PathUtils.FitPathToOS(snapshotFullPath); if (snapshotFullPath != null) hasSnapshot = (new File(snapshotFullPath)).exists(); autoProc = wrapper.getAutoProcs()[dcIndex]; autoProcStatisticsOverall = wrapper.getScalingStatsOverall()[dcIndex]; autoProcStatisticsInner = wrapper.getScalingStatsInner()[dcIndex]; autoProcStatisticsOuter = wrapper.getScalingStatsOuter()[dcIndex]; DataCollectionGroup3VO dcGroup = dataCollectionGroupService .findByPk(dc.getDataCollectionGroupVOId(), false, true); tabScreening = dcGroup.getScreeningsTab(); } if (tabScreening != null && tabScreening.length > 0) { displayOutputParam = true;// there is at least 1 screening so we display the output params Screening3VO screeningVO = tabScreening[0]; ScreeningOutput3VO[] screeningOutputTab = screeningVO.getScreeningOutputsTab(); if (screeningOutputTab != null && screeningOutputTab.length > 0) { if (screeningOutputTab[0].getScreeningOutputLatticesTab() != null && screeningOutputTab[0].getScreeningOutputLatticesTab().length > 0) { lattice = screeningOutputTab[0].getScreeningOutputLatticesTab()[0]; } screeningOutput = screeningOutputTab[0]; } } String autoprocessingStatus = ""; String autoprocessingStep = ""; if (wrapper != null && wrapper.getAutoProcs() != null && wrapper.getAutoProcs().length > dcIndex) { AutoProcIntegration3VO autoProcIntegration = wrapper.getAutoProcIntegrations()[dcIndex]; if (autoProcIntegration != null) { List<AutoProcStatus3VO> autoProcEvents = autoProcIntegration.getAutoProcStatusList(); if (autoProcEvents != null && autoProcEvents.size() > 0) { AutoProcStatus3VO st = autoProcEvents.get(autoProcEvents.size() - 1); autoprocessingStatus = st.getStatus(); autoprocessingStep = st.getStep(); } } } boolean hasAutoProcAttachment = false; if (wrapper != null && wrapper.getAutoProcs() != null) { for (int a = 0; a < autoProcs.size(); a++) { Integer autoProcProgramId = autoProcs.get(a).getAutoProcProgramVOId(); if (autoProcProgramId != null) { List<AutoProcProgramAttachment3VO> attachments = appService .findByPk(autoProcProgramId, true).getAttachmentListVOs(); if (attachments != null && attachments.size() > 0) { hasAutoProcAttachment = true; break; } } } } DataCollectionBean dataCollection = null; if (dc != null) { dataCollection = new DataCollectionBean(dc, beamLineName, proposal, proteinAcronym, pdbFileName, experimentType, hasSnapshot, autoProc, autoProcStatisticsOverall, autoProcStatisticsInner, autoProcStatisticsOuter, screeningOutput, lattice, autoprocessingStatus, autoprocessingStep, hasAutoProcAttachment); } BeamLineSetup3VO beamline = null; Session3VO session = null; Detector3VO detector = null; String fullDenzoPath = null; boolean DenzonContentPresent = false; if (dc != null) { // beamline setup beamline = dc.getDataCollectionGroupVO().getSessionVO().getBeamLineSetupVO(); // Session session = dc.getDataCollectionGroupVO().getSessionVO(); // Detector detector = dc.getDetectorVO(); // energy DecimalFormat df3 = (DecimalFormat) NumberFormat.getInstance(Locale.US); df3.applyPattern("#####0.000"); Double energy = null; if (dc.getWavelength() != null && dc.getWavelength().compareTo(new Double(0)) != 0) energy = Constants.WAVELENGTH_TO_ENERGY_CONSTANT / dc.getWavelength(); if (energy != null) dataCollection.setEnergy(new Double(df3.format(energy))); else dataCollection.setEnergy(null); // axis start label String axisStartLabel = dc.getRotationAxis() == null ? "" : dc.getRotationAxis() + " start"; dataCollection.setAxisStartLabel(axisStartLabel); // totalExposureTime if (dc.getExposureTime() != null && dc.getNumberOfImages() != null) { dataCollection.setTotalExposureTime( new Double(df3.format(dataCollection.getExposureTime() * dc.getNumberOfImages()))); } // kappa Double kappa = dc.getKappaStart(); String kappaStr = ""; if (kappa == null || kappa.equals(Constants.SILLY_NUMBER)) kappaStr = new String("0"); else kappaStr = new String(kappa.toString()); dataCollection.setKappa(kappaStr); // phi Double phi = dc.getPhiStart(); String phiStr = ""; if (phi == null || phi.equals(Constants.SILLY_NUMBER)) phiStr = new String("0"); else phiStr = new String(phi.toString()); dataCollection.setPhi(phiStr); // undulatorGaps DecimalFormat df2 = (DecimalFormat) NumberFormat.getInstance(Locale.US); // DecimalFormat df2 = new DecimalFormat("##0.##"); df2.applyPattern("##0.##"); StringBuffer buf = new StringBuffer(); // if no type then there is no meaningful value // if no undulator 1 then no 2 and no 3 if (beamline.getUndulatorType1() != null && beamline.getUndulatorType1().length() > 0) { if (dc.getUndulatorGap1() != null && !dc.getUndulatorGap1().equals(Constants.SILLY_NUMBER)) { Double gap1 = new Double(df2.format(dc.getUndulatorGap1())); buf.append(gap1.toString()).append(" mm "); } if (beamline.getUndulatorType2() != null && beamline.getUndulatorType2().length() > 0) { if (dc.getUndulatorGap2() != null && !dc.getUndulatorGap2().equals(Constants.SILLY_NUMBER)) { Double gap2 = new Double(df2.format(dc.getUndulatorGap2())); buf.append(gap2.toString()).append(" mm "); } if (beamline.getUndulatorType3() != null && beamline.getUndulatorType3().length() > 0) { if (dc.getUndulatorGap3() != null && !dc.getUndulatorGap3().equals(Constants.SILLY_NUMBER)) { Double gap3 = new Double(df2.format(dc.getUndulatorGap3())); buf.append(gap3.toString()).append(" mm "); } } } } String undulatorGaps = buf.toString(); dataCollection.setUndulatorGaps(undulatorGaps); DecimalFormat nf1 = (DecimalFormat) NumberFormat.getInstance(Locale.UK); nf1.applyPattern("#"); DecimalFormat df5 = (DecimalFormat) NumberFormat.getInstance(Locale.US); df5.applyPattern("#####0.00000"); // slitGapHorizontalMicro Integer slitGapHorizontalMicro = null; if (dc.getSlitGapHorizontal() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion slitGapHorizontalMicro = new Integer( nf1.format(dc.getSlitGapHorizontal().doubleValue() * 1000)); } dataCollection.setSlitGapHorizontalMicro(slitGapHorizontalMicro); // slitGapVerticalMicro Integer slitGapVerticalMicro = null; if (dc.getSlitGapVertical() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion slitGapVerticalMicro = new Integer(nf1.format(dc.getSlitGapVertical().doubleValue() * 1000)); } dataCollection.setSlitGapVerticalMicro(slitGapVerticalMicro); // detectorPixelSizeHorizontalMicro Double detectorPixelSizeHorizontalMicro = null; if (detector != null && detector.getDetectorPixelSizeHorizontal() != null) { // in DB pixel size unit is mm, detectorPixelSizeHorizontalMicro = new Double( df5.format(detector.getDetectorPixelSizeHorizontal())); } dataCollection.setDetectorPixelSizeHorizontalMicro(detectorPixelSizeHorizontalMicro); // detectorPixelSizeHorizontalMicro Double detectorPixelSizeVerticalMicro = null; if (detector != null && detector.getDetectorPixelSizeVertical() != null) { // in DB pixel size unit is mm, detectorPixelSizeVerticalMicro = new Double( df5.format(detector.getDetectorPixelSizeVertical())); } dataCollection.setDetectorPixelSizeVerticalMicro(detectorPixelSizeVerticalMicro); // beamSizeAtSampleXMicro Integer beamSizeAtSampleXMicro = null; if (dc.getBeamSizeAtSampleX() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion beamSizeAtSampleXMicro = new Integer( nf1.format(dc.getBeamSizeAtSampleX().doubleValue() * 1000)); } dataCollection.setBeamSizeAtSampleXMicro(beamSizeAtSampleXMicro); // beamSizeAtSampleYMicro Integer beamSizeAtSampleYMicro = null; if (dc.getBeamSizeAtSampleY() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion beamSizeAtSampleYMicro = new Integer( nf1.format(dc.getBeamSizeAtSampleY().doubleValue() * 1000)); } dataCollection.setBeamSizeAtSampleYMicro(beamSizeAtSampleYMicro); // beamDivergenceHorizontalInt Integer beamDivergenceHorizontalInt = null; if (beamline.getBeamDivergenceHorizontal() != null) { beamDivergenceHorizontalInt = new Integer(nf1.format(beamline.getBeamDivergenceHorizontal())); } dataCollection.setBeamDivergenceHorizontalInt(beamDivergenceHorizontalInt); // beamDivergenceVerticalInt Integer beamDivergenceVerticalInt = null; if (beamline.getBeamDivergenceVertical() != null) { beamDivergenceVerticalInt = new Integer(nf1.format(beamline.getBeamDivergenceVertical())); } dataCollection.setBeamDivergenceVerticalInt(beamDivergenceVerticalInt); // DNA or EDNA Content present ? String fullDNAPath = PathUtils.getFullDNAPath(dc); String fullEDNAPath = PathUtils.getFullEDNAPath(dc); boolean EDNAContentPresent = (new File(fullEDNAPath + EDNA_FILES_INDEX_FILE)).exists() || (new File(fullDNAPath + Constants.DNA_FILES_INDEX_FILE)).exists(); isEDNACharacterisation = EDNAContentPresent; // Denzo Content present ? if (Constants.DENZO_ENABLED) { fullDenzoPath = FileUtil.GetFullDenzoPath(dc); DenzonContentPresent = (new File(fullDenzoPath)).exists(); displayDenzoContent = DisplayDenzoContent(dc); if (DenzonContentPresent) // Check html file present { File denzoIndex = new File(fullDenzoPath + DENZO_HTML_INDEX); if (!denzoIndex.exists()) { errors.add("Denzo File does not exist " + denzoIndex); DenzonContentPresent = false; } } } } // HashMap<String, Object> data = new HashMap<String, Object>(); // context path data.put("contextPath", request.getContextPath()); // autoProcList data.put("autoProcList", autoProcList); // autoProcIdSelected data.put("autoProcIdSelected", autoProcIdSelected); // rMerge & iSigma data.put("rMerge", rMerge); data.put("iSigma", iSigma); data.put("nbRemoved", nbRemoved); data.put("dataCollectionId", dataCollectionId); data.put("dataCollection", dataCollection); // beamlinesetup data.put("beamline", beamline); // session data.put("session", session); // detector data.put("detector", detector); // interrupted autoProc data.put("interruptedAutoProcEvents", interruptedAutoProcEvents1); // displayOutputParam data.put("displayOutputParam", displayOutputParam); // isEDNACharacterisation data.put("isEDNACharacterisation", isEDNACharacterisation); // isAutoprocessing data.put("isAutoprocessing", isAutoprocessing); // displayDenzoContent data.put("displayDenzoContent", displayDenzoContent); // DenzonContentPresent data.put("DenzonContentPresent", DenzonContentPresent); // fullDenzoPath data.put("fullDenzoPath", fullDenzoPath); // data => Gson GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss"); } catch (Exception e) { e.printStackTrace(); } }