use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.
the class RemoveTaskDataCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
Task task = persistenceContext.findTask(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
long contentId = task.getTaskData().getDocumentContentId();
if (!input) {
contentId = task.getTaskData().getOutputContentId();
}
Content outputContent = persistenceContext.findContent(contentId);
Map<String, Object> initialContent = new HashMap<>();
Map<String, Object> mergedContent = new HashMap<>();
if (outputContent != null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
mergedContent.putAll(((Map<String, Object>) unmarshalledObject));
// set initial content for the sake of listeners
initialContent.putAll(mergedContent);
variableNames.forEach(name -> mergedContent.remove(name));
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, mergedContent, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
if (input) {
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
} else {
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(mergedContent);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, mergedContent);
}
return null;
}
use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.
the class UpdateTaskCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
Task task = persistenceContext.findTask(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
}
taskEventSupport.fireBeforeTaskUpdated(task, context);
// process task meta data
if (userTask.getFormName() != null) {
((InternalTask) task).setFormName(userTask.getFormName());
}
if (userTask.getName() != null) {
((InternalTask) task).setName(userTask.getName());
}
if (userTask.getDescription() != null) {
((InternalTask) task).setDescription(userTask.getDescription());
}
if (userTask.getPriority() != null) {
((InternalTask) task).setPriority(userTask.getPriority());
}
if (userTask.getDueDate() != null) {
((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
}
// process task inputs
long inputContentId = task.getTaskData().getDocumentContentId();
Content inputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> mergedContent = inputs;
if (inputs != null) {
if (inputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, mcontext.getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(outputContentData.getContent());
persistenceContext.persistContent(content);
((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
} else {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
((Map<String, Object>) unmarshalledObject).putAll(inputs);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) inputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(inputContent);
}
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
}
if (outputs != null) {
// process task outputs
context.getTaskContentService().addOutputContent(taskId, outputs);
}
persistenceContext.updateTask(task);
// finally trigger event support after the updates
taskEventSupport.fireAfterTaskUpdated(task, context);
return null;
}
use of org.kie.internal.task.api.model.InternalContent 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.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method setOutput.
public void setOutput(long taskId, String userId, Object outputContentData) {
Task task = persistenceContext.findTask(taskId);
ContentData contentData = ContentMarshallerHelper.marshal(task, outputContentData, environment);
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(contentData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setOutputToTask(content, contentData, task);
}
use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method setFault.
public void setFault(long taskId, String userId, FaultData fault) {
Task task = persistenceContext.findTask(taskId);
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(fault.getContent());
persistenceContext.persistContent(content);
persistenceContext.setFaultToTask(content, fault, task);
}
Aggregations