use of org.kie.internal.utils.LazyLoaded in project jbpm by kiegroup.
the class ProcessServiceImpl method getProcessInstanceVariables.
@Override
public Map<String, Object> getProcessInstanceVariables(String deploymentId, Long processInstanceId) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) ksession.getProcessInstance(processInstanceId, true);
Map<String, Object> variables = pi.getVariables();
for (Object variable : variables.values()) {
if (variable instanceof LazyLoaded<?>) {
((LazyLoaded<?>) variable).load();
}
}
return variables;
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.utils.LazyLoaded 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.utils.LazyLoaded in project jbpm by kiegroup.
the class CaseServiceImpl method internalGetCaseFileInstance.
/*
* internal methods
*/
@SuppressWarnings("unchecked")
protected CaseFileInstance internalGetCaseFileInstance(String caseId, String deploymentId) {
logger.debug("Retrieving case file from working memory for case " + caseId);
Collection<CaseFileInstance> caseFiles = (Collection<CaseFileInstance>) processService.execute(deploymentId, CaseContext.get(caseId), commandsFactory.newGetObjects(new ClassObjectFilter(CaseFileInstance.class)));
if (caseFiles.size() == 0) {
throw new CaseNotFoundException("Case with id " + caseId + " was not found");
} else if (caseFiles.size() == 1) {
CaseFileInstance caseFile = caseFiles.iterator().next();
logger.debug("Single case file {} found in working memory", caseFile);
// apply authorization
Map<String, Object> filteredData = authorizationManager.filterByDataAuthorization(caseId, caseFile, caseFile.getData());
((CaseFileInstanceImpl) caseFile).setData(filteredData);
for (Object variable : caseFile.getData().values()) {
if (variable instanceof LazyLoaded<?>) {
((LazyLoaded<?>) variable).load();
}
}
return caseFile;
}
logger.warn("Multiple case files found in working memory (most likely not using PER_CASE strategy), trying to filter out...");
CaseFileInstance caseFile = caseFiles.stream().filter(cf -> cf.getCaseId().equals(caseId)).findFirst().orElse(null);
logger.warn("Case file {} after filtering {}", caseFile, (caseFile == null ? "not found" : "found"));
if (caseFile != null) {
// apply authorization
Map<String, Object> filteredData = authorizationManager.filterByDataAuthorization(caseId, caseFile, caseFile.getData());
((CaseFileInstanceImpl) caseFile).setData(filteredData);
for (Object variable : caseFile.getData().values()) {
if (variable instanceof LazyLoaded<?>) {
((LazyLoaded<?>) variable).load();
}
}
}
return caseFile;
}
use of org.kie.internal.utils.LazyLoaded 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);
}
}
Aggregations