org.camunda.spin.Spin Java Examples

The following examples show how to use org.camunda.spin.Spin. 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: XmlSerializationIT.java    From camunda-external-task-client-java with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetTypedSerializedXml() {
  // given
  engineRule.startProcessInstance(processDefinition.getId(), VARIABLE_NAME_XML, VARIABLE_VALUE_XML_OBJECT_VALUE);

  // when
  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(handler)
    .open();

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  ObjectValue typedValue = task.getVariableTyped(VARIABLE_NAME_XML, false);
  assertThat(typedValue.getObjectTypeName()).isEqualTo(XmlSerializable.class.getName());
  assertThat(typedValue.getType()).isEqualTo(OBJECT);
  assertThat(typedValue.isDeserialized()).isFalse();

  SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
  assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getStringProperty()).isEqualTo(serializedValue.childElement("stringProperty").textContent());
  assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getBooleanProperty()).isEqualTo(Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
  assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getIntProperty()).isEqualTo(Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
 
Example #2
Source File: FeelEngineIT.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected VariableMap createSpinParsedVariableInMap(String serializationType) {
  if ("json".equalsIgnoreCase(serializationType)) {
    JsonListSerializable<String> jsonList = new JsonListSerializable<>();
    jsonList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.JSON(jsonList.toExpectedJsonString()));

  } else if ("xml".equalsIgnoreCase(serializationType)) {
    XmlListSerializable<String> xmlList = new XmlListSerializable<>();
    xmlList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.XML(xmlList.toExpectedXmlString()));

  } else {
    return Variables.createVariables();

  }
}
 
Example #3
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithPrefix() {
  // given
  SpinXmlElement xml = Spin.XML("<data xmlns:p=\"http://www.example.org\">" +
                                        "<p:customer p:name=\"Kermit\" language=\"en\" />" +
                                      "</data>");

  Map<String, Val> xmlAttrMap = new HashMap();
  xmlAttrMap.put("@p$name", new ValString("Kermit"));
  xmlAttrMap.put("@language", new ValString("en"));

  Map<String, Val> xmlInnerMap = new HashMap();
  xmlInnerMap.put("p$customer", valueMapper.toVal(xmlAttrMap));
  xmlInnerMap.put("@xmlns$p", new ValString("http://www.example.org"));

  Map<String, Val> xmlContextMap = new HashMap();
  xmlContextMap.put("data", valueMapper.toVal(xmlInnerMap));

  ValContext context = (ValContext) valueMapper.toVal(xmlContextMap);

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #4
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithContent() {
  // given
  SpinXmlElement xml = Spin.XML("<customer>Kermit</customer>");

  Map<String, Val> xmlInnerMap = new HashMap();
  xmlInnerMap.put("$content", new ValString("Kermit"));

  Map<String, Val> xmlContextMap = new HashMap();
  xmlContextMap.put("customer", valueMapper.toVal(xmlInnerMap));

  ValContext context = (ValContext) valueMapper.toVal(xmlContextMap);

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #5
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithChildObject() {
  // given
  Map<String, Val> xmlAttrMap = new HashMap();
  xmlAttrMap.put("@city", new ValString("Berlin"));
  xmlAttrMap.put("@zipCode", new ValString("10961"));
  Map<String, Val> xmlInnerMap = new HashMap();
  xmlInnerMap.put("address", valueMapper.toVal(xmlAttrMap));
  Map<String, Val> xmlContextMap = new HashMap();
  xmlContextMap.put("customer", valueMapper.toVal(xmlInnerMap));

  ValContext context = (ValContext) valueMapper.toVal(xmlContextMap);
  SpinXmlElement xml = Spin.XML("<customer>" +
                                    "<address city=\"Berlin\" zipCode=\"10961\" />" +
                                "</customer>");

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #6
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithAttributes() {
  // given
  Map<String, Val> xmlInnerMap = new HashMap();
  xmlInnerMap.put("@name", new ValString("Kermit"));
  xmlInnerMap.put("@language", new ValString("en"));
  Map<String, Val> xmlContextMap = new HashMap();
  xmlContextMap.put("customer", valueMapper.toVal(xmlInnerMap));

  ValContext context = (ValContext) valueMapper.toVal(xmlContextMap);
  SpinXmlElement xml = Spin.XML(" <customer name=\"Kermit\" language=\"en\" /> ");

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #7
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapNestedCamundaSpinJSONObjectAsContext() {

  // given
  Map<String, Val> nestedMap = new HashMap<>();
  nestedMap.put("city", new ValString("Berlin"));
  nestedMap.put("zipCode", valueMapper.toVal(10961));

  Map<String, Val> contextMap = new HashMap<>();
  contextMap.put("customer", new ValString("Kermit"));
  contextMap.put("address", valueMapper.toVal(nestedMap));

  ValContext context = (ValContext) valueMapper.toVal(contextMap);
  SpinJsonNode json = Spin.JSON("{" +
                                    "\"customer\": \"Kermit\", " +
                                    "\"address\": {\"" +
                                      "city\": \"Berlin\", " +
                                    "\"zipCode\": 10961}}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #8
Source File: SpinValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected byte[] serializeToByteArray(Object deserializedObject) throws Exception {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputStreamWriter outWriter = new OutputStreamWriter(out, Context.getProcessEngineConfiguration().getDefaultCharset());
  BufferedWriter bufferedWriter = new BufferedWriter(outWriter);

  try {
    Spin<?> wrapper = (Spin<?>) deserializedObject;
    wrapper.writeToWriter(bufferedWriter);
    return out.toByteArray();
  }
  finally {
    IoUtil.closeSilently(out);
    IoUtil.closeSilently(outWriter);
    IoUtil.closeSilently(bufferedWriter);
  }
}
 
Example #9
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Spin<?>> T createSpinFromReader(Reader parameter) {
  ensureNotNull("parameter", parameter);

  RewindableReader rewindableReader = new RewindableReader(parameter, READ_SIZE);

  DataFormat<T> matchingDataFormat = null;
  for (DataFormat<?> format : DataFormats.getAvailableDataFormats()) {
    if (format.getReader().canRead(rewindableReader, rewindableReader.getRewindBufferSize())) {
      matchingDataFormat = (DataFormat<T>) format;
    }

    try {
      rewindableReader.rewind();
    } catch (IOException e) {
      throw LOG.unableToReadFromReader(e);
    }

  }

  if (matchingDataFormat == null) {
    throw LOG.unrecognizableDataFormatException();
  }

  return createSpin(rewindableReader, matchingDataFormat);
}
 
Example #10
Source File: KeycloakAuthenticationFilter.java    From camunda-bpm-identity-keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {

       // Get the Bearer Token and extract claims
       Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
       OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
       String accessToken = details.getTokenValue();
       String claims = JwtHelper.decode(accessToken).getClaims();
       
       // Extract user ID from Token claims -depending on Keycloak Identity Provider configuration
       // String userId = Spin.JSON(claims).prop("sub").stringValue();
       String userId = Spin.JSON(claims).prop("email").stringValue(); // useEmailAsCamundaUserId = true
       // String userId = Spin.JSON(claims).prop("preferred_username").stringValue(); // useUsernameAsCamundaUserId = true
       LOG.debug("Extracted userId from bearer token: {}", userId);

       try {
       	identityService.setAuthentication(userId, getUserGroups(userId));
       	chain.doFilter(request, response);
       } finally {
       	identityService.clearAuthentication();
       }
}
 
Example #11
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Spin<?>> T createSpin(Object parameter) {
  ensureNotNull("parameter", parameter);

  if (parameter instanceof String) {
    return createSpinFromString((String) parameter);

  } else if (parameter instanceof Reader) {
    return createSpinFromReader((Reader) parameter);

  } else if (parameter instanceof Spin) {
    return createSpinFromSpin((T) parameter);

  } else {
    throw LOG.unsupportedInputParameter(parameter.getClass());
  }
}
 
Example #12
Source File: JsonTreeReadPropertyScriptTest.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@Test
@Script
@ScriptVariable(name = "input", file = EXAMPLE_JSON_FILE_NAME)
public void shouldBeSameAsJavaValue() {

  SpinJsonNode node = Spin.JSON(EXAMPLE_JSON);
  SpinJsonNode childNode = node.prop("orderDetails");

  SpinJsonNode property1 = node.prop("order");
  SpinJsonNode property2 = childNode.prop("price");
  SpinJsonNode property3 = node.prop("active");

  String javaVariable1 = property1.stringValue();
  Number javaVariable2 = property2.numberValue();
  Boolean javaVariable3 = property3.boolValue();

  String scriptVariable1 = script.getVariable("stringValue");
  Number scriptVariable2 = script.getVariable("numberValue");
  Boolean scriptVariable3 = script.getVariable("boolValue");

  assertThat(javaVariable1).isEqualTo(scriptVariable1);
  assertThat(javaVariable2).isEqualTo(scriptVariable2);
  assertThat(javaVariable3).isEqualTo(scriptVariable3);
}
 
Example #13
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Spin<?>> T createSpin(Object parameter, DataFormat<T> format) {
  ensureNotNull("parameter", parameter);
  ensureNotNull("format", format);

  if (parameter instanceof String) {
    return createSpinFromString((String) parameter, format);

  } else if (parameter instanceof Reader) {
    return createSpinFromReader((Reader) parameter, format);

  } else if (parameter instanceof Spin) {
    return createSpinFromSpin((T) parameter, format);

  } else {
    return createSpinFromObject(parameter, format);
  }
}
 
Example #14
Source File: SpinValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected boolean canSerializeValue(Object value) {
  if (value instanceof Spin<?>) {
    Spin<?> wrapper = (Spin<?>) value;
    return wrapper.getDataFormatName().equals(serializationDataFormat);
  }

  return false;
}
 
Example #15
Source File: XmlSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testGetSerializedVariableValue() {
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  XmlSerializable bean = new XmlSerializable("a String", 42, true);
  runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());

  ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);

  SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
  assertEquals(bean.getStringProperty(), serializedValue.childElement("stringProperty").textContent());
  assertEquals(bean.getBooleanProperty(), Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
  assertEquals(bean.getIntProperty(), Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
 
Example #16
Source File: XmlSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsXml() {
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  XmlSerializable bean = new XmlSerializable("a String", 42, true);
  // request object to be serialized as XML
  runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());

  // validate untyped value
  Object value = runtimeService.getVariable(instance.getId(), "simpleBean");
  assertEquals(bean, value);

  // validate typed value
  ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
  assertEquals(ValueType.OBJECT, typedValue.getType());

  assertTrue(typedValue.isDeserialized());

  assertEquals(bean, typedValue.getValue());
  assertEquals(bean, typedValue.getValue(XmlSerializable.class));
  assertEquals(XmlSerializable.class, typedValue.getObjectType());

  assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
  assertEquals(XmlSerializable.class.getName(), typedValue.getObjectTypeName());
  SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
  assertEquals(bean.getStringProperty(), serializedValue.childElement("stringProperty").textContent());
  assertEquals(bean.getBooleanProperty(), Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
  assertEquals(bean.getIntProperty(), Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
 
Example #17
Source File: XmlSerializationIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGetTypedSerializedXmlAsList() {
  // given
  engineRule.startProcessInstance(processDefinition.getId(), VARIABLE_NAME_XML, VARIABLE_VALUE_XML_LIST_OBJECT_VALUE);

  // when
  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(handler)
    .open();

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  ObjectValue typedValue = task.getVariableTyped(VARIABLE_NAME_XML, false);
  assertThat(typedValue.getObjectTypeName()).isEqualTo(XmlSerializables.class.getName());
  assertThat(typedValue.getType()).isEqualTo(OBJECT);
  assertThat(typedValue.isDeserialized()).isFalse();

  SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
  SpinList<SpinXmlElement> childElements = serializedValue.childElements();
  childElements.forEach((c) -> {
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getStringProperty()).isEqualTo(c.childElement("stringProperty").textContent());
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getBooleanProperty()).isEqualTo(Boolean.parseBoolean(c.childElement("booleanProperty").textContent()));
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getIntProperty()).isEqualTo(Integer.parseInt(c.childElement("intProperty").textContent()));
  });
}
 
Example #18
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithoutContent() {
  // given
  SpinXmlElement xml = Spin.XML("<customer />");
  ValContext context = (ValContext) valueMapper
      .toVal(Collections.singletonMap("customer", null));

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #19
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinXMLObjectWithListOfChildObjects() {
  // given
  SpinXmlElement xml = Spin.XML("<data>" +
                                        "<customer name=\"Kermit\" language=\"en\" />" +
                                        "<customer name=\"John\" language=\"de\" />" +
                                        "<provider name=\"Foobar\" />" +
                                       "</data>");

  Map<String, Val> xmlProviderAttrMap = new HashMap();
  xmlProviderAttrMap.put("@name", new ValString("Foobar"));

  Map<String, Val> xmlCustomerAttrMap1 = new HashMap();
  xmlCustomerAttrMap1.put("@name", new ValString("Kermit"));
  xmlCustomerAttrMap1.put("@language", new ValString("en"));

  Map<String, Val> xmlCustomerAttrMap2 = new HashMap();
  xmlCustomerAttrMap2.put("@name", new ValString("John"));
  xmlCustomerAttrMap2.put("@language", new ValString("de"));

  Map<String, Val> xmlInnerMap = new HashMap();
  xmlInnerMap.put("provider", valueMapper.toVal(xmlProviderAttrMap));
  xmlInnerMap.put("customer",
                  valueMapper.toVal(Arrays.asList(xmlCustomerAttrMap1, xmlCustomerAttrMap2)));

  Map<String, Val> xmlContextMap = new HashMap();
  xmlContextMap.put("data", valueMapper.toVal(xmlInnerMap));

  ValContext context = (ValContext) valueMapper.toVal(xmlContextMap);

  // when
  Val value = valueMapper.toVal(xml);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #20
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinJSONarrayAsList() {
  // given
  List<Val> list = Arrays.asList(new ValString("Kermit"), new ValString("Waldo"));
  ValList feelList = (ValList) valueMapper.toVal(list);
  ValContext context = (ValContext) valueMapper.toVal(Collections.singletonMap("customer", feelList));
  SpinJsonNode json = Spin.JSON("{\"customer\": [\"Kermit\", \"Waldo\"]}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #21
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinJSONObjectAsContext() {
  // given
  Map<String, Val> map = new HashMap<>();
  map.put("customer", new ValString("Kermit"));
  map.put("language", new ValString("en"));
  ValContext context = (ValContext) valueMapper.toVal(map);
  SpinJsonNode json = Spin.JSON("{\"customer\": \"Kermit\", \"language\": \"en\"}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example #22
Source File: JaxBContextProviderTest.java    From camunda-spin with Apache License 2.0 5 votes vote down vote up
/**
 * This test uses a dataformat with a JAXBContext that cannot resolve any classes.
 * Thus, it is expected that mapping an object to XML using this context fails.
 */
@Test
public void testCustomJaxBProvider() {

  Object objectToConvert = new Customer();

  // using the default jaxb context provider for conversion should work
  SpinXmlElement spinWrapper = Spin.XML(objectToConvert);
  spinWrapper.writeToWriter(new StringWriter());

  // using the custom jaxb context provider should fail with a JAXBException
  ((DomXmlDataFormat) DataFormats.xml()).setJaxBContextProvider(new EmptyContextProvider());
  try {
    spinWrapper = Spin.XML(objectToConvert);
    spinWrapper.writeToWriter(new StringWriter());
  } catch (SpinXmlDataFormatException e) {

    // assert that there is a jaxb exception somewhere in the exception hierarchy
    Set<Throwable> processedExceptions = new HashSet<Throwable>();
    while (!processedExceptions.contains(e.getCause()) && e.getCause() != null) {
      if (e.getCause() instanceof JAXBException) {
        // happy path
        return;
      }

      processedExceptions.add(e.getCause());
    }

    fail("expected a JAXBException in the cause hierarchy of the spin exception");
  }

}
 
Example #23
Source File: SpinValueImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public DataFormat<? extends Spin<?>> getDataFormat() {
  if(isDeserialized) {
    return DataFormats.getDataFormat(dataFormatName);
  }
  else {
    throw new IllegalStateException("Spin value is not deserialized.");
  }
}
 
Example #24
Source File: SpinValueImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Spin<?> getValue() {
  if(isDeserialized) {
    return super.getValue();
  }
  else {
    // deserialize the serialized value by using
    // the given data format
    value = S(getValueSerialized(), getSerializationDataFormat());
    isDeserialized = true;

    setValueSerialized(null);

    return value;
  }
}
 
Example #25
Source File: SpinValueImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public SpinValueImpl(
    Spin<?> value,
    String serializedValue,
    String dataFormatName,
    boolean isDeserialized,
    ValueType type,
    boolean isTransient) {

  super(value, type);

  this.serializedValue = serializedValue;
  this.dataFormatName = dataFormatName;
  this.isDeserialized = isDeserialized;
  this.isTransient = isTransient;
}
 
Example #26
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 5 votes vote down vote up
public <T extends Spin<?>> T createSpinFromObject(Object parameter, DataFormat<T> format) {
  ensureNotNull("parameter", parameter);

  DataFormatMapper mapper = format.getMapper();
  Object dataFormatInput = mapper.mapJavaToInternal(parameter);

  return format.createWrapperInstance(dataFormatInput);
}
 
Example #27
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 5 votes vote down vote up
public <T extends Spin<?>> T createSpinFromReader(Reader parameter, DataFormat<T> format) {
  ensureNotNull("parameter", parameter);

  DataFormatReader reader = format.getReader();
  Object dataFormatInput = reader.readInput(parameter);
  return format.createWrapperInstance(dataFormatInput);
}
 
Example #28
Source File: SpinFactoryImpl.java    From camunda-spin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Spin<?>> T createSpin(Object parameter, String dataFormatName) {
  ensureNotNull("dataFormatName", dataFormatName);

  DataFormat<T> dataFormat = (DataFormat<T>) DataFormats.getDataFormat(dataFormatName);

  return createSpin(parameter, dataFormat);
}
 
Example #29
Source File: SpinFunctionMapper.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void createMethodBindings() {
  Class<?> spinClass =  Spin.class;
  SPIN_FUNCTION_MAP.put("S", ReflectUtil.getMethod(spinClass, "S", Object.class));
  SPIN_FUNCTION_MAP.put("XML", ReflectUtil.getMethod(spinClass, "XML", Object.class));
  SPIN_FUNCTION_MAP.put("JSON", ReflectUtil.getMethod(spinClass, "JSON", Object.class));
}
 
Example #30
Source File: XmlSerializationIT.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
@Test
public void shoudSetXmlListVariable() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME_XML, Variables.objectValue(VARIABLE_VALUE_XML_LIST_DESERIALIZED).serializationDataFormat(XML).create());
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  ObjectValue serializedValue = task.getVariableTyped(VARIABLE_NAME_XML, false);
  assertThat(serializedValue.isDeserialized()).isFalse();
  assertThat(serializedValue.getType()).isEqualTo(OBJECT);
  assertThat(serializedValue.getObjectTypeName()).isEqualTo("org.camunda.bpm.client.variable.XmlSerializables");

  SpinXmlElement spinElement = Spin.XML(serializedValue.getValueSerialized());
  SpinList<SpinXmlElement> childElements = spinElement.childElements();
  childElements.forEach((c) -> {
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getStringProperty()).isEqualTo(c.childElement("stringProperty").textContent());
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getBooleanProperty()).isEqualTo(Boolean.parseBoolean(c.childElement("booleanProperty").textContent()));
    assertThat(VARIABLE_VALUE_XML_DESERIALIZED.getIntProperty()).isEqualTo(Integer.parseInt(c.childElement("intProperty").textContent()));
  });

  ObjectValue deserializedValue = task.getVariableTyped(VARIABLE_NAME_XML);
  assertThat(deserializedValue.isDeserialized()).isTrue();
  assertThat(deserializedValue.getValue()).isEqualTo(VARIABLE_VALUE_XML_LIST_DESERIALIZED);
  assertThat(deserializedValue.getType()).isEqualTo(OBJECT);
  assertThat(deserializedValue.getObjectTypeName()).isEqualTo("org.camunda.bpm.client.variable.XmlSerializables");

  XmlSerializables variableValue = task.getVariable(VARIABLE_NAME_XML);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_XML_LIST_DESERIALIZED);
}