Java Code Examples for org.camunda.bpm.engine.variable.Variables#dateValue()

The following examples show how to use org.camunda.bpm.engine.variable.Variables#dateValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateValueMapper.java    From camunda-external-task-client-java with Apache License 2.0 6 votes vote down vote up
public DateValue readValue(TypedValueField typedValueField) {
  Date date = null;

  String value = (String) typedValueField.getValue();
  if (value != null) {
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    try {
      date = sdf.parse(value);
    }
    catch (ParseException e) {
      throw LOG.valueMapperExceptionWhileParsingDate(value, e);
    }
  }

  return Variables.dateValue(date);
}
 
Example 2
Source File: DateFormType.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TypedValue convertToModelValue(TypedValue propertyValue) {
  Object value = propertyValue.getValue();
  if(value == null) {
    return Variables.dateValue(null, propertyValue.isTransient());
  }
  else if(value instanceof Date) {
    return Variables.dateValue((Date) value, propertyValue.isTransient());
  }
  else if(value instanceof String) {
    String strValue = ((String) value).trim();
    if (strValue.isEmpty()) {
      return Variables.dateValue(null, propertyValue.isTransient());
    }
    try {
      return Variables.dateValue((Date) dateFormat.parseObject(strValue), propertyValue.isTransient());
    } catch (ParseException e) {
      throw new ProcessEngineException("Could not parse value '"+value+"' as date using date format '"+datePattern+"'.");
    }
  }
  else {
    throw new ProcessEngineException("Value '"+value+"' cannot be transformed into a Date.");
  }
}
 
Example 3
Source File: DateValueMapperTest.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWriteValue() {
  // given
  DateValue dateValue = Variables.dateValue(VARIABLE_VALUE_DATE);
  TypedValueField typedValueField = new TypedValueField();

  // when
  dateValueMapper.writeValue(dateValue, typedValueField);

  // then
  assertThat(typedValueField.getValue()).isEqualTo(VARIABLE_VALUE_DATE_SERIALIZED);
}
 
Example 4
Source File: DateDataTypeTransformer.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
@Override
public TypedValue transform(Object value) throws IllegalArgumentException {
  if (value instanceof Date) {
    return Variables.dateValue((Date) value);

  } else if (value instanceof String) {
    Date date = transformString((String) value);
    return Variables.dateValue(date);

  } else {
    throw new IllegalArgumentException();
  }
}
 
Example 5
Source File: DmnDataTypeTransformerTest.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
@Test
public void dateType() throws ParseException {
  DmnDataTypeTransformer typeTransformer = registry.getTransformer("date");

  Date date = toDate("2015-09-18T12:00:00");
  TypedValue dateValue = Variables.dateValue(date);

  assertThat(typeTransformer.transform("2015-09-18T12:00:00"), is(dateValue));
  assertThat(typeTransformer.transform(date), is(dateValue));
}
 
Example 6
Source File: DmnDataTypeTransformerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void dateType() throws ParseException {
  DmnDataTypeTransformer typeTransformer = registry.getTransformer("date");

  Date date = toDate("2015-09-18T12:00:00");
  TypedValue dateValue = Variables.dateValue(date);

  assertThat(typeTransformer.transform("2015-09-18T12:00:00"), is(dateValue));
  assertThat(typeTransformer.transform(date), is(dateValue));
}
 
Example 7
Source File: DmnDataTypeTransformerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldTransformZonedDateTime() {
  // given
  DmnDataTypeTransformer typeTransformer = registry.getTransformer("date");

  Date date = toDate("2015-09-18T12:00:00");
  TypedValue dateValue = Variables.dateValue(date);
  ZonedDateTime zonedDateTime = ZonedDateTime.of(2015, 9, 18, 12, 0, 0, 0, ZoneId.of("Europe/Berlin"));

  // when
  TypedValue transformedFromZonedDateTime = typeTransformer.transform(zonedDateTime);

  // then
  assertThat(transformedFromZonedDateTime, is(dateValue));
}
 
Example 8
Source File: DmnDataTypeTransformerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldTransformLocalDateTime() {
  // given
  DmnDataTypeTransformer typeTransformer = registry.getTransformer("date");

  Date date = toDate("2015-09-18T15:00:00");
  TypedValue dateValue = Variables.dateValue(date);
  LocalDateTime localDateTime = LocalDateTime.parse("2015-09-18T15:00:00");

  // when
  TypedValue transformedFromLocalDateTime = typeTransformer.transform(localDateTime);

  // then
  assertThat(transformedFromLocalDateTime, is(dateValue));
}
 
Example 9
Source File: DateValueMapper.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
public DateValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.dateValue((Date) untypedValue.getValue());
}
 
Example 10
Source File: FeelEngineTest.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
protected DateValue parseDateAndTime(String dateAndTimeString) {
  Date date = FeelFunctionMapper.parseDateAndTime(dateAndTimeString);
  return Variables.dateValue(date);
}
 
Example 11
Source File: FeelEngineTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected DateValue parseDateAndTime(String dateAndTimeString) {
  Date date = FeelFunctionMapper.parseDateAndTime(dateAndTimeString);
  return Variables.dateValue(date);
}
 
Example 12
Source File: DateValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public DateValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.dateValue((Date) untypedValue.getValue(), untypedValue.isTransient());
}
 
Example 13
Source File: PrimitiveValueTypeImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public DateValue createValue(Object value, Map<String, Object> valueInfo) {
  return Variables.dateValue((Date) value, isTransient(valueInfo));
}