use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseRoleAssignments.
@Override
public Collection<CaseRoleInstance> getCaseRoleAssignments(String caseId) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.MODIFY_ROLE_ASSIGNMENT);
ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, pi.getDeploymentId());
return ((CaseFileInstanceImpl) caseFile).getAssignments();
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseInstance.
@Override
public CaseInstance getCaseInstance(String caseId, boolean withData, boolean withRoles, boolean withMilestones, boolean withStages) throws CaseNotFoundException {
authorizationManager.checkAuthorization(caseId);
CaseInstanceImpl caseInstance = (CaseInstanceImpl) caseRuntimeDataService.getCaseInstanceById(caseId);
if (caseInstance.getStatus().equals(ProcessInstance.STATE_ACTIVE)) {
if (withData) {
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, caseInstance.getDeploymentId());
caseInstance.setCaseFile(caseFile);
}
if (withMilestones) {
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, false, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseMilestones(milestones);
}
if (withRoles) {
Collection<CaseRoleInstance> roles = getCaseRoleAssignments(caseId);
caseInstance.setCaseRoles(roles);
}
if (withStages) {
Collection<CaseStageInstance> stages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseStages(stages);
}
}
return caseInstance;
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseComments.
/*
* Case comments methods
*/
@Override
public Collection<CommentInstance> getCaseComments(String caseId, QueryContext queryContext) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.MODIFY_COMMENT);
ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, pi.getDeploymentId());
List<CommentInstance> caseComments = new ArrayList<>(((CaseFileInstanceImpl) caseFile).getComments());
// apply authorization
caseComments = authorizationManager.filterByCommentAuthorization(caseId, caseFile, caseComments);
int caseCommentsSize = caseComments.size();
int offset = queryContext.getOffset();
int pageSize = queryContext.getCount();
int pageIndex = (caseCommentsSize + pageSize - 1) / pageSize;
if (caseCommentsSize < pageSize) {
return caseComments;
} else if (pageIndex == (offset / pageSize) + 1) {
return caseComments.subList(offset, caseCommentsSize);
} else {
return caseComments.subList(offset, offset + pageSize);
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseInstanceAuditEventListener method afterCaseStarted.
@Override
public void afterCaseStarted(CaseStartEvent event) {
CaseFileInstance caseFile = event.getCaseFile();
if (caseFile == null) {
return;
}
Collection<CaseRoleInstance> caseRoleAssignments = ((CaseFileInstanceImpl) caseFile).getAssignments();
if (caseRoleAssignments != null && !caseRoleAssignments.isEmpty()) {
for (CaseRoleInstance roleAssignment : caseRoleAssignments) {
logger.debug("Role {} has following assignments {}", roleAssignment.getRoleName(), roleAssignment.getRoleAssignments());
if (roleAssignment.getRoleAssignments() != null && !roleAssignment.getRoleAssignments().isEmpty()) {
List<CaseRoleAssignmentLog> objects = new ArrayList<>();
roleAssignment.getRoleAssignments().forEach(entity -> {
CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), roleAssignment.getRoleName(), entity);
objects.add(assignmentLog);
});
commandService.execute(new PersistObjectCommand(objects.toArray()));
}
}
} else {
// add public role so it can be found by queries that take assignments into consideration
CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), "*", TaskModelProvider.getFactory().newGroup(AuthorizationManager.PUBLIC_GROUP));
commandService.execute(new PersistObjectCommand(assignmentLog));
}
Map<String, Object> initialData = caseFile.getData();
if (initialData.isEmpty()) {
return;
}
List<CaseFileDataLog> insert = new ArrayList<>();
initialData.forEach((name, value) -> {
if (value != null) {
CaseFileDataLog caseFileDataLog = new CaseFileDataLog(event.getCaseId(), caseFile.getDefinitionId(), name);
insert.add(caseFileDataLog);
caseFileDataLog.setItemType(value.getClass().getName());
caseFileDataLog.setItemValue(value.toString());
caseFileDataLog.setLastModified(new Date());
caseFileDataLog.setLastModifiedBy(event.getUser());
}
});
commandService.execute(new PersistObjectCommand(insert.toArray()));
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class AddDataCaseFileInstanceCommand method execute.
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() != 1) {
throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size());
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
// apply authorization
authorizationManager.checkDataAuthorization(caseFile.getCaseId(), caseFile, parameters.keySet());
FactHandle factHandle = ksession.getFactHandle(caseFile);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
caseFile.addAll(parameters);
// setup data restriction if any are given
for (String name : parameters.keySet()) {
if (accessRestriction != null) {
((CaseFileInstanceImpl) caseFile).addDataAccessRestriction(name, accessRestriction);
} else {
((CaseFileInstanceImpl) caseFile).removeDataAccessRestriction(name);
}
}
ksession.update(factHandle, caseFile);
triggerRules(ksession);
caseEventSupport.fireAfterCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
return null;
}
Aggregations