use of org.kie.internal.task.api.ContentMarshallerContext 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.ContentMarshallerContext in project jbpm by kiegroup.
the class GetTaskContentCommand method execute.
@SuppressWarnings("unchecked")
public Map<String, Object> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Task taskById = context.getTaskQueryService().getTaskInstanceById(taskId);
if (taskById == null) {
throw new IllegalStateException("Unable to find task with id " + taskId);
}
TaskContentService contentService = context.getTaskContentService();
Content contentById = contentService.getContentById(taskById.getTaskData().getDocumentContentId());
ContentMarshallerContext mContext = contentService.getMarshallerContext(taskById);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (!(unmarshalledObject instanceof Map)) {
logger.debug(" The Task Content is not of type Map, it was: {} so packaging it into new map under Content key ", unmarshalledObject.getClass());
Map<String, Object> content = new HashMap<String, Object>();
content.put("Content", unmarshalledObject);
return content;
}
Map<String, Object> content = (Map<String, Object>) unmarshalledObject;
return content;
}
use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method deleteOutput.
public void deleteOutput(long taskId, String userId) {
Task task = persistenceContext.findTask(taskId);
long contentId = task.getTaskData().getOutputContentId();
Content content = persistenceContext.findContent(contentId);
Map<String, Object> initialContent = new HashMap<>();
ContentMarshallerContext context = TaskContentRegistry.get().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), context.getEnvironment(), context.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content before updating with this params
initialContent.putAll((Map<String, Object>) unmarshalledObject);
}
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, this.context, initialContent);
ContentData data = TaskModelProvider.getFactory().newContentData();
persistenceContext.removeContent(content);
persistenceContext.setOutputToTask(null, data, task);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, this.context, null);
}
use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class TaskContentServiceImpl method addOutputContent.
@SuppressWarnings("unchecked")
public long addOutputContent(long taskId, Map<String, Object> params) {
Task task = persistenceContext.findTask(taskId);
loadTaskVariables(task);
long outputContentId = task.getTaskData().getOutputContentId();
Content outputContent = persistenceContext.findContent(outputContentId);
Map<String, Object> initialContent = new HashMap<>();
long contentId = -1;
if (outputContent == null) {
ContentMarshallerContext context = getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(outputContentData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setOutputToTask(content, outputContentData, task);
contentId = content.getId();
} else {
// I need to merge it if it already exist
ContentMarshallerContext context = getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content before updating with this params
initialContent.putAll((Map<String, Object>) unmarshalledObject);
((Map<String, Object>) unmarshalledObject).putAll(params);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
contentId = outputContentId;
}
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);
persistenceContext.updateTask(task);
return contentId;
}
use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class TaskRuleServiceImpl method executeRules.
@Override
public void executeRules(Task task, String userId, Object params, String scope) throws TaskException {
KieBase ruleBase = ruleContextProvider.getKieBase(scope);
if (ruleBase != null) {
KieSession session = ruleBase.newKieSession();
Map<String, Object> globals = ruleContextProvider.getGlobals(scope);
if (globals != null) {
for (Map.Entry<String, Object> entry : globals.entrySet()) {
session.setGlobal(entry.getKey(), entry.getValue());
}
}
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(userId);
TaskServiceRequest request = new TaskServiceRequest(scope, user, null);
session.setGlobal("request", request);
session.insert(task);
if (params != null) {
if (params instanceof ContentData) {
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task);
params = ContentMarshallerHelper.unmarshall(((ContentData) params).getContent(), ctx.getEnvironment(), ctx.getClassloader());
}
session.insert(params);
}
session.fireAllRules();
session.dispose();
if (!request.isAllowed()) {
StringBuilder error = new StringBuilder("Cannot perform operation " + scope + " :\n");
if (request.getReasons() != null) {
for (String reason : request.getReasons()) {
error.append(reason).append('\n');
}
}
throw request.getException(error.toString());
}
}
}
Aggregations