Search in sources :

Example 1 with AccessCertificationCampaignStateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType in project midpoint by Evolveum.

the class CertificationManagerImpl method openNextStage.

@Override
public void openNextStage(String campaignOid, int requestedStageNumber, Task task, OperationResult parentResult) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Validate.notNull(campaignOid, "campaignOid");
    Validate.notNull(task, "task");
    Validate.notNull(parentResult, "parentResult");
    OperationResult result = parentResult.createSubresult(OPERATION_OPEN_NEXT_STAGE);
    result.addParam("campaignOid", campaignOid);
    result.addParam("requestedStageNumber", requestedStageNumber);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("openNextStage starting for {}", ObjectTypeUtil.toShortString(campaign));
        }
        securityEnforcer.authorize(ModelAuthorizationAction.OPEN_CERTIFICATION_CAMPAIGN_REVIEW_STAGE.getUrl(), null, campaign.asPrismObject(), null, null, null, result);
        final int currentStageNumber = campaign.getStageNumber();
        final int stages = CertCampaignTypeUtil.getNumberOfStages(campaign);
        final AccessCertificationCampaignStateType state = campaign.getState();
        LOGGER.trace("openNextStage: currentStageNumber={}, stages={}, requestedStageNumber={}, state={}", currentStageNumber, stages, requestedStageNumber, state);
        if (IN_REVIEW_STAGE.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the stage " + currentStageNumber + " is currently open.");
        } else if (IN_REMEDIATION.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is currently in the remediation phase.");
        } else if (CLOSED.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is already closed.");
        } else if (!REVIEW_STAGE_DONE.equals(state) && !CREATED.equals(state)) {
            throw new IllegalStateException("Unexpected campaign state: " + state);
        } else if (REVIEW_STAGE_DONE.equals(state) && requestedStageNumber != currentStageNumber + 1) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is currently in stage " + currentStageNumber);
        } else if (CREATED.equals(state) && requestedStageNumber != 1) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign was just created");
        } else if (requestedStageNumber > stages) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign has only " + stages + " stages");
        } else {
            final CertificationHandler handler = findCertificationHandler(campaign);
            final AccessCertificationStageType stage = updateHelper.createStage(campaign, currentStageNumber + 1);
            final List<ItemDelta<?, ?>> deltas = updateHelper.getDeltasForStageOpen(campaign, stage, handler, task, result);
            updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
            updateHelper.afterStageOpen(campaignOid, stage, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't move to certification campaign stage " + requestedStageNumber + ": unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 2 with AccessCertificationCampaignStateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType in project midpoint by Evolveum.

the class CertificationManagerImpl method openNextStage.

@Override
public void openNextStage(@NotNull String campaignOid, @NotNull Task task, @NotNull OperationResult parentResult) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_OPEN_NEXT_STAGE);
    result.addParam("campaignOid", campaignOid);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        LOGGER.debug("openNextStage starting for {}", ObjectTypeUtil.toShortStringLazy(campaign));
        securityEnforcer.authorize(ModelAuthorizationAction.OPEN_CERTIFICATION_CAMPAIGN_REVIEW_STAGE.getUrl(), null, AuthorizationParameters.Builder.buildObject(campaign.asPrismObject()), null, task, result);
        final int currentStageNumber = campaign.getStageNumber();
        final int stages = CertCampaignTypeUtil.getNumberOfStages(campaign);
        final AccessCertificationCampaignStateType state = campaign.getState();
        LOGGER.trace("openNextStage: iteration={}, currentStageNumber={}, stages={}, state={}", norm(campaign.getIteration()), currentStageNumber, stages, state);
        if (IN_REVIEW_STAGE.equals(state)) {
            result.recordFatalError("Couldn't advance to the next review stage as the stage " + currentStageNumber + " is currently open.");
        } else if (IN_REMEDIATION.equals(state)) {
            result.recordFatalError("Couldn't advance to the next review stage as the campaign is currently in the remediation phase.");
        } else if (CLOSED.equals(state)) {
            result.recordFatalError("Couldn't advance to the next review stage as the campaign is already closed.");
        } else if (!REVIEW_STAGE_DONE.equals(state) && !CREATED.equals(state)) {
            throw new IllegalStateException("Unexpected campaign state: " + state);
        } else if (currentStageNumber >= stages) {
            result.recordFatalError("Couldn't advance to the next review stage as the campaign has only " + stages + " stages");
        } else {
            CertificationHandler handler = findCertificationHandler(campaign);
            openerHelper.openNextStage(campaign, handler, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't move to the next certification campaign stage: unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 3 with AccessCertificationCampaignStateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType in project midpoint by Evolveum.

the class ReportFunctions method searchCertificationDefinitions.

/**
 * Retrieves all definitions.
 * Augments them by count of campaigns (all + open ones).
 *
 * definitions and campaigns counts are expected to be low, so we can afford to go through all of them here
 */
public Collection<PrismObject<AccessCertificationDefinitionForReportType>> searchCertificationDefinitions() throws ConfigurationException, SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance();
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    List<PrismObject<AccessCertificationDefinitionType>> definitions = model.searchObjects(AccessCertificationDefinitionType.class, null, options, task, result);
    final Map<String, PrismObject<AccessCertificationDefinitionForReportType>> definitionsForReportMap = new HashMap<>();
    for (PrismObject<AccessCertificationDefinitionType> definition : definitions) {
        // create subclass with the values copied from the superclass
        PrismObject<AccessCertificationDefinitionForReportType> definitionForReport = prismContext.createObjectable(AccessCertificationDefinitionForReportType.class).asPrismObject();
        for (Item<?, ?> item : definition.getValue().getItems()) {
            definitionForReport.getValue().add(item.clone());
        }
        definitionsForReportMap.put(definition.getOid(), definitionForReport);
    }
    ResultHandler<AccessCertificationCampaignType> handler = (campaignObject, parentResult) -> {
        AccessCertificationCampaignType campaign = campaignObject.asObjectable();
        if (campaign.getDefinitionRef() != null) {
            String definitionOid = campaign.getDefinitionRef().getOid();
            PrismObject<AccessCertificationDefinitionForReportType> definitionObject = definitionsForReportMap.get(definitionOid);
            if (definitionObject != null) {
                AccessCertificationDefinitionForReportType definition = definitionObject.asObjectable();
                int campaigns = definition.getCampaigns() != null ? definition.getCampaigns() : 0;
                definition.setCampaigns(campaigns + 1);
                AccessCertificationCampaignStateType state = campaign.getState();
                if (state != AccessCertificationCampaignStateType.CREATED && state != CLOSED) {
                    int openCampaigns = definition.getOpenCampaigns() != null ? definition.getOpenCampaigns() : 0;
                    definition.setOpenCampaigns(openCampaigns + 1);
                }
            }
        }
        return true;
    };
    model.searchObjectsIterative(AccessCertificationCampaignType.class, null, handler, null, task, result);
    List<PrismObject<AccessCertificationDefinitionForReportType>> rv = new ArrayList<>(definitionsForReportMap.values());
    rv.sort((o1, o2) -> {
        String n1 = o1.asObjectable().getName().getOrig();
        String n2 = o2.asObjectable().getName().getOrig();
        if (n1 == null) {
            n1 = "";
        }
        return n1.compareTo(n2);
    });
    for (PrismObject<AccessCertificationDefinitionForReportType> defObject : rv) {
        AccessCertificationDefinitionForReportType def = defObject.asObjectable();
        if (def.getCampaigns() == null) {
            def.setCampaigns(0);
        }
        if (def.getOpenCampaigns() == null) {
            def.setOpenCampaigns(0);
        }
    }
    return rv;
}
Also used : com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) F_STATE(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_STATE) Trace(com.evolveum.midpoint.util.logging.Trace) F_NAME(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME) TaskManager(com.evolveum.midpoint.task.api.TaskManager) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AuditingConstants(com.evolveum.midpoint.cases.api.AuditingConstants) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) CollectionUtils(org.apache.commons.collections.CollectionUtils) CLOSED(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.CLOSED) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) CertCampaignTypeUtil.norm(com.evolveum.midpoint.schema.util.CertCampaignTypeUtil.norm) Task(com.evolveum.midpoint.task.api.Task) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Objects(java.util.Objects) ModelService(com.evolveum.midpoint.model.api.ModelService) AuditEventStageType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QName(javax.xml.namespace.QName) ModelAuditService(com.evolveum.midpoint.model.api.ModelAuditService) Clock(com.evolveum.midpoint.common.Clock) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 4 with AccessCertificationCampaignStateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType in project midpoint by Evolveum.

the class CertificationManagerImpl method closeCurrentStage.

@Override
public void closeCurrentStage(String campaignOid, int stageNumberToClose, Task task, OperationResult parentResult) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Validate.notNull(campaignOid, "campaignOid");
    Validate.notNull(task, "task");
    Validate.notNull(parentResult, "parentResult");
    OperationResult result = parentResult.createSubresult(OPERATION_CLOSE_CURRENT_STAGE);
    result.addParam("campaignOid", campaignOid);
    result.addParam("stageNumber", stageNumberToClose);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("closeCurrentStage starting for {}", ObjectTypeUtil.toShortString(campaign));
        }
        securityEnforcer.authorize(ModelAuthorizationAction.CLOSE_CERTIFICATION_CAMPAIGN_REVIEW_STAGE.getUrl(), null, campaign.asPrismObject(), null, null, null, result);
        final int currentStageNumber = campaign.getStageNumber();
        final int stages = CertCampaignTypeUtil.getNumberOfStages(campaign);
        final AccessCertificationCampaignStateType state = campaign.getState();
        LOGGER.trace("closeCurrentStage: currentStageNumber={}, stages={}, stageNumberToClose={}, state={}", currentStageNumber, stages, stageNumberToClose, state);
        if (stageNumberToClose != currentStageNumber) {
            result.recordFatalError("Couldn't close review stage " + stageNumberToClose + " as the campaign is not in that stage");
        } else if (!IN_REVIEW_STAGE.equals(state)) {
            result.recordFatalError("Couldn't close review stage " + stageNumberToClose + " as it is currently not open");
        } else {
            List<ItemDelta<?, ?>> deltas = updateHelper.getDeltasForStageClose(campaign, result);
            updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
            updateHelper.afterStageClose(campaignOid, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't close certification campaign stage " + stageNumberToClose + ": unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 5 with AccessCertificationCampaignStateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType in project midpoint by Evolveum.

the class AccCertUpdateHelper method createDeltasToRecordStageOpen.

// some bureaucracy... stage#, state, start time, triggers
List<ItemDelta<?, ?>> createDeltasToRecordStageOpen(AccessCertificationCampaignType campaign, AccessCertificationStageType newStage) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    final List<ItemDelta<?, ?>> itemDeltaList = new ArrayList<>();
    itemDeltaList.add(createStageNumberDelta(newStage.getNumber()));
    final PropertyDelta<AccessCertificationCampaignStateType> stateDelta = createStateDelta(IN_REVIEW_STAGE);
    itemDeltaList.add(stateDelta);
    final boolean campaignJustCreated = newStage.getNumber() == 1;
    if (campaignJustCreated) {
        PropertyDelta<XMLGregorianCalendar> startDelta = createStartTimeDelta(XmlTypeConverter.createXMLGregorianCalendar(new Date()));
        itemDeltaList.add(startDelta);
    }
    final XMLGregorianCalendar stageDeadline = newStage.getDeadline();
    if (stageDeadline != null) {
        // auto-closing and notifications triggers
        final AccessCertificationStageDefinitionType stageDef = CertCampaignTypeUtil.findStageDefinition(campaign, newStage.getNumber());
        List<TriggerType> triggers = new ArrayList<>();
        // pseudo-random ID so this trigger will not be deleted by trigger task handler (if this code itself is executed as part of previous trigger firing)
        // TODO implement this more seriously!
        long lastId = (long) (Math.random() * 1000000000);
        final TriggerType triggerClose = new TriggerType(prismContext);
        triggerClose.setHandlerUri(AccessCertificationCloseStageTriggerHandler.HANDLER_URI);
        triggerClose.setTimestamp(stageDeadline);
        triggerClose.setId(lastId);
        triggers.add(triggerClose);
        for (Duration beforeDeadline : stageDef.getNotifyBeforeDeadline()) {
            final XMLGregorianCalendar beforeEnd = CloneUtil.clone(stageDeadline);
            beforeEnd.add(beforeDeadline.negate());
            if (XmlTypeConverter.toMillis(beforeEnd) > System.currentTimeMillis()) {
                final TriggerType triggerBeforeEnd = new TriggerType(prismContext);
                triggerBeforeEnd.setHandlerUri(AccessCertificationCloseStageApproachingTriggerHandler.HANDLER_URI);
                triggerBeforeEnd.setTimestamp(beforeEnd);
                triggerBeforeEnd.setId(++lastId);
                triggers.add(triggerBeforeEnd);
            }
        }
        ContainerDelta<TriggerType> triggerDelta = ContainerDelta.createModificationReplace(ObjectType.F_TRIGGER, AccessCertificationCampaignType.class, prismContext, triggers);
        itemDeltaList.add(triggerDelta);
    }
    return itemDeltaList;
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Duration(javax.xml.datatype.Duration) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Aggregations

AccessCertificationCampaignStateType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 AuditingConstants (com.evolveum.midpoint.cases.api.AuditingConstants)1 Clock (com.evolveum.midpoint.common.Clock)1 ModelAuditService (com.evolveum.midpoint.model.api.ModelAuditService)1 ModelService (com.evolveum.midpoint.model.api.ModelService)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 com.evolveum.midpoint.schema (com.evolveum.midpoint.schema)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 CertCampaignTypeUtil.norm (com.evolveum.midpoint.schema.util.CertCampaignTypeUtil.norm)1 Task (com.evolveum.midpoint.task.api.Task)1 TaskManager (com.evolveum.midpoint.task.api.TaskManager)1 com.evolveum.midpoint.util.exception (com.evolveum.midpoint.util.exception)1 Trace (com.evolveum.midpoint.util.logging.Trace)1