use of org.jbpm.shared.services.impl.commands.PersistObjectCommand in project jbpm by kiegroup.
the class CaseInstanceAuditEventListener method afterCaseRoleAssignmentAdded.
@Override
public void afterCaseRoleAssignmentAdded(CaseRoleAssignmentEvent event) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("caseId", event.getCaseId());
QueryStringCommand<List<Long>> queryCommand = new QueryStringCommand<List<Long>>(FIND_CASE_PROCESS_INST_ID_QUERY, parameters);
List<Long> processInstanceId = commandService.execute(queryCommand);
if (processInstanceId.isEmpty()) {
return;
}
CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(processInstanceId.get(0), event.getCaseId(), event.getRole(), event.getEntity());
commandService.execute(new PersistObjectCommand(assignmentLog));
}
use of org.jbpm.shared.services.impl.commands.PersistObjectCommand 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.shared.services.impl.commands.PersistObjectCommand in project jbpm by kiegroup.
the class TableCaseIdGenerator method register.
@Override
public void register(String prefix) {
CaseIdInfo caseIdInfo = findCaseIdInfoByPrefix(prefix);
if (caseIdInfo == null) {
logger.debug("Case id prefix {} not yet registered", prefix);
caseIdInfo = new CaseIdInfo();
caseIdInfo.setCaseIdPrefix(prefix);
caseIdInfo.setCurrentValue(new Long(0));
commandService.execute(new PersistObjectCommand(caseIdInfo));
} else {
logger.debug("Case id prefix {} already registered and it's current value is {}", prefix, caseIdInfo.getCurrentValue());
}
}
use of org.jbpm.shared.services.impl.commands.PersistObjectCommand in project jbpm by kiegroup.
the class DeploymentStore method enableDeploymentUnit.
public void enableDeploymentUnit(DeploymentUnit unit) {
String unitContent = xstream.toXML(unit);
DeploymentStoreEntry entry = findDeploymentStoreByDeploymentId(unit.getIdentifier());
if (entry != null) {
// update only
// 0 - disabled, 1 - enabled, 2 - activated, 3 - deactivated
entry.setState(STATE_ENABLED);
entry.setUpdateDate(new Date());
entry.setDeploymentUnit(unitContent);
commandService.execute(new MergeObjectCommand(entry));
return;
}
entry = new DeploymentStoreEntry();
entry.setDeploymentId(unit.getIdentifier());
// 0 - disabled, 1 - enabled, 2 - activated, 3 - deactivated
entry.setState(STATE_ENABLED);
entry.setUpdateDate(new Date());
entry.setDeploymentUnit(unitContent);
if (unit instanceof AttributesAware) {
String attribtues = buildEntryAttributes(((AttributesAware) unit).getAttributes());
entry.setAttributes(attribtues);
}
commandService.execute(new PersistObjectCommand(entry));
}
use of org.jbpm.shared.services.impl.commands.PersistObjectCommand in project jbpm by kiegroup.
the class CaseInstanceAuditEventListener method afterCaseDataAdded.
@Override
public void afterCaseDataAdded(CaseDataEvent event) {
Map<String, Object> addedData = event.getData();
if (addedData.isEmpty()) {
return;
}
List<CaseFileDataLog> insert = new ArrayList<>();
List<CaseFileDataLog> update = new ArrayList<>();
List<String> currentCaseData = currentCaseData(event.getCaseId());
addedData.forEach((name, value) -> {
if (value != null) {
CaseFileDataLog caseFileDataLog = null;
if (currentCaseData.contains(name)) {
logger.debug("Case instance {} has already stored log value for {} thus it's going to be updated", event.getCaseId(), name);
caseFileDataLog = caseFileDataByName(event.getCaseId(), name);
update.add(caseFileDataLog);
} else {
logger.debug("Case instance {} has no log value for {} thus it's going to be inserted", event.getCaseId(), name);
caseFileDataLog = new CaseFileDataLog(event.getCaseId(), event.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()));
commandService.execute(new MergeObjectCommand(update.toArray()));
}
Aggregations