use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class PerCaseRuntimeManager method init.
@Override
public void init() {
TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader()));
boolean owner = false;
TransactionManager tm = null;
if (environment.usePersistence()) {
tm = getTransactionManagerInternal(environment.getEnvironment());
owner = tm.begin();
}
try {
// need to init one session to bootstrap all case - such as start timers
KieSession initialKsession = factory.newKieSession();
// there is a need to call getProcessRuntime otherwise the start listeners are not registered
initialKsession.execute(new ExecutableCommand<Void>() {
private static final long serialVersionUID = 1L;
@Override
public Void execute(org.kie.api.runtime.Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
((InternalKnowledgeRuntime) ksession).getProcessRuntime();
return null;
}
});
factory.onDispose(initialKsession.getIdentifier());
initialKsession.execute(new DestroyKSessionCommand(initialKsession, this));
if (!"false".equalsIgnoreCase(System.getProperty("org.jbpm.rm.init.timer"))) {
if (mapper instanceof JPAMapper) {
List<Long> ksessionsToInit = ((JPAMapper) mapper).findKSessionToInit(this.identifier);
for (Long id : ksessionsToInit) {
initialKsession = factory.findKieSessionById(id);
initialKsession.execute(new DisposeKSessionCommand(initialKsession, this));
}
}
}
if (tm != null) {
tm.commit(owner);
}
} catch (Exception e) {
if (tm != null) {
tm.rollback(owner);
}
throw new RuntimeException("Exception while initializing runtime manager " + this.identifier, e);
}
}
use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class PerRequestRuntimeManager method init.
@Override
public void init() {
TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader()));
configureRuntimeOnTaskService(newTaskService(taskServiceFactory), null);
}
use of org.kie.internal.task.api.ContentMarshallerContext 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.internal.task.api.ContentMarshallerContext 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.internal.task.api.ContentMarshallerContext 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