use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstanceWithRestrictions.
@Override
public CaseFileInstance newCaseFileInstanceWithRestrictions(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, OrganizationalEntity> rolesAssignment, Map<String, List<String>> accessRestrictions) {
CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
if (def == null) {
throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
}
CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
caseFile.setupRoles(def.getCaseRoles());
Map<String, List<String>> combinedAccessRestrictions = def.getDataAccessRestrictions();
if (accessRestrictions != null) {
combinedAccessRestrictions.putAll(accessRestrictions);
}
caseFile.setAccessRestrictions(combinedAccessRestrictions);
rolesAssignment.entrySet().stream().forEach(entry -> caseFile.assign(entry.getKey(), entry.getValue()));
return caseFile;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstance.
@Override
public CaseFileInstance newCaseFileInstance(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, OrganizationalEntity> rolesAssignment) {
CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
if (def == null) {
throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
}
CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
caseFile.setupRoles(def.getCaseRoles());
caseFile.setAccessRestrictions(def.getDataAccessRestrictions());
rolesAssignment.entrySet().stream().forEach(entry -> caseFile.assign(entry.getKey(), entry.getValue()));
return caseFile;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method startCase.
@Override
public String startCase(String deploymentId, String caseDefinitionId, CaseFileInstance caseFile) {
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentId, caseDefinitionId);
if (caseDef == null) {
throw new CaseNotFoundException("Case definition " + caseDefinitionId + " not found");
}
String caseId = caseIdGenerator.generate(caseDef.getIdentifierPrefix(), (caseFile == null ? new HashMap<>() : caseFile.getData()));
logger.debug("Generated case id {} for case definition id {}", caseId, caseDefinitionId);
if (caseFile == null) {
caseFile = new CaseFileInstanceImpl(caseId, caseDefinitionId);
((CaseFileInstanceImpl) caseFile).setupRoles(caseDef.getCaseRoles());
logger.debug("CaseFile was not given, creating new empty one.");
} else {
((CaseFileInstanceImpl) caseFile).setCaseId(caseId);
logger.debug("CaseFile {} was given, associating it with case {}", caseFile, caseId);
}
// If owner is provided in the case file use that, otherwise default to current logged in user.
boolean hasOwner = ((CaseFileInstanceImpl) caseFile).getAssignments().stream().anyMatch(role -> role.getRoleName().equals(AuthorizationManager.OWNER_ROLE));
if (hasOwner == false) {
((CaseFileInstanceImpl) caseFile).assignOwner(newUser(identityProvider.getName()));
}
processService.execute(deploymentId, CaseContext.get(caseId), new StartCaseCommand(identityProvider, caseId, deploymentId, caseDefinitionId, caseFile, processService));
return caseId;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseFileInstanceMarshallingStrategy method unmarshal.
@SuppressWarnings("unchecked")
@Override
public Object unmarshal(Context context, ObjectInputStream is, byte[] object, ClassLoader classloader) throws IOException, ClassNotFoundException {
logger.debug("About to read {} bytes to unmarshal CaseFileInstance", (object == null ? 0 : object.length));
Map<String, Object> caseFileContent = (Map<String, Object>) caseFileMarshaller.unmarshal(context, is, object, classloader);
CaseFileInstanceImpl caseFileInstance = new CaseFileInstanceImpl();
caseFileInstance.setCaseId((String) caseFileContent.get(CASE_ID_KEY));
caseFileInstance.setDefinitionId((String) caseFileContent.get(CASE_DEF_ID_KEY));
caseFileInstance.setCaseStartDate((Date) caseFileContent.get(CASE_START_KEY));
caseFileInstance.setCaseEndDate((Date) caseFileContent.get(CASE_END_KEY));
caseFileInstance.setCaseReopenDate((Date) caseFileContent.get(CASE_REOPEN_KEY));
caseFileInstance.setRolesAssignments((Map<String, CaseRoleInstance>) caseFileContent.get(CASE_ROLE_ASSIGNMENTS_KEY));
caseFileInstance.setComments((List<CommentInstance>) caseFileContent.get(CASE_COMMENTS_KEY));
logger.debug("CaseFileInstance meta data unmarshalled properly into {}", caseFileInstance);
List<SerializedContent> caseDataContent = (List<SerializedContent>) caseFileContent.get(CASE_DATA_KEY);
logger.debug("About to read serialized content {}", caseDataContent);
for (SerializedContent serializedContent : caseDataContent) {
ObjectMarshallingStrategy marshaller = marshallersByName.get(serializedContent.getMarshaller());
logger.debug("Marshaller for {} is of type {}", serializedContent, marshaller);
Object value = marshaller.unmarshal(context, is, serializedContent.getContent(), classloader);
caseFileInstance.add(serializedContent.getName(), value);
logger.debug("Data unmarshalled into {} and put into case file under '{}' name", value, serializedContent.getName());
}
caseFileInstance.setAccessRestrictions((Map<String, List<String>>) caseFileContent.get(CASE_DATA_RESTRICTIONS_KEY));
caseFileInstance.setParentInstanceId((Long) caseFileContent.get(CASE_PARENT_INSTANCE_ID_KEY));
caseFileInstance.setParentWorkItemId((Long) caseFileContent.get(CASE_PARENT_WORK_ITEM_ID_KEY));
logger.debug("Unmarshal of CaseFileInstance completed - result {}", caseFileInstance);
return caseFileInstance;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class NotifyParentCaseEventListener method notifyParentOnCompletion.
protected void notifyParentOnCompletion(CaseEvent event) {
CaseFileInstanceImpl caseFileInstance = (CaseFileInstanceImpl) event.getCaseFile();
if (caseFileInstance == null) {
return;
}
if (caseFileInstance.getParentInstanceId() != null && caseFileInstance.getParentWorkItemId() != null) {
logger.debug("Case {} has defined parent information instance {}, work item {}, going to notify it", event.getCaseId(), caseFileInstance.getParentInstanceId(), caseFileInstance.getParentWorkItemId());
ProcessService processService = (ProcessService) ServiceRegistry.get().service(ServiceRegistry.PROCESS_SERVICE);
Map<String, Object> results = new HashMap<>(caseFileInstance.getData());
results.put("CaseId", event.getCaseId());
processService.completeWorkItem(caseFileInstance.getParentWorkItemId(), results);
logger.debug("Parent instance id {}, work item id {}, has been successfully notified about case {} completion", caseFileInstance.getParentInstanceId(), caseFileInstance.getParentWorkItemId(), event.getCaseId());
caseFileInstance.setParentInstanceId(null);
caseFileInstance.setParentWorkItemId(null);
}
}
Aggregations