use of org.jbpm.services.task.impl.model.xml.JaxbContent in project jbpm by kiegroup.
the class AbstractTaskSerializationTest method jaxbContentTest.
@Test
public void jaxbContentTest() throws Exception {
Assume.assumeFalse(getType().equals(TestType.YAML));
ContentImpl content = new ContentImpl();
content.setId(23);
Map<String, Object> map = new HashMap<String, Object>();
map.put("life", new Integer(23));
map.put("sick", new Integer(45));
byte[] bytes = ContentMarshallerHelper.marshallContent(null, map, null);
content.setContent(bytes);
JaxbContent jaxbContent = new JaxbContent(content);
JaxbContent copyJaxbContent = testRoundTrip(jaxbContent);
Assertions.assertThat(jaxbContent).isEqualToComparingFieldByFieldRecursively(copyJaxbContent);
}
use of org.jbpm.services.task.impl.model.xml.JaxbContent in project jbpm by kiegroup.
the class HumanTaskServicesBaseTest method xmlRoundTripContent.
protected JaxbContent xmlRoundTripContent(Content content) {
JaxbContent xmlContent = new JaxbContent(content);
JaxbContent xmlCopy = null;
try {
Marshaller marshaller = JAXBContext.newInstance(JaxbContent.class).createMarshaller();
// marshal
StringWriter stringWriter = new StringWriter();
marshaller.marshal(xmlContent, stringWriter);
// unmarshal
Unmarshaller unmarshaller = JAXBContext.newInstance(JaxbContent.class).createUnmarshaller();
ByteArrayInputStream inputStream = new ByteArrayInputStream(stringWriter.toString().getBytes());
xmlCopy = (JaxbContent) unmarshaller.unmarshal(inputStream);
for (Field field : JaxbContent.class.getDeclaredFields()) {
field.setAccessible(true);
Object orig = field.get(xmlContent);
Object roundTrip = field.get(xmlCopy);
if (orig instanceof byte[]) {
Assert.assertTrue(Arrays.equals((byte[]) orig, (byte[]) roundTrip));
} else {
Assert.assertEquals(field.getName(), orig, roundTrip);
}
}
} catch (Exception e) {
logger.error("Unable to complete round trip: " + e.getMessage(), e);
Assert.fail("Unable to complete round trip: " + e.getMessage());
}
Object orig = ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertNotNull("Round tripped JaxbContent is null!", xmlCopy);
Object roundTrip = ContentMarshallerHelper.unmarshall(xmlCopy.getContent(), null);
Assert.assertEquals(orig, roundTrip);
return xmlCopy;
}
use of org.jbpm.services.task.impl.model.xml.JaxbContent in project jbpm by kiegroup.
the class AddAttachmentCommand method execute.
public Long execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Attachment attachmentImpl = attachment;
if (attachmentImpl == null) {
attachmentImpl = jaxbAttachment;
}
Content contentImpl = content;
if (contentImpl == null) {
contentImpl = jaxbContent;
}
if (rawContent != null && contentImpl == null) {
Task task = context.getPersistenceContext().findTask(taskId);
contentImpl = TaskModelProvider.getFactory().newContent();
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getTaskData().getDeploymentId());
((InternalContent) contentImpl).setContent(ContentMarshallerHelper.marshallContent(task, rawContent, ctx.getEnvironment()));
((InternalAttachment) attachmentImpl).setSize(contentImpl.getContent().length);
}
doCallbackOperationForAttachment(attachmentImpl, context);
return context.getTaskAttachmentService().addAttachment(taskId, attachmentImpl, contentImpl);
}
use of org.jbpm.services.task.impl.model.xml.JaxbContent in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithMapContent.
@Test
public void testNewTaskWithMapContent() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Map<String, Object> variablesMap = new HashMap<String, Object>();
variablesMap.put("key1", "value1");
variablesMap.put("key2", null);
variablesMap.put("key3", "value3");
ContentData data = ContentMarshallerHelper.marshal(null, variablesMap, null);
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, data);
long taskId = task.getId();
// Task should be assigned to the single potential owner and state set to Reserved
Task task1 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
assertEquals("java.util.HashMap", task1.getTaskData().getDocumentType());
long contentId = task1.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
// content
Content content = taskService.getContentById(contentId);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
if (!(unmarshalledObject instanceof Map)) {
fail("The variables should be a Map");
}
Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
JaxbContent jaxbContent = xmlRoundTripContent(content);
assertNotNull("Jaxb Content map not filled", jaxbContent.getContentMap());
assertEquals("value1", unmarshalledvars.get("key1"));
assertNull(unmarshalledvars.get("key2"));
assertEquals("value3", unmarshalledvars.get("key3"));
}
Aggregations