Example usage for java.text ParseException getMessage

List of usage examples for java.text ParseException getMessage

Introduction

In this page you can find the example usage for java.text ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.jahia.services.importexport.LegacyImportHandler.java

private boolean setPropertyField(ExtendedNodeType baseType, String localName, JCRNodeWrapper node,
        String propertyName, String value, Map<String, String> creationMetadata) throws RepositoryException {
    JCRNodeWrapper parent = node;//  w  ww  . jav  a 2s  . c  o m
    String mixinType = null;
    if (propertyName.contains("|")) {
        mixinType = StringUtils.substringBefore(propertyName, "|");
        propertyName = StringUtils.substringAfter(propertyName, "|");
    }
    if (StringUtils.contains(propertyName, "/")) {
        String parentPath = StringUtils.substringBeforeLast(propertyName, "/");
        if (parent.hasNode(parentPath)) {
            parent = parent.getNode(parentPath);
        }
        propertyName = StringUtils.substringAfterLast(propertyName, "/");
    }
    parent = checkoutNode(parent);
    if (!StringUtils.isEmpty(mixinType) && !parent.isNodeType(mixinType)) {
        parent.addMixin(mixinType);
    }

    ExtendedPropertyDefinition propertyDefinition;
    propertyDefinition = parent.getApplicablePropertyDefinition(propertyName);
    if (propertyDefinition == null) {
        return false;
    }
    if (propertyDefinition.isProtected()) {
        return false;
    }

    if (StringUtils.isNotBlank(value) && !value.equals("<empty>")) {
        Node n = parent;
        if (propertyDefinition.isInternationalized()) {
            n = getOrCreateI18N(parent, locale, creationMetadata);
        }
        if (!n.isCheckedOut()) {
            session.checkout(n);
        }
        switch (propertyDefinition.getRequiredType()) {
        case PropertyType.DATE:
            GregorianCalendar cal = new GregorianCalendar();
            try {
                DateFormat df = new SimpleDateFormat(ImportExportService.DATE_FORMAT);
                Date d = df.parse(value);
                cal.setTime(d);
                n.setProperty(propertyName, cal);
            } catch (java.text.ParseException e) {
                logger.error(e.getMessage(), e);
            }
            break;

        case PropertyType.REFERENCE:
        case PropertyType.WEAKREFERENCE:
            if (propertyDefinition.isMultiple()) {
                String[] strings = Patterns.TRIPPLE_DOLLAR.split(value);
                for (String s : strings) {
                    createReferenceValue(s, propertyDefinition.getSelector(), n, propertyName);
                }
            } else {
                createReferenceValue(value, propertyDefinition.getSelector(), n, propertyName);
            }
            break;

        default:
            switch (propertyDefinition.getSelector()) {
            case SelectorType.RICHTEXT: {
                if (value.contains("=\"###")) {
                    int count = 1;
                    StringBuilder buf = new StringBuilder(value);
                    while (buf.indexOf("=\"###") > -1) {
                        int from = buf.indexOf("=\"###") + 2;
                        int to = buf.indexOf("\"", from);

                        String ref = buf.substring(from, to);
                        if (ref.startsWith("###/webdav")) {
                            ref = StringUtils.substringAfter(ref, "###/webdav");
                            buf.replace(from, to, "##doc-context##/{workspace}/##ref:link" + count + "##");
                        } else if (ref.startsWith("###file:")) {
                            ref = StringUtils.substringAfter(ref, "###file:");
                            final int qmPos = ref.indexOf('?');
                            boolean isUuid = false;
                            if (qmPos != -1) {
                                if (StringUtils.substring(ref, qmPos + 1).startsWith("uuid=default:")) {
                                    ref = StringUtils.substring(ref, qmPos + 14);
                                    isUuid = true;
                                } else
                                    ref = StringUtils.substringBefore(ref, "?");
                            }
                            if (!isUuid)
                                ref = correctFilename(ref);
                            buf.replace(from, to, "##doc-context##/{workspace}/##ref:link" + count + "##");
                        } else {
                            ref = StringUtils.substringAfterLast(ref, "/");
                            // we keep the URL parameters if any
                            String params = "";
                            int pos = ref.indexOf('?');
                            if (pos == -1) {
                                pos = ref.indexOf('#');
                            }
                            if (pos != -1) {
                                params = ref.substring(pos);
                                ref = ref.substring(0, pos);
                            }
                            buf.replace(from, to,
                                    "##cms-context##/{mode}/{lang}/##ref:link" + count + "##.html" + params);
                        }
                        try {
                            ref = URLDecoder.decode(ref, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                        }

                        if (!references.containsKey(ref)) {
                            references.put(ref, new ArrayList<String>());
                        }
                        references.get(ref)
                                .add(n.getIdentifier() + "/[" + count + "]" + propertyDefinition.getName());
                        count++;
                    }
                    value = buf.toString();
                }
                n.setProperty(propertyName, value);
                if (logger.isDebugEnabled())
                    logger.debug("Setting on node " + n.getPath() + " property " + propertyName + " with value="
                            + value);
                break;
            }
            default: {
                String[] vcs = propertyDefinition.getValueConstraints();
                List<String> constraints = Arrays.asList(vcs);
                if (!propertyDefinition.isMultiple()) {
                    if (value.startsWith("<jahia-resource")) {
                        value = ResourceBundleMarker.parseMarkerValue(value).getResourceKey();
                        if (value.startsWith(propertyDefinition.getResourceBundleKey())) {
                            value = value.substring(propertyDefinition.getResourceBundleKey().length() + 1);
                        }
                    } else if ("jcr:description".equals(propertyName)) {
                        value = removeHtmlTags(value);
                    }

                    value = baseType != null ? mapping.getMappedPropertyValue(baseType, localName, value)
                            : value;
                    if (valueMatchesContraints(value, constraints)) {
                        try {
                            n.setProperty(propertyName, value);
                            if (logger.isDebugEnabled())
                                logger.debug("Setting on node " + n.getPath() + " property " + propertyName
                                        + " with value=" + value);
                        } catch (Exception e) {
                            logger.error("Impossible to set property " + propertyName + " due to exception", e);
                        }
                    } else {
                        logger.error(
                                "Impossible to set property " + propertyName + " due to some constraint error");
                        logger.error(" - value       = " + value);
                        logger.error(" - constraints = " + constraints.toString());
                    }
                } else {
                    String[] strings = Patterns.TRIPPLE_DOLLAR.split(value);
                    List<Value> values = new ArrayList<Value>();
                    for (String string : strings) {

                        if (string.startsWith("<jahia-resource")) {
                            string = ResourceBundleMarker.parseMarkerValue(string).getResourceKey();
                            if (string.startsWith(propertyDefinition.getResourceBundleKey())) {
                                string = string
                                        .substring(propertyDefinition.getResourceBundleKey().length() + 1);
                            }
                        }
                        value = baseType != null ? mapping.getMappedPropertyValue(baseType, localName, value)
                                : value;
                        if (constraints.isEmpty() || constraints.contains(value)) {
                            values.add(new ValueImpl(string, propertyDefinition.getRequiredType()));
                        }
                    }
                    n.setProperty(propertyName, values.toArray(new Value[values.size()]));
                    if (logger.isDebugEnabled())
                        logger.debug("Setting on node " + n.getPath() + " property " + propertyName
                                + " with value=" + values);
                }
                break;
            }
            }
        }
    } else {
        return false;
    }

    return true;
}

From source file:com.ushahidi.swiftriver.core.api.controller.RiversController.java

/**
 * Get drops in the river./* w w  w  .  ja va  2s .c  o m*/
 * 
 * @return
 * @throws NotFoundException
 */
@RequestMapping(value = "/{id}/drops", method = RequestMethod.GET)
@ResponseBody
public List<GetDropDTO> getDrops(@PathVariable Long id, Principal principal,
        @RequestParam(value = "count", required = false, defaultValue = "10") Integer count,
        @RequestParam(value = "max_id", required = false) Long maxId,
        @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
        @RequestParam(value = "since_id", required = false) Long sinceId,
        @RequestParam(value = "date_from", required = false) String dateFromS,
        @RequestParam(value = "date_to", required = false) String dateToS,
        @RequestParam(value = "keywords", required = false) String keywords,
        @RequestParam(value = "channels", required = false) String channels,
        @RequestParam(value = "channel_ids", required = false) String cIds,
        @RequestParam(value = "state", required = false) String state,
        @RequestParam(value = "photos", required = false) Boolean photos,
        @RequestParam(value = "locations", required = false) String locations) throws NotFoundException {

    if (maxId == null) {
        maxId = Long.MAX_VALUE;
    }

    List<ErrorField> errors = new ArrayList<ErrorField>();

    List<Long> channelIds = new ArrayList<Long>();
    if (cIds != null) {
        for (String cId : cIds.split(",")) {
            try {
                channelIds.add(Long.parseLong(cId));
            } catch (NumberFormatException ex) {
                errors.add(new ErrorField("channel_ids", "invalid"));
            }
        }
    }

    List<String> channelList = new ArrayList<String>();
    if (channels != null) {
        channelList.addAll(Arrays.asList(channels.split(",")));
    }

    Boolean isRead = null;
    if (state != null) {
        if (state.equalsIgnoreCase("read") || state.equalsIgnoreCase("unread")) {
            isRead = state.equalsIgnoreCase("read");
        } else {
            errors.add(new ErrorField("state", "invalid"));
        }
    }

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy");
    Date dateFrom = null;
    if (dateFromS != null) {
        try {
            dateFrom = dateFormat.parse(dateFromS);
        } catch (ParseException e) {
            errors.add(new ErrorField("date_from", "invalid"));
        }
    }

    Date dateTo = null;
    if (dateToS != null) {
        try {
            dateTo = dateFormat.parse(dateToS);
        } catch (ParseException e) {
            errors.add(new ErrorField("date_to", "invalid"));
        }
    }

    if (!errors.isEmpty()) {
        BadRequestException e = new BadRequestException("Invalid parameter.");
        e.setErrors(errors);
        throw e;
    }

    // Build the drop filter
    DropFilter dropFilter = new DropFilter();
    dropFilter.setMaxId(maxId);
    dropFilter.setSinceId(sinceId);
    dropFilter.setChannels(channelList);
    dropFilter.setChannelIds(channelIds);

    try {
        dropFilter.setDateFrom(dateFrom);
    } catch (InvalidFilterException e) {
        errors.add(new ErrorField("date_from", e.getMessage()));
    }

    try {
        dropFilter.setDateTo(dateTo);
    } catch (InvalidFilterException e) {
        errors.add(new ErrorField("date_to", e.getMessage()));
    }

    dropFilter.setRead(isRead);
    dropFilter.setPhotos(photos);
    dropFilter.setKeywords(keywords);
    dropFilter.setBoundingBox(locations);

    // Check for errors
    if (!errors.isEmpty()) {
        BadRequestException exception = new BadRequestException();
        exception.setErrors(errors);
        throw exception;
    }

    return riverService.getDrops(id, dropFilter, page, count, principal.getName());
}

From source file:com.evolveum.polygon.connector.ldap.schema.AbstractSchemaTranslator.java

private Object toIcfValue(String icfAttributeName, Value<?> ldapValue, String ldapAttributeName,
        AttributeType ldapAttributeType) {
    if (ldapValue == null) {
        return null;
    }//  w w  w.  ja  v  a2  s  .  c o  m
    if (OperationalAttributeInfos.PASSWORD.is(icfAttributeName)) {
        return new GuardedString(ldapValue.getString().toCharArray());
    } else {
        String syntaxOid = null;
        if (ldapAttributeType != null) {
            syntaxOid = ldapAttributeType.getSyntaxOid();
        }
        if (SchemaConstants.GENERALIZED_TIME_SYNTAX.equals(syntaxOid)) {
            if (AbstractLdapConfiguration.TIMESTAMP_PRESENTATION_UNIX_EPOCH
                    .equals(getConfiguration().getTimestampPresentation())) {
                try {
                    GeneralizedTime gt = new GeneralizedTime(ldapValue.getString());
                    return gt.getCalendar().getTimeInMillis();
                } catch (ParseException e) {
                    throw new InvalidAttributeValueException("Wrong generalized time format in LDAP attribute "
                            + ldapAttributeName + ": " + e.getMessage(), e);
                }
            } else {
                return ldapValue.getString();
            }
        } else if (SchemaConstants.BOOLEAN_SYNTAX.equals(syntaxOid)) {
            return Boolean.parseBoolean(ldapValue.getString());
        } else if (isIntegerSyntax(syntaxOid)) {
            return Integer.parseInt(ldapValue.getString());
        } else if (isLongSyntax(syntaxOid)) {
            return Long.parseLong(ldapValue.getString());
        } else if (isBinarySyntax(syntaxOid)) {
            LOG.ok("Converting to ICF: {0} (syntax {1}, value {2}): explicit binary", ldapAttributeName,
                    syntaxOid, ldapValue.getClass());
            return ldapValue.getBytes();
        } else if (isStringSyntax(syntaxOid)) {
            LOG.ok("Converting to ICF: {0} (syntax {1}, value {2}): explicit string", ldapAttributeName,
                    syntaxOid, ldapValue.getClass());
            return ldapValue.getString();
        } else {
            if (ldapValue instanceof StringValue) {
                LOG.ok("Converting to ICF: {0} (syntax {1}, value {2}): detected string", ldapAttributeName,
                        syntaxOid, ldapValue.getClass());
                return ldapValue.getString();
            } else {
                LOG.ok("Converting to ICF: {0} (syntax {1}, value {2}): detected binary", ldapAttributeName,
                        syntaxOid, ldapValue.getClass());
                return ldapValue.getBytes();
            }
        }
    }
}

From source file:com.vmware.identity.idm.server.provider.ldap.LdapProvider.java

private int getAccountFlags(ILdapEntry entry) {
    final String ATTR_ACCOUNT_FLAGS = _ldapSchemaMapping
            .getUserAttribute(IdentityStoreAttributeMapping.AttributeIds.UserAttributeAcountControl);
    final String ATTR_PWD_ACCOUNT_LOCKED_TIME = getMappedAttrPwdAccountLockedTime();
    int currentFlag = 0;
    if (entry.getAttributeValues(ATTR_ACCOUNT_FLAGS) != null) {
        currentFlag = getOptionalIntegerValue(entry.getAttributeValues(ATTR_ACCOUNT_FLAGS), 0);
    } else if (entry.getAttributeValues(ATTR_PWD_ACCOUNT_LOCKED_TIME) != null) {
        String generalizedTime = getOptionalStringValue(entry.getAttributeValues(ATTR_PWD_ACCOUNT_LOCKED_TIME));
        if (StringUtils.isNotEmpty(generalizedTime)) {
            // handle special case when account is permanently locked
            // http://tools.ietf.org/html/draft-behera-ldap-password-policy-10#section-5.3
            if (generalizedTime.equals("000001010000Z")) {
                log.info("User account is permanently locked!");
                return AccountControlFlag.FLAG_LOCKED_ACCOUNT.getValue();
            }/*from ww w  .j av  a2 s .c  o  m*/
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
            formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
            boolean accountLocked = false;
            try {
                Date lockedTs = formatter.parse(generalizedTime);
                long lockoutDur = getLockoutDurationSettings();
                if (lockoutDur == INVALID_VALUE_PWD_LOCKOUT_DURATION) {//invalid setting -- cannot load due to multiple entries or no entries
                    return currentFlag;
                } else {
                    accountLocked = !(lockedTs
                            .getTime() < (System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(lockoutDur)));
                }
            } catch (ParseException e) {
                throw new IllegalArgumentException(e.getMessage());
            }
            if (accountLocked) {
                currentFlag = AccountControlFlag.FLAG_LOCKED_ACCOUNT.getValue();
            }
        }
    }
    return currentFlag;
}

From source file:com.baidu.gcrm.customer.service.impl.CustomerServiceImpl.java

/**
 * /* w  ww  . jav  a 2s  .  co  m*/
 * ??: ? ????????
 * processOtherInfo
 * @:    chenchunhui01
 * @:    2014715 ?3:55:46     
 * @param record
 * @param locale   
 * @return void  
 * @exception   
 * @version
 */
private void processOtherInfo(Map<String, Object> record, LocaleConstants locale) {
    Object filed = record.get(ModifyRecordConstant.TABLEFIELD_KEY);
    if (filed == null) {
        return;
    }
    String filedName = filed.toString();
    String newValueKey = "";
    if (record.get(ModifyRecordConstant.NEWVALUE_KEY) != null)
        newValueKey = record.get(ModifyRecordConstant.NEWVALUE_KEY).toString();
    String oldValueKey = "";
    if (record.get(ModifyRecordConstant.OLDVALUE_KEY) != null)
        oldValueKey = record.get(ModifyRecordConstant.OLDVALUE_KEY).toString();

    if ("customerType".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    MessageHelper.getMessage("customer.type." + newValueKey, locale));
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    MessageHelper.getMessage("customer.type." + oldValueKey, locale));
    } else if ("companySize".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    MessageHelper.getMessage("customer.companySize." + newValueKey, locale));
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    MessageHelper.getMessage("customer.companySize." + oldValueKey, locale));
    } else if ("country".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    countryCacheServiceImpl.getByIdAndLocale(newValueKey, locale).getI18nName());
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    countryCacheServiceImpl.getByIdAndLocale(oldValueKey, locale).getI18nName());
    } else if ("industry".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    industryServiceImpl.getByIdAndLocale(newValueKey, locale).getI18nName());
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    industryServiceImpl.getByIdAndLocale(oldValueKey, locale).getI18nName());
    } else if ("belongSales".equals(filedName) || "belongManager".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey)) {
            User user = userService.findByUcid(Long.valueOf(newValueKey));
            if (user != null)
                record.put(ModifyRecordConstant.NEWVALUE_KEY, user.getRealname());
            else
                record.put(ModifyRecordConstant.NEWVALUE_KEY, "");
        }
        if (StringUtils.isNotBlank(oldValueKey)) {
            User user = userService.findByUcid(Long.valueOf(oldValueKey));
            if (user != null)
                record.put(ModifyRecordConstant.OLDVALUE_KEY, user.getRealname());
            else
                record.put(ModifyRecordConstant.NEWVALUE_KEY, "");
        }
    } else if ("agentType".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    MessageHelper.getMessage("customer.agentType." + newValueKey, locale));
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    MessageHelper.getMessage("customer.agentType." + oldValueKey, locale));
    } else if ("agentRegional".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    agentRegionalService.getByIdAndLocale(newValueKey, locale).getI18nName());
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    agentRegionalService.getByIdAndLocale(oldValueKey, locale).getI18nName());
    } else if ("agentCountry".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey)) {
            String[] countryIds = newValueKey.split(",");
            StringBuffer countryName = new StringBuffer();
            for (String countryId : countryIds) {
                countryName.append(countryCacheServiceImpl.getByIdAndLocale(countryId, locale).getI18nName());
                countryName.append("?");
            }
            if (countryName.length() > 0) {
                record.put(ModifyRecordConstant.NEWVALUE_KEY,
                        countryName.subSequence(0, countryName.length() - 1));
            } else {
                record.put(ModifyRecordConstant.NEWVALUE_KEY, "");
            }
        }
        if (StringUtils.isNotBlank(oldValueKey)) {
            String[] countryIds = oldValueKey.split(",");
            StringBuffer countryName = new StringBuffer();

            for (String countryId : countryIds) {
                countryName.append(countryCacheServiceImpl.getByIdAndLocale(countryId, locale).getI18nName());
                countryName.append("?");
            }
            if (countryName.length() > 0) {
                record.put(ModifyRecordConstant.OLDVALUE_KEY,
                        countryName.subSequence(0, countryName.length() - 1));
            } else {
                record.put(ModifyRecordConstant.OLDVALUE_KEY, "");
            }
        }
    } else if ("businessType".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey)) {
            String[] businessKeys = newValueKey.split(",");
            StringBuffer businessTypeNames = new StringBuffer();
            for (String businessTypeKey : businessKeys) {
                businessTypeNames
                        .append(MessageHelper.getMessage("customer.businessType." + businessTypeKey, locale));
                businessTypeNames.append("?");
            }
            if (businessTypeNames.length() > 0) {
                record.put(ModifyRecordConstant.NEWVALUE_KEY,
                        businessTypeNames.subSequence(0, businessTypeNames.length() - 1));
            } else {
                record.put(ModifyRecordConstant.NEWVALUE_KEY, "");
            }
        }
        if (StringUtils.isNotBlank(oldValueKey)) {
            String[] businessKeys = oldValueKey.split(",");
            StringBuffer businessTypeNames = new StringBuffer();
            for (String businessTypeKey : businessKeys) {
                businessTypeNames
                        .append(MessageHelper.getMessage("customer.businessType." + businessTypeKey, locale));
                businessTypeNames.append("?");
            }
            if (businessTypeNames.length() > 0) {
                record.put(ModifyRecordConstant.OLDVALUE_KEY,
                        businessTypeNames.subSequence(0, businessTypeNames.length() - 1));
            } else {
                record.put(ModifyRecordConstant.OLDVALUE_KEY, "");
            }
        }

    } else if ("registerTime".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey)) {
            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy", Locale.ENGLISH);
            try {
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
                record.put(ModifyRecordConstant.NEWVALUE_KEY, sdf1.format(sdf.parse(newValueKey)));
            } catch (ParseException e) {
                LoggerHelper.err(getClass(), e.getMessage(), e);
            }
        }
        if (StringUtils.isNotBlank(oldValueKey)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
                record.put(ModifyRecordConstant.OLDVALUE_KEY, sdf1.format(sdf.parse(oldValueKey)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    } else if ("currencyType".equals(filedName)) {
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    currencyTypeServiceImpl.getByIdAndLocale(newValueKey, locale).getI18nName());
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    currencyTypeServiceImpl.getByIdAndLocale(oldValueKey, locale).getI18nName());
    } else if ("type".equals(filedName)) {
        //?
        if (StringUtils.isNotBlank(newValueKey))
            record.put(ModifyRecordConstant.NEWVALUE_KEY,
                    MessageHelper.getMessage("customer.attachment.type." + newValueKey, locale));
        if (StringUtils.isNotBlank(oldValueKey))
            record.put(ModifyRecordConstant.OLDVALUE_KEY,
                    MessageHelper.getMessage("customer.attachment.type." + oldValueKey, locale));
    }
}

From source file:com.topsec.tsm.sim.report.model.ReportModel.java

private static String countTime(String time, String type) {
    int minuteV = 0;
    SimpleDateFormat sdf = new SimpleDateFormat(ReportUiConfig.dFormat1);
    Date date = null;/*from w ww . j  av  a  2s.co m*/
    Calendar calendar = Calendar.getInstance();
    try {
        date = sdf.parse(time);
    } catch (ParseException e) {
        log.error(e.getMessage());
    }
    calendar.setTime(date);

    if ("hour".equals(type)) {
        calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) / 10 * 10);
        calendar.set(Calendar.SECOND, 0);
        date = calendar.getTime();
        time = sdf.format(date);
    } else if ("day".equals(type)) {
        minuteV = calendar.get(Calendar.HOUR_OF_DAY);
        if (minuteV > 18) {
            calendar.set(Calendar.HOUR_OF_DAY, 18);
        } else if (minuteV > 12) {
            calendar.set(Calendar.HOUR_OF_DAY, 12);
        } else if (minuteV > 6) {
            calendar.set(Calendar.HOUR_OF_DAY, 6);
        } else if (minuteV > 0) {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
        }
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        date = calendar.getTime();
        time = sdf.format(date);
    }
    return time;
}

From source file:au.org.theark.core.dao.DataExtractionDao.java

/**
 * Simple export to CSV as first cut//from w  w  w .j  a va 2s .c om
 */
public File createSubjectDemographicCSV(Search search, DataExtractionVO devo,
        List<DemographicField> allSubjectFields, List<CustomFieldDisplay> cfds, FieldCategory fieldCategory) {
    final String tempDir = System.getProperty("java.io.tmpdir");
    String filename = new String("SUBJECTDEMOGRAPHICS.csv");
    final java.io.File file = new File(tempDir, filename);
    if (filename == null || filename.isEmpty()) {
        filename = "exportcsv.csv";
    }

    HashMap<String, ExtractionVO> hashOfSubjectsWithData = devo.getDemographicData();
    HashMap<String, ExtractionVO> hashOfSubjectCustomData = devo.getSubjectCustomData();

    OutputStream outputStream;
    try {
        outputStream = new FileOutputStream(file);
        CsvWriter csv = new CsvWriter(outputStream);

        // Header
        csv.write("SUBJECTUID");

        Set<String> demofields = new HashSet<String>();
        for (String subjectUID : hashOfSubjectsWithData.keySet()) {
            HashMap<String, String> keyValues = hashOfSubjectsWithData.get(subjectUID).getKeyValues();
            demofields.addAll((keyValues.keySet()));
        }
        for (String demoField : demofields) {
            csv.write(demoField);
        }
        for (CustomFieldDisplay cfd : cfds) {
            csv.write(cfd.getCustomField().getName());
        }
        csv.endLine();

        for (String subjectUID : hashOfSubjectsWithData.keySet()) {
            csv.write(subjectUID);

            for (String demoField : demofields) {
                HashMap<String, String> keyValues = hashOfSubjectsWithData.get(subjectUID).getKeyValues();
                csv.write(keyValues.get(demoField));

            }

            /**
             * for (String subjectUID : hashOfSubjectsWithData.keySet()) { HashMap<String, String> keyValues =
             * hashOfSubjectsWithData.get(subjectUID).getKeyValues(); log.info(subjectUID + " has " + keyValues.size() + "demo fields"); //
             * remove(subjectUID).getKeyValues().size() + "demo fields"); for (String key : keyValues.keySet()) { log.info("     key=" + key +
             * "\t   value=" + keyValues.get(key)); } }
             */
            ExtractionVO evo = hashOfSubjectCustomData.get(subjectUID);
            if (evo != null) {
                HashMap<String, String> keyValues = evo.getKeyValues();
                for (CustomFieldDisplay cfd : cfds) {

                    String valueResult = keyValues.get(cfd.getCustomField().getName());
                    if (cfd.getCustomField().getFieldType().getName()
                            .equalsIgnoreCase(Constants.FIELD_TYPE_DATE) && valueResult != null) {
                        try {
                            DateFormat dateFormat = new SimpleDateFormat(
                                    au.org.theark.core.Constants.DD_MM_YYYY);
                            String[] dateFormats = { au.org.theark.core.Constants.DD_MM_YYYY,
                                    au.org.theark.core.Constants.yyyy_MM_dd_hh_mm_ss_S };
                            Date date = DateUtils.parseDate(valueResult, dateFormats);
                            csv.write(dateFormat.format(date));
                        } catch (ParseException e) {
                            csv.write(valueResult);
                        }
                    } else {
                        csv.write(valueResult);
                    }
                }
            } else {
                // Write out a line with no values (no data existed for subject in question
                for (CustomFieldDisplay cfd : cfds) {
                    csv.write("");
                }
            }

            csv.endLine();
        }
        csv.close();
    } catch (FileNotFoundException e) {
        log.error(e.getMessage());
    }

    return file;
}

From source file:org.openmrs.module.rheapocadapter.impl.HL7MessageTransformer.java

public List<Obs> fromORU_R01toObs(ORU_R01 oru) throws HL7Exception {

    // validate message
    validate(oru);//from w  w w .j  ava  2  s.  c  om
    List<Obs> obses = new ArrayList<Obs>();
    // extract segments for convenient use below
    MSH msh = getMSH(oru);
    PID pid = getPID(oru);
    String messageControlId = msh.getMessageControlID().getValue();
    if (log.isDebugEnabled())
        log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);

    Patient patient = getPatient(pid);
    if (log.isDebugEnabled())
        log.debug("Processing HL7 message for patient " + patient.getPatientId());
    // create observations
    if (log.isDebugEnabled())
        log.debug("Creating observations for message " + messageControlId + "...");
    ORU_R01_PATIENT_RESULT patientResult = oru.getPATIENT_RESULT();
    int numObr = patientResult.getORDER_OBSERVATIONReps();
    for (int i = 0; i < numObr; i++) {
        if (log.isDebugEnabled())
            log.debug("Processing OBR (" + i + " of " + numObr + ")");
        ORU_R01_ORDER_OBSERVATION orderObs = patientResult.getORDER_OBSERVATION(i);
        // the parent obr
        OBR obr = orderObs.getOBR();
        int numObs = orderObs.getOBSERVATIONReps();
        for (int j = 0; j < numObs; j++) {
            if (log.isDebugEnabled())
                log.debug("Processing OBS (" + j + " of " + numObs + ")");

            OBX obx = orderObs.getOBSERVATION(j).getOBX();
            PV1 pv1 = oru.getPATIENT_RESULT().getPATIENT().getVISIT().getPV1();
            Obs obs;
            try {
                obs = parseObs(obx, obr, pid, pv1);

                if (!obs.getValueText().equals(null))
                    obs.setValueText(obs.getValueText() + "/" + oru.toString());
                else
                    obs.setValueText(oru.toString());

                obses.add(obs);
            } catch (ParseException e) {
                log.error("Unable to parse" + e.getMessage());
            }
        }
    }
    return (obses.isEmpty()) ? obses : null;

}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductBundlesController.java

/**
 * This method list the product bundles//  w  ww  . j  a  va  2  s  . c  o m
 * 
 * @param currentTenant
 * @param tenantParam
 * @param serviceInstaceUuid
 * @param resourceType
 * @param filters
 * @param context
 * @param viewCatalog
 * @param revision
 * @param channelId
 * @param currencyCode
 * @param historyDate
 * @param dateFormat
 * @param request
 * @return
 */
@RequestMapping(value = { "list.json" }, method = RequestMethod.POST)
@ResponseBody
public List<ProductBundleRevision> listProductBundles(@ModelAttribute("currentTenant") Tenant currentTenant,
        @RequestParam(value = "tenant", required = false) String tenantParam,
        @RequestParam(value = "serviceInstaceUuid", required = false) String serviceInstaceUuid,
        @RequestParam(value = "resourceType", required = false) String resourceType,
        @RequestParam(value = "filters", required = false) String filters,
        @RequestParam(value = "context", required = false) String context,
        @RequestParam(value = "viewCatalog", required = false, defaultValue = "false") Boolean viewCatalog,
        @RequestParam(value = "revision", required = false) String revision,
        @RequestParam(value = "channelParam", required = false) String channelId,
        @RequestParam(value = "currencyCode", required = false) String currencyCode,
        @RequestParam(value = "revisionDate", required = false, defaultValue = "") String historyDate,
        @RequestParam(value = "dateFormat", required = false) String dateFormat, HttpServletRequest request) {
    logger.debug("# listProductBundles method entered...(list.json)");

    Tenant effectiveTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY);
    User user = actorService.getActor();
    boolean anonymousBrowsing = false;
    if (getCurrentUser() == null) {
        anonymousBrowsing = true;
    }
    if (!anonymousBrowsing && !user.getTenant().equals(effectiveTenant)) {
        user = effectiveTenant.getOwner();
    }

    ServiceInstance serviceInstance = connectorConfigurationManager.getInstanceByUUID(serviceInstaceUuid);
    ServiceResourceType serviceResourceType = connectorConfigurationManager
            .getServiceResourceType(serviceInstaceUuid, resourceType);
    List<ProductBundleRevision> filteredBundleRevisions = new ArrayList<ProductBundleRevision>();
    Date historyDateObj = null;
    Channel channel = null;
    if (StringUtils.isNotBlank(channelId)) {
        channel = channelService.getChannelById(channelId);
    } else {
        channel = channelService.getDefaultServiceProviderChannel();
    }
    CurrencyValue currency = currencyValueService.locateBYCurrencyCode(currencyCode);
    if (viewCatalog == true && user.getTenant().equals(tenantService.getSystemTenant())) {
        Revision channelRevision = null;
        Boolean includeFutureBundle = false;
        if (StringUtils.isBlank(revision) || revision.equalsIgnoreCase("current")) {
            channelRevision = channelService.getCurrentRevision(channel);
        } else if (revision.equalsIgnoreCase("planned")) {
            includeFutureBundle = true;
            channelRevision = channelService.getFutureRevision(channel);
        } else if (revision.equalsIgnoreCase("history")) {

            if (historyDate != null && !historyDate.isEmpty()) {
                dateFormat = "MM/dd/yyyy HH:mm:ss";
                DateFormat formatter = new SimpleDateFormat(dateFormat);
                try {
                    historyDateObj = formatter.parse(historyDate);
                } catch (ParseException e) {
                    throw new InvalidAjaxRequestException(e.getMessage());
                }
            } else {
                List<Date> historyDatesForCatalog = productService.getHistoryDates(channel.getCatalog());
                historyDateObj = historyDatesForCatalog.get(0);
            }
            channelRevision = channelService.getRevisionForTheDateGiven(historyDateObj, channel);
        }
        filteredBundleRevisions = productBundleService.getProductBundleRevisions(serviceInstance,
                serviceResourceType, createStringMapCombined(context), createStringMapCombined(filters), user,
                getSessionLocale(request), channel, currency, channelRevision, includeFutureBundle);
    } else if (anonymousBrowsing) {
        filteredBundleRevisions = productBundleService.listAnonymousProductBundleRevisions(serviceInstance,
                serviceResourceType, createStringMapCombined(context), createStringMapCombined(filters), user,
                getSessionLocale(request), channel, currency);
    } else {
        filteredBundleRevisions = productBundleService.getProductBundleRevisions(serviceInstance,
                serviceResourceType, createStringMapCombined(context), createStringMapCombined(filters), user,
                getSessionLocale(request));
    }

    logger.debug("# listProductBundles method leaving...(list.json)");

    return getLighterProductBundles(filteredBundleRevisions);
}