use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class PatientVariablePersistenceStrategyTest method getTaskContent.
@SuppressWarnings("rawtypes")
private MedicalRecord getTaskContent(RuntimeEngine runtimeEngine, TaskSummary summary) throws IOException, ClassNotFoundException {
logger.info(" >>> Getting Task Content = {}", summary.getId());
Task task = runtimeEngine.getTaskService().getTaskById(summary.getId());
long documentContentId = task.getTaskData().getDocumentContentId();
Content content = runtimeEngine.getTaskService().getContentById(documentContentId);
Object readObject = ContentMarshallerHelper.unmarshall(content.getContent(), runtimeEngine.getKieSession().getEnvironment());
logger.info(" >>> Object = {}", readObject);
return (MedicalRecord) ((Map) readObject).get("Content");
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class LocalTaskServiceTest method testHumanTaskWithSingleTypeContent.
@Test
public void testHumanTaskWithSingleTypeContent() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("pVar", "sampleValue");
kieSession.startProcess(TASK_SINGLE_TYPE_ID, params);
// let john execute Task 1
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
TaskSummary task = list.get(0);
logger.info("John is executing task {}", task.getName());
taskService.start(task.getId(), "john");
// let's verify content, first manually by using marshaler helper
Content content = taskService.getContentById(taskService.getTaskById(task.getId()).getTaskData().getDocumentContentId());
byte[] contentbyte = content.getContent();
Object tmpObject = ContentMarshallerHelper.unmarshall(contentbyte, kieSession.getEnvironment());
assertNotNull(tmpObject);
assertTrue(tmpObject instanceof String);
assertEquals("someContent", tmpObject);
// then by using getTaskContent api method
Map<String, Object> contentMap = taskService.getTaskContent(task.getId());
assertNotNull(contentMap);
assertEquals(1, contentMap.size());
assertTrue(contentMap.containsKey("Content"));
String actualContent = (String) contentMap.get("Content");
assertNotNull(actualContent);
assertEquals("someContent", actualContent);
// let's move on to complete the tasks and process instance
taskService.complete(task.getId(), "john", null);
// let mary execute Task 2
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
task = list.get(0);
logger.info("Mary is executing task {}", task.getName());
taskService.start(task.getId(), "mary");
taskService.complete(task.getId(), "mary", null);
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class UserTaskServiceImpl method getAttachmentContentById.
@Override
public Object getAttachmentContentById(String deploymentId, Long taskId, Long attachmentId) {
UserTaskInstanceDesc task = dataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
RuntimeManager manager = getRuntimeManager(task);
if (manager == null) {
logger.warn("Cannot find runtime manager for task {}", taskId);
return null;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
// perform actual operation
TaskService taskService = engine.getTaskService();
Attachment attachment = ((InternalTaskService) taskService).getAttachmentById(attachmentId);
long documentContentId = attachment.getAttachmentContentId();
if (documentContentId > 0) {
Content contentById = taskService.getContentById(documentContentId);
if (contentById == null) {
return null;
}
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
return unmarshall;
}
return null;
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class UserTaskServiceImpl method getTaskInputContentByTaskId.
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> getTaskInputContentByTaskId(String deploymentId, Long taskId) {
UserTaskInstanceDesc task = dataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
RuntimeManager manager = getRuntimeManager(task);
if (manager == null) {
logger.warn("Cannot find runtime manager for task {}", taskId);
return null;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
Task taskInstanceById = taskService.getTaskById(taskId);
long documentContentId = taskInstanceById.getTaskData().getDocumentContentId();
if (documentContentId > 0) {
Content contentById = taskService.getContentById(documentContentId);
if (contentById == null) {
return new HashMap<String, Object>();
}
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
Map<String, Object> data = (Map<String, Object>) unmarshall;
for (Object variable : data.values()) {
if (variable instanceof LazyLoaded<?>) {
((LazyLoaded<?>) variable).load();
}
}
return data;
}
return new HashMap<String, Object>();
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class AddTaskInputsCommand 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 inputContentId = task.getTaskData().getDocumentContentId();
Content outputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> initialContent = new HashMap<String, Object>();
Map<String, Object> mergedContent = values;
if (outputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, 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(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content with data from storage before being altered by this values
initialContent.putAll((Map<String, Object>) unmarshalledObject);
((Map<String, Object>) unmarshalledObject).putAll(values);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
return null;
}
Aggregations