use of org.kie.internal.task.api.model.InternalComment in project jbpm by kiegroup.
the class JaxbTask method getTask.
/**
* This is a convienence method that retrieves a TaskImpl instance. It's used
* internally in the {@link AddTaskCommand#execute(org.kie.internal.command.Context)} method
* because that command requires a persistable task representation.
* </p>
* Users who are looking for information from the task should <i>not</i> use this method:
* all of the task information is already available via the normal methods
* defined by the {@link Task} or {@link InternalTask} interfaces, both of which this class
* implements: for example: {@link JaxbTask#getId()}, {@link JaxbTask#getTaskData()}
* or {@link JaxbTask#getPeopleAssignments()}.
* @return a TaskImpl instance
*/
public Task getTask() {
InternalTask taskImpl = (InternalTask) TaskModelProvider.getFactory().newTask();
if (this.getId() != null) {
taskImpl.setId(this.getId());
}
if (this.priority != null) {
taskImpl.setPriority(this.getPriority());
}
JaxbPeopleAssignments jaxbPeopleAssignments = this.peopleAssignments;
InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
if (jaxbPeopleAssignments.getTaskInitiator() != null) {
User user = createUser(this.getPeopleAssignments().getTaskInitiator().getId());
peopleAssignments.setTaskInitiator(user);
}
List<OrganizationalEntity> potentialOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getPotentialOwners());
peopleAssignments.setPotentialOwners(potentialOwners);
List<OrganizationalEntity> businessAdmins = copyOrganizationalEntityList(jaxbPeopleAssignments.getBusinessAdministrators());
peopleAssignments.setBusinessAdministrators(businessAdmins);
List<OrganizationalEntity> exclOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getExcludedOwners());
peopleAssignments.setExcludedOwners(exclOwners);
List<OrganizationalEntity> taskStake = copyOrganizationalEntityList(jaxbPeopleAssignments.getTaskStakeholders());
peopleAssignments.setTaskStakeholders(taskStake);
List<OrganizationalEntity> recipients = copyOrganizationalEntityList(jaxbPeopleAssignments.getRecipients());
peopleAssignments.setRecipients(recipients);
taskImpl.setPeopleAssignments(peopleAssignments);
taskImpl.setSubTaskStrategy(this.getSubTaskStrategy());
{
List<I18NText> names = new ArrayList<I18NText>();
for (I18NText n : this.getNames()) {
I18NText text = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) text).setId(n.getId());
((InternalI18NText) text).setLanguage(n.getLanguage());
((InternalI18NText) text).setText(n.getText());
names.add(text);
}
taskImpl.setNames(names);
}
if (this.getName() != null) {
taskImpl.setName(this.getName());
} else if (!this.getNames().isEmpty()) {
taskImpl.setName(this.getNames().get(0).getText());
}
{
List<I18NText> subjects = new ArrayList<I18NText>();
for (I18NText s : this.getSubjects()) {
I18NText text = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) text).setId(s.getId());
((InternalI18NText) text).setLanguage(s.getLanguage());
((InternalI18NText) text).setText(s.getText());
subjects.add(text);
}
taskImpl.setSubjects(subjects);
}
if (this.getSubject() != null) {
taskImpl.setSubject(this.getSubject());
} else if (!this.getSubjects().isEmpty()) {
taskImpl.setSubject(this.getSubjects().get(0).getText());
}
{
List<I18NText> descriptions = new ArrayList<I18NText>();
for (I18NText d : this.getDescriptions()) {
I18NText text = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) text).setId(d.getId());
((InternalI18NText) text).setLanguage(d.getLanguage());
((InternalI18NText) text).setText(d.getText());
descriptions.add(text);
}
taskImpl.setDescriptions(descriptions);
}
if (this.getDescription() != null) {
taskImpl.setDescription(this.getDescription());
} else if (!this.getDescriptions().isEmpty()) {
taskImpl.setDescription(this.getDescriptions().get(0).getText());
}
taskImpl.setTaskType(this.getTaskType());
taskImpl.setFormName(this.getFormName());
// task data
InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
JaxbTaskData jaxbTaskData = (JaxbTaskData) this.getTaskData();
taskData.setStatus(jaxbTaskData.getStatus());
taskData.setPreviousStatus(jaxbTaskData.getPreviousStatus());
taskData.setActualOwner(createUser(jaxbTaskData.getActualOwnerId()));
taskData.setCreatedBy(createUser(jaxbTaskData.getCreatedById()));
taskData.setCreatedOn(jaxbTaskData.getCreatedOn());
taskData.setActivationTime(jaxbTaskData.getActivationTime());
taskData.setExpirationTime(jaxbTaskData.getExpirationTime());
taskData.setSkipable(jaxbTaskData.isSkipable());
taskData.setWorkItemId(jaxbTaskData.getWorkItemId());
taskData.setProcessInstanceId(jaxbTaskData.getProcessInstanceId());
taskData.setDocumentContentId(jaxbTaskData.getDocumentContentId());
taskData.setDocumentAccessType(jaxbTaskData.getDocumentAccessType());
taskData.setDocumentType(jaxbTaskData.getDocumentType());
taskData.setOutputAccessType(jaxbTaskData.getOutputAccessType());
taskData.setOutputType(jaxbTaskData.getOutputType());
taskData.setOutputContentId(jaxbTaskData.getOutputContentId());
taskData.setFaultName(jaxbTaskData.getFaultName());
taskData.setFaultAccessType(jaxbTaskData.getFaultAccessType());
taskData.setFaultType(jaxbTaskData.getFaultType());
taskData.setFaultContentId(jaxbTaskData.getFaultContentId());
taskData.setParentId(jaxbTaskData.getParentId());
taskData.setProcessId(jaxbTaskData.getProcessId());
taskData.setProcessSessionId(jaxbTaskData.getProcessSessionId());
List<Comment> jaxbComments = jaxbTaskData.getComments();
if (jaxbComments != null) {
List<Comment> comments = new ArrayList<Comment>(jaxbComments.size());
for (Comment jaxbComment : jaxbComments) {
InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
if (jaxbComment.getId() != null) {
comment.setId(jaxbComment.getId());
}
comment.setAddedAt(jaxbComment.getAddedAt());
comment.setAddedBy(createUser(((JaxbComment) jaxbComment).getAddedById()));
comment.setText(jaxbComment.getText());
comments.add(comment);
}
taskData.setComments(comments);
}
List<Attachment> jaxbAttachments = jaxbTaskData.getAttachments();
if (jaxbAttachments != null) {
List<Attachment> attachments = new ArrayList<Attachment>(jaxbAttachments.size());
for (Attachment jaxbAttach : jaxbAttachments) {
InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
if (jaxbAttach.getId() != null) {
attach.setId(jaxbAttach.getId());
}
attach.setName(jaxbAttach.getName());
attach.setContentType(jaxbAttach.getContentType());
attach.setAttachedAt(jaxbAttach.getAttachedAt());
attach.setAttachedBy(createUser(((JaxbAttachment) jaxbAttach).getAttachedById()));
attach.setSize(jaxbAttach.getSize());
attach.setAttachmentContentId(jaxbAttach.getAttachmentContentId());
attachments.add(attach);
}
taskData.setAttachments(attachments);
}
taskData.setDeploymentId(jaxbTaskData.getDeploymentId());
((InternalTask) taskImpl).setTaskData(taskData);
return taskImpl;
}
use of org.kie.internal.task.api.model.InternalComment in project jbpm by kiegroup.
the class AbstractTaskSerializationTest method jaxbTaskTest.
// TESTS ----------------------------------------------------------------------------------------------------------------------
@Test
public void jaxbTaskTest() throws Exception {
// Yaml serialization requires major changes in order to be supported.. :/
Assume.assumeTrue(!getType().equals(TestType.YAML));
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
InputStream stream = getClass().getResourceAsStream(MvelFilePath.FullTask);
assertNotNull("Could not load file: " + MvelFilePath.FullTask, stream);
Reader reader = new InputStreamReader(stream);
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
// fill task
task.setFormName("Bruno's Form");
task.setId(23L);
task.setSubTaskStrategy(SubTasksStrategy.EndParentOnAllSubTasksEnd);
for (I18NText text : task.getNames()) {
((InternalI18NText) text).setId((long) random.nextInt(1000));
}
for (I18NText text : task.getSubjects()) {
((InternalI18NText) text).setId((long) random.nextInt(1000));
}
for (I18NText text : task.getDescriptions()) {
((InternalI18NText) text).setId((long) random.nextInt(1000));
}
// fill task -> task data
InternalTaskData taskData = (InternalTaskData) task.getTaskData();
taskData.setOutputAccessType(AccessType.Inline);
taskData.setFaultAccessType(AccessType.Unknown);
taskData.setTaskInputVariables(new HashMap<String, Object>());
taskData.setTaskOutputVariables(new HashMap<String, Object>());
// fill task -> task data -> comment
String payload = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
comment.setId(42);
comment.setText(payload);
comment.setAddedAt(new Date());
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Case");
comment.setAddedBy(user);
taskData.addComment(comment);
// fill task -> task data -> attachment
InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
attach.setId(10);
attach.setName("virus");
attach.setContentType("ROM");
attach.setAttachedAt(new Date());
user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Wintermute");
attach.setAttachedBy(user);
attach.setSize(payload.getBytes().length);
attach.setAttachmentContentId(comment.getId());
taskData.addAttachment(attach);
JaxbTask xmlTask = new JaxbTask(task);
verifyThatAllFieldsAreFilledOrUnsupported(xmlTask, InternalTask.class);
verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData(), TaskData.class);
verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getAttachments().get(0), Attachment.class);
verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getComments().get(0), Comment.class);
assertNotNull(xmlTask.getNames());
assertTrue(xmlTask.getNames().size() > 0);
JaxbTask bornAgainTask = testRoundTrip(xmlTask);
assertNotNull(bornAgainTask.getNames());
assertTrue("Round-tripped task has empty 'names' list!", !bornAgainTask.getNames().isEmpty());
Assertions.assertThat(xmlTask).isEqualToComparingFieldByFieldRecursively(bornAgainTask);
assertNotNull(((InternalTask) xmlTask).getFormName());
assertEquals(((InternalTask) xmlTask).getFormName(), ((InternalTask) bornAgainTask).getFormName());
Task realTask = xmlTask.getTask();
verifyThatXmlFieldsAreFilled(realTask, xmlTask, InternalTask.class, "deadlines");
verifyThatXmlFieldsAreFilled(realTask.getTaskData(), xmlTask.getTaskData(), TaskData.class, "taskInputVariables", "taskOutputVariables");
}
Aggregations