use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method escalateCampaign.
public void escalateCampaign(String campaignOid, EscalateWorkItemActionType escalateAction, WorkItemEventCauseInformationType causeInformation, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, SecurityViolationException {
MidPointPrincipal principal = securityContextManager.getPrincipal();
result.addContext("user", toShortString(principal.getFocus()));
ObjectReferenceType initiator = ObjectTypeUtil.createObjectRef(principal.getFocus(), prismContext);
ObjectReferenceType attorney = ObjectTypeUtil.createObjectRef(principal.getAttorney(), prismContext);
List<AccessCertificationWorkItemType> workItems = queryHelper.searchOpenWorkItems(CertCampaignTypeUtil.createWorkItemsForCampaignQuery(campaignOid, prismContext), null, false, null, result);
if (workItems.isEmpty()) {
LOGGER.debug("No work items, no escalation (campaign: {})", campaignOid);
return;
}
LOGGER.debug("Going to escalate the campaign {}: {} work item(s)", campaignOid, workItems.size());
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
ModificationsToExecute modifications = new ModificationsToExecute();
// Currently we expect all open certification work items for a given campaign to have the same escalation level.
// Because of consistence with other parts of midPoint we store the escalation level within work item itself.
// But we enforce it to be the same for all the open work items.
// This behavior will most probably change in the future.
AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
int newStageEscalationLevelNumber = CertCampaignTypeUtil.getCurrentStageEscalationLevelNumber(campaign) + 1;
WorkItemEscalationLevelType newEscalationLevel = new WorkItemEscalationLevelType().number(newStageEscalationLevelNumber).name(escalateAction.getEscalationLevelName()).displayName(escalateAction.getEscalationLevelDisplayName());
for (AccessCertificationWorkItemType workItem : workItems) {
AccessCertificationCaseType aCase = CertCampaignTypeUtil.getCaseChecked(workItem);
AccessCertificationCampaignType workItemCampaign = CertCampaignTypeUtil.getCampaignChecked(aCase);
if (!java.util.Objects.equals(workItemCampaign.getOid(), campaignOid)) {
throw new IllegalArgumentException("Work item to delegate does not belong to specified campaign (" + campaignOid + ") but to " + workItemCampaign);
}
if (workItem.getCloseTimestamp() != null) {
throw new IllegalStateException("Couldn't delegate a work item that is already closed: " + workItem);
}
if (workItem.getStageNumber() != workItemCampaign.getStageNumber()) {
throw new IllegalStateException("Couldn't delegate a work item that is not in a current stage. Current stage: " + workItemCampaign.getStageNumber() + ", work item stage: " + workItem.getStageNumber());
}
if (norm(workItem.getIteration()) != norm(workItemCampaign.getIteration())) {
throw new IllegalStateException("Couldn't delegate a work item that is not in a current iteration. Current stage: " + norm(workItemCampaign.getIteration()) + ", work item iteration: " + norm(workItem.getIteration()));
}
if (workItem.getOutput() != null && workItem.getOutput().getOutcome() != null) {
// The latter is less awkward, so let's do it that way.
continue;
}
List<ObjectReferenceType> delegates = computeDelegateTo(escalateAction, workItem, aCase, workItemCampaign, task, result);
int escalationLevel = WorkItemTypeUtil.getEscalationLevelNumber(workItem);
if (escalationLevel + 1 != newStageEscalationLevelNumber) {
throw new IllegalStateException("Different escalation level numbers for certification cases: work item level (" + newEscalationLevel + ") is different from the stage level (" + newStageEscalationLevelNumber + ")");
}
LOGGER.debug("Escalating work item {} to level: {}; delegates={}: cause={}", workItem, newEscalationLevel, delegates, causeInformation);
List<ObjectReferenceType> assigneesBefore = CloneUtil.cloneCollectionMembers(workItem.getAssigneeRef());
WorkItemDelegationMethodType method = getDelegationMethod(escalateAction);
List<ObjectReferenceType> newAssignees = new ArrayList<>();
List<ObjectReferenceType> delegatedTo = new ArrayList<>();
CaseRelatedUtils.computeAssignees(newAssignees, delegatedTo, delegates, method, workItem.getAssigneeRef());
WorkItemDelegationEventType event = ApprovalContextUtil.createDelegationEvent(newEscalationLevel, assigneesBefore, delegatedTo, method, causeInformation, prismContext);
event.setTimestamp(now);
event.setInitiatorRef(initiator);
event.setAttorneyRef(attorney);
event.setWorkItemId(workItem.getId());
event.setEscalationLevel(workItem.getEscalationLevel());
event.setStageNumber(campaign.getStageNumber());
event.setIteration(norm(campaign.getIteration()));
List<ItemDelta<?, ?>> deltas = new ArrayList<>();
addDeltasForNewAssigneesAndEvent(deltas, workItem, aCase, newAssignees, event);
deltas.add(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_CASE, aCase.getId(), F_WORK_ITEM, workItem.getId(), F_ESCALATION_LEVEL).replace(newEscalationLevel).asItemDelta());
modifications.add(deltas);
// notification (after modifications)
}
AccessCertificationStageType stage = CertCampaignTypeUtil.getCurrentStage(campaign);
assert stage != null;
Long stageId = stage.asPrismContainerValue().getId();
assert stageId != null;
modifications.add(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_STAGE, stageId, AccessCertificationStageType.F_ESCALATION_LEVEL).replace(newEscalationLevel).asItemDelta());
AccessCertificationStageDefinitionType stageDefinition = CertCampaignTypeUtil.getCurrentStageDefinition(campaign);
modifications.add(updateHelper.getDeltasToCreateTriggersForTimedActions(campaignOid, newStageEscalationLevelNumber, XmlTypeConverter.toDate(stage.getStartTimestamp()), XmlTypeConverter.toDate(stage.getDeadline()), stageDefinition.getTimedActions()));
updateHelper.modifyCampaignPreAuthorized(campaignOid, modifications, task, result);
campaign = generalHelper.getCampaign(campaignOid, null, task, result);
// TODO differentiate between "old" and "new" reviewers
updateHelper.notifyReviewers(campaign, true, task, result);
// AccessCertificationCampaignType updatedCampaign = refreshCampaign(campaign, task, result);
// LOGGER.info("Updated campaign state: {}", updatedCampaign.getState());
// eventHelper.onCampaignEnd(updatedCampaign, task, result);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class AbstractCertificationTest method recordDecision.
protected void recordDecision(String campaignOid, AccessCertificationCaseType aCase, AccessCertificationResponseType response, String comment, String reviewerOid, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Authentication originalAuthentication = null;
String realReviewerOid;
if (reviewerOid != null) {
originalAuthentication = SecurityContextHolder.getContext().getAuthentication();
login(getUser(reviewerOid));
realReviewerOid = reviewerOid;
} else {
realReviewerOid = securityContextManager.getPrincipal().getOid();
}
List<AccessCertificationWorkItemType> workItems = aCase.getWorkItem().stream().filter(wi -> ObjectTypeUtil.containsOid(wi.getAssigneeRef(), realReviewerOid)).filter(wi -> wi.getStageNumber() == aCase.getStageNumber()).filter(wi -> norm(wi.getIteration()) == norm(aCase.getIteration())).collect(Collectors.toList());
assertEquals("Wrong # of current work items for " + realReviewerOid + " in " + aCase, 1, workItems.size());
long id = aCase.asPrismContainerValue().getId();
certificationManager.recordDecision(campaignOid, id, workItems.get(0).getId(), response, comment, task, result);
if (reviewerOid != null) {
SecurityContextHolder.getContext().setAuthentication(originalAuthentication);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class PrismIdentifierGenerator method generate.
public IdGeneratorResult generate(Containerable containerable) {
IdGeneratorResult result = new IdGeneratorResult();
if (!(containerable instanceof AccessCertificationCaseType)) {
return result;
}
AccessCertificationCaseType aCase = (AccessCertificationCaseType) containerable;
List<PrismContainer<?>> values = listAllPrismContainers(aCase.asPrismContainerValue());
generateContainerIds(values, result);
return result;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class QAccessCertificationCampaignMapping method loadCases.
private void loadCases(AccessCertificationCampaignType base, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull JdbcSession jdbcSession, boolean forceFull) throws SchemaException {
QAccessCertificationCaseMapping casesMapping = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping();
PrismContainer<AccessCertificationCaseType> cases = base.asPrismObject().findOrCreateContainer(F_CASE);
QAccessCertificationCase qcase = casesMapping.defaultAlias();
var query = jdbcSession.newQuery().from(qcase).select(casesMapping.selectExpressions(qcase, options)).where(qcase.ownerOid.eq(SqaleUtils.oidToUUid(base.getOid())));
// Load all / changed containers
Collection<Long> idsToFetch = casesToFetch(options);
if (forceFull || idsToFetch == null) {
// Noop, no need to add additional condition
// we are fetching all cases
cases.setIncomplete(false);
} else if (idsToFetch.isEmpty()) {
return;
} else {
// We fetch only containers explicitly mentioned in retrieve options
query = query.where(qcase.cid.in(idsToFetch));
}
List<Tuple> rows = query.fetch();
for (Tuple row : rows) {
AccessCertificationCaseType c = casesMapping.toSchemaObject(row, qcase, options, jdbcSession, forceFull);
cases.add(c.asPrismContainerValue());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class CertificationCaseHelper method updateLoadedCertificationCase.
// TODO find a better name
public AccessCertificationCaseType updateLoadedCertificationCase(GetContainerableResult result, Map<String, PrismObject<AccessCertificationCampaignType>> ownersMap, Collection<SelectorOptions<GetOperationOptions>> options, Session session, OperationResult operationResult) throws SchemaException {
byte[] fullObject = result.getFullObject();
AccessCertificationCaseType aCase = RAccessCertificationCase.createJaxb(fullObject, prismContext);
generalHelper.validateContainerable(aCase, AccessCertificationCaseType.class);
String ownerOid = result.getOwnerOid();
PrismObject<AccessCertificationCampaignType> campaign = resolveCampaign(ownerOid, ownersMap, session, operationResult);
if (campaign != null && !campaign.asObjectable().getCase().contains(aCase)) {
campaign.asObjectable().getCase().add(aCase);
}
objectRetriever.attachDiagDataIfRequested(aCase.asPrismContainerValue(), fullObject, options);
return aCase;
}
Aggregations