Example usage for org.joda.time LocalDate parse

List of usage examples for org.joda.time LocalDate parse

Introduction

In this page you can find the example usage for org.joda.time LocalDate parse.

Prototype

@FromString
public static LocalDate parse(String str) 

Source Link

Document

Parses a LocalDate from the specified string.

Usage

From source file:org.apache.sqoop.connector.idf.CSVIntermediateDataFormat.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w w . jav  a 2  s .co  m*/
 */
@Override
public Object[] getObjectData() {
    if (schema.isEmpty()) {
        throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0006);
    }

    String[] fields = getFields();

    if (fields == null) {
        return null;
    }

    if (fields.length != schema.getColumns().size()) {
        throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0005,
                "The data " + getTextData() + " has the wrong number of fields.");
    }

    Object[] out = new Object[fields.length];
    Column[] cols = schema.getColumns().toArray(new Column[fields.length]);
    for (int i = 0; i < fields.length; i++) {
        Type colType = cols[i].getType();
        if (fields[i].equals("NULL")) {
            out[i] = null;
            continue;
        }

        Long byteSize;
        switch (colType) {
        case TEXT:
            out[i] = unescapeStrings(fields[i]);
            break;
        case BINARY:
            out[i] = unescapeByteArray(fields[i]);
            break;
        case FIXED_POINT:
            byteSize = ((FixedPoint) cols[i]).getByteSize();
            if (byteSize != null && byteSize <= Integer.SIZE) {
                out[i] = Integer.valueOf(fields[i]);
            } else {
                out[i] = Long.valueOf(fields[i]);
            }
            break;
        case FLOATING_POINT:
            byteSize = ((FloatingPoint) cols[i]).getByteSize();
            if (byteSize != null && byteSize <= Float.SIZE) {
                out[i] = Float.valueOf(fields[i]);
            } else {
                out[i] = Double.valueOf(fields[i]);
            }
            break;
        case DECIMAL:
            out[i] = new BigDecimal(fields[i]);
            break;
        case DATE:
            out[i] = LocalDate.parse(fields[i]);
            break;
        case DATE_TIME:
            // A datetime string with a space as date-time separator will not be
            // parsed expectedly. The expected separator is "T". See also:
            // https://github.com/JodaOrg/joda-time/issues/11
            String iso8601 = fields[i].replace(" ", "T");
            out[i] = LocalDateTime.parse(iso8601);
            break;
        case BIT:
            out[i] = Boolean.valueOf(fields[i].equals("1") || fields[i].toLowerCase().equals("true"));
            break;
        default:
            throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004,
                    "Column type from schema was not recognized for " + colType);
        }
    }
    return out;
}

From source file:org.apache.tajo.datum.DatumFactory.java

License:Apache License

public static DateDatum createDate(String dateStr) {
    return new DateDatum(LocalDate.parse(dateStr));
}

From source file:org.biokoframework.system.repository.sql.translator.annotation.impl.LocalDateTranslator.java

License:Open Source License

@Override
public void insertIntoStatement(String fieldName, Object fieldValue, Field fieldAnnotation,
        PreparedStatement statement, int sqlIndex) throws SQLException {
    if (fieldValue == null) {
        statement.setObject(sqlIndex, null);
    } else {/*ww w  .j av  a2  s .  co  m*/
        LocalDate timestamp = LocalDate.parse((String) fieldValue);
        statement.setString(sqlIndex, timestamp.toString(DateTimeFormat.forPattern(MYSQL_DATE)));
    }
}

From source file:org.estatio.dom.valuetypes.LocalDateInterval.java

License:Apache License

/**
 * Parse a string to a LocalDate/*w w w.j av a 2  s . com*/
 * 
 * @param input  a string representing a parsable LocalDate, "*" or "----------" returns null
 * @return
 */
private static LocalDate parseLocalDate(final String input) {
    if (input.contains("--") || input.contains("*")) {
        return null;
    }
    return LocalDate.parse(input);
}

From source file:org.flowable.form.engine.impl.cmd.AbstractGetFormInstanceModelCmd.java

License:Apache License

public void fillVariablesWithFormValues(Map<String, JsonNode> submittedFormFieldMap,
        List<FormField> allFields) {
    for (FormField field : allFields) {

        JsonNode fieldValueNode = submittedFormFieldMap.get(field.getId());

        if (fieldValueNode == null || fieldValueNode.isNull()) {
            continue;
        }//from www  .  ja  v a  2 s .  co m

        String fieldType = field.getType();
        String fieldValue = fieldValueNode.asText();

        if (FormFieldTypes.DATE.equals(fieldType)) {
            try {
                if (StringUtils.isNotEmpty(fieldValue)) {
                    LocalDate dateValue = LocalDate.parse(fieldValue);
                    variables.put(field.getId(), dateValue.toString("d-M-yyyy"));
                }
            } catch (Exception e) {
                LOGGER.error("Error parsing form date value for process instance {} and task {} with value {}",
                        processInstanceId, taskId, fieldValue, e);
            }

        } else if (fieldValueNode.isBoolean()) {
            variables.put(field.getId(), fieldValueNode.asBoolean());

        } else if (fieldValueNode.isLong()) {
            variables.put(field.getId(), fieldValueNode.asLong());

        } else if (fieldValueNode.isDouble()) {
            variables.put(field.getId(), fieldValueNode.asDouble());

        } else {
            variables.put(field.getId(), fieldValue);
        }
    }
}

From source file:org.flowable.form.engine.impl.cmd.GetFormInstanceModelCmd.java

License:Apache License

public void fillVariablesWithFormValues(Map<String, JsonNode> submittedFormFieldMap,
        List<FormField> allFields) {
    for (FormField field : allFields) {

        JsonNode fieldValueNode = submittedFormFieldMap.get(field.getId());

        if (fieldValueNode == null || fieldValueNode.isNull()) {
            continue;
        }//w  ww  .j  a v  a2s  . c  om

        String fieldType = field.getType();
        String fieldValue = fieldValueNode.asText();

        if (FormFieldTypes.DATE.equals(fieldType)) {
            try {
                if (StringUtils.isNotEmpty(fieldValue)) {
                    LocalDate dateValue = LocalDate.parse(fieldValue);
                    variables.put(field.getId(), dateValue.toString("d-M-yyyy"));
                }
            } catch (Exception e) {
                logger.error("Error parsing form date value for process instance {} and task {} with value {}",
                        processInstanceId, taskId, fieldValue, e);
            }

        } else {
            variables.put(field.getId(), fieldValue);
        }
    }
}

From source file:org.flowable.form.engine.impl.cmd.GetFormModelWithVariablesCmd.java

License:Apache License

public void fillVariablesWithFormInstanceValues(Map<String, JsonNode> formInstanceFieldMap,
        List<FormField> allFields) {
    for (FormField field : allFields) {

        JsonNode fieldValueNode = formInstanceFieldMap.get(field.getId());

        if (fieldValueNode == null || fieldValueNode.isNull()) {
            continue;
        }//from   ww  w.  j a v  a  2s.c om

        String fieldType = field.getType();
        String fieldValue = fieldValueNode.asText();

        if (FormFieldTypes.DATE.equals(fieldType)) {
            try {
                if (StringUtils.isNotEmpty(fieldValue)) {
                    LocalDate dateValue = LocalDate.parse(fieldValue);
                    variables.put(field.getId(), dateValue);
                }
            } catch (Exception e) {
                logger.error("Error parsing form date value for process instance {} with value {}",
                        processInstanceId, fieldValue, e);
            }

        } else {
            variables.put(field.getId(), fieldValue);
        }
    }
}

From source file:org.flowable.form.engine.impl.cmd.GetVariablesFromFormSubmissionCmd.java

License:Apache License

@SuppressWarnings("unchecked")
protected Object transformFormFieldValueToVariableValue(FormField formField, Object formFieldValue) {

    Object result = formFieldValue;
    if (formField.getType().equals(FormFieldTypes.DATE)) {
        if (StringUtils.isNotEmpty((String) formFieldValue)) {
            try {
                result = LocalDate.parse((String) formFieldValue);

            } catch (Exception e) {
                e.printStackTrace();/*from w  w  w  . ja va2  s  .c  om*/
                result = null;
            }
        }

    } else if (formField.getType().equals(FormFieldTypes.INTEGER) && formFieldValue instanceof String) {
        String strFieldValue = (String) formFieldValue;
        if (StringUtils.isNotEmpty(strFieldValue) && NumberUtils.isNumber(strFieldValue)) {
            result = Long.valueOf(strFieldValue);

        } else {
            result = null;
        }

    } else if (formField.getType().equals(FormFieldTypes.AMOUNT) && formFieldValue instanceof String) {
        try {
            result = Double.parseDouble((String) formFieldValue);

        } catch (NumberFormatException e) {
            result = null;
        }

    } else if (formField.getType().equals(FormFieldTypes.DROPDOWN)) {
        if (formFieldValue instanceof Map<?, ?>) {
            result = ((Map<?, ?>) formFieldValue).get("id");
            if (result == null) {
                // fallback to name for manual config options
                result = ((Map<?, ?>) formFieldValue).get("name");
            }
        }

    } else if (formField.getType().equals(FormFieldTypes.UPLOAD)) {
        result = (String) formFieldValue;

    } else if (formField.getType().equals(FormFieldTypes.PEOPLE)
            || formField.getType().equals(FormFieldTypes.FUNCTIONAL_GROUP)) {
        if (formFieldValue instanceof Map<?, ?>) {
            Map<String, Object> value = (Map<String, Object>) formFieldValue;
            Object id = value.get("id");
            if (id instanceof Number) {
                result = ((Number) id).longValue();

            } else {
                // Wrong type, ignore
                result = null;
            }
        } else {
            // Incorrect or empty map, ignore
            result = null;
        }
    }

    // Default: no processing needs to be done, can be stored as-is
    return result;
}

From source file:org.goobi.production.model.bibliography.course.Course.java

License:Open Source License

/**
 * Constructor to create a course from an xml source.
 *
 * @param xml/*from   w  w  w .  ja va2s . co  m*/
 *            XML document data structure
 * @throws NoSuchElementException
 *             if ELEMENT_COURSE or ELEMENT_PROCESSES cannot be found
 * @throws IllegalArgumentException
 *             if the dates of two blocks do overlap
 * @throws NullPointerException
 *             if a mandatory element is absent
 */
public Course(Document xml) throws NoSuchElementException {
    super();
    processesAreVolatile = false;
    Element rootNode = XMLUtils.getFirstChildWithTagName(xml, ELEMENT_COURSE);
    Element processesNode = XMLUtils.getFirstChildWithTagName(rootNode, ELEMENT_PROCESSES);
    int initialCapacity = 10;
    for (Node processNode = processesNode.getFirstChild(); processNode != null; processNode = processNode
            .getNextSibling()) {
        if (!(processNode instanceof Element) || !processNode.getNodeName().equals(ELEMENT_PROCESS)) {
            continue;
        }
        List<IndividualIssue> process = new ArrayList<>(initialCapacity);
        for (Node blockNode = processNode.getFirstChild(); blockNode != null; blockNode = blockNode
                .getNextSibling()) {
            if (!(blockNode instanceof Element) || !blockNode.getNodeName().equals(ELEMENT_BLOCK)) {
                continue;
            }
            String variant = ((Element) blockNode).getAttribute(ATTRIBUTE_VARIANT);
            for (Node issueNode = blockNode.getFirstChild(); issueNode != null; issueNode = issueNode
                    .getNextSibling()) {
                if (!(issueNode instanceof Element) || !issueNode.getNodeName().equals(ELEMENT_APPEARED)) {
                    continue;
                }
                String issue = ((Element) issueNode).getAttribute(ATTRIBUTE_ISSUE_HEADING);
                String date = ((Element) issueNode).getAttribute(ATTRIBUTE_DATE);
                if (date == null) {
                    throw new NullPointerException(ATTRIBUTE_DATE);
                }
                IndividualIssue individualIssue = addAddition(variant, issue, LocalDate.parse(date));
                process.add(individualIssue);
            }
        }
        processes.add(process);
        initialCapacity = (int) Math.round(1.1 * process.size());
    }
    recalculateRegularityOfIssues();
    processesAreVolatile = true;
}

From source file:org.jpmml.evaluator.TypeUtil.java

License:Open Source License

static private LocalDate parseDate(String value) {
    return LocalDate.parse(value);
}