Search in sources :

Example 31 with AccessCertificationCaseType

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);
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 32 with AccessCertificationCaseType

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);
    }
}
Also used : AssertJUnit(org.testng.AssertJUnit) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) Collections.singletonList(java.util.Collections.singletonList) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) WorkItemTypeUtil(com.evolveum.midpoint.schema.util.cases.WorkItemTypeUtil) F_CASE(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_CASE) TestUtil(com.evolveum.midpoint.test.util.TestUtil) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) CertCampaignTypeUtil.norm(com.evolveum.midpoint.schema.util.CertCampaignTypeUtil.norm) AccessCertificationService(com.evolveum.midpoint.model.api.AccessCertificationService) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) DummyResource(com.evolveum.icf.dummy.resource.DummyResource) PrismObject(com.evolveum.midpoint.prism.PrismObject) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) com.evolveum.midpoint.certification.impl(com.evolveum.midpoint.certification.impl) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) CertCampaignTypeUtil(com.evolveum.midpoint.schema.util.CertCampaignTypeUtil) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) Authentication(org.springframework.security.core.Authentication) OutcomeUtils(com.evolveum.midpoint.certification.api.OutcomeUtils) Authentication(org.springframework.security.core.Authentication)

Example 33 with AccessCertificationCaseType

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;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)

Example 34 with AccessCertificationCaseType

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());
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Tuple(com.querydsl.core.Tuple)

Example 35 with AccessCertificationCaseType

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;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Aggregations

AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)31 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)5 Task (com.evolveum.midpoint.task.api.Task)5 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)4 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)4 java.util (java.util)4 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)3