use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class UserTaskServiceImpl method getTaskOutputContentByTaskId.
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> getTaskOutputContentByTaskId(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().getOutputContentId();
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 SingletonRuntimeManager method init.
public void init() {
// TODO should we proxy/wrap the ksession so we capture dispose.destroy method calls?
String location = getLocation();
Long knownSessionId = getPersistedSessionId(location, identifier);
InternalTaskService internalTaskService = newTaskService(taskServiceFactory);
boolean owner = false;
TransactionManager tm = null;
if (environment.usePersistence()) {
tm = getTransactionManagerInternal(environment.getEnvironment());
owner = tm.begin();
}
try {
if (knownSessionId > 0) {
try {
this.singleton = new SynchronizedRuntimeImpl(factory.findKieSessionById(knownSessionId), internalTaskService);
} catch (RuntimeException e) {
// in case session with known id was found
}
}
if (this.singleton == null) {
this.singleton = new SynchronizedRuntimeImpl(factory.newKieSession(), internalTaskService);
persistSessionId(location, identifier, singleton.getKieSession().getIdentifier());
}
((RuntimeEngineImpl) singleton).setManager(this);
TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader()));
configureRuntimeOnTaskService(internalTaskService, singleton);
registerItems(this.singleton);
attachManager(this.singleton);
this.registry.register(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 PerProcessInstanceRuntimeManager 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 TaskInstanceServiceImpl method getContentMapForUser.
@Override
public Map<String, Object> getContentMapForUser(Long taskId, String userId) {
// check permissions
this.lifeCycleManager.taskOperation(Operation.View, taskId, userId, null, null, toGroups(null));
Task task = this.persistenceContext.findTask(taskId);
if (task.getTaskData() != null && task.getTaskData().getOutputContentId() != null) {
Content content = this.persistenceContext.findContent(task.getTaskData().getOutputContentId());
ContentMarshallerContext mContext = TaskContentRegistry.get().getMarshallerContext(task);
Object outputContent = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (outputContent instanceof Map) {
return (Map<String, Object>) outputContent;
} else {
throw new IllegalStateException("Output content for task " + taskId + " is not a Map<String, Object>!");
}
}
return null;
}
use of org.kie.internal.task.api.ContentMarshallerContext in project jbpm by kiegroup.
the class TaskContentServiceImpl method loadContentData.
@SuppressWarnings("unchecked")
protected Map<String, Object> loadContentData(Long contentId, Task task) {
if (contentId != null) {
Map<String, Object> data = null;
Content contentById = getContentById(contentId);
if (contentById != null) {
ContentMarshallerContext mContext = getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (!(unmarshalledObject instanceof Map)) {
data = new HashMap<String, Object>();
data.put("Content", unmarshalledObject);
} else {
data = (Map<String, Object>) unmarshalledObject;
}
return data;
}
}
return null;
}
Aggregations