Search in sources :

Example 1 with TaskContentService

use of org.kie.internal.task.api.TaskContentService 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;
}
Also used : Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) Content(org.kie.api.task.model.Content) HashMap(java.util.HashMap) Map(java.util.Map) TaskContentService(org.kie.internal.task.api.TaskContentService) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Content (org.kie.api.task.model.Content)1 Task (org.kie.api.task.model.Task)1 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)1 TaskContentService (org.kie.internal.task.api.TaskContentService)1