Search in sources :

Example 1 with TriggerType

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

the class AccessCertificationCloseStageTriggerHandler method handle.

@Override
public <O extends ObjectType> void handle(PrismObject<O> prismObject, TriggerType trigger, Task task, OperationResult result) {
    try {
        ObjectType object = prismObject.asObjectable();
        if (!(object instanceof AccessCertificationCampaignType)) {
            LOGGER.error("Trigger of this type is supported only on {} objects, not on {}", AccessCertificationCampaignType.class.getSimpleName(), object.getClass().getName());
            return;
        }
        AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object;
        LOGGER.info("Automatically closing current stage of {}", ObjectTypeUtil.toShortString(campaign));
        if (campaign.getState() != IN_REVIEW_STAGE) {
            LOGGER.warn("Campaign {} is not in a review stage; this 'close stage' trigger will be ignored.", ObjectTypeUtil.toShortString(campaign));
            return;
        }
        int currentStageNumber = campaign.getStageNumber();
        certificationManager.closeCurrentStage(campaign.getOid(), currentStageNumber, task, result);
        if (currentStageNumber < CertCampaignTypeUtil.getNumberOfStages(campaign)) {
            LOGGER.info("Automatically opening next stage of {}", ObjectTypeUtil.toShortString(campaign));
            certificationManager.openNextStage(campaign.getOid(), currentStageNumber + 1, task, result);
        } else {
            LOGGER.info("Automatically starting remediation for {}", ObjectTypeUtil.toShortString(campaign));
            certificationManager.startRemediation(campaign.getOid(), task, result);
        }
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | RuntimeException e) {
        LoggingUtils.logException(LOGGER, "Couldn't close current campaign and possibly advance to the next one", e);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 2 with TriggerType

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

the class ObjectTemplateProcessor method processTemplate.

/**
	 * Process focus template: application of object template where focus is both source and target. 
	 */
public <F extends FocusType> void processTemplate(LensContext<F> context, ObjectTemplateMappingEvaluationPhaseType phase, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ObjectAlreadyExistsException {
    LensFocusContext<F> focusContext = context.getFocusContext();
    if (focusContext.isDelete()) {
        LOGGER.trace("Skipping processing of object template: focus delete");
        return;
    }
    ObjectTemplateType objectTemplate = context.getFocusTemplate();
    if (objectTemplate == null) {
        // No applicable template
        LOGGER.trace("Skipping processing of object template: no object template");
        return;
    }
    int iteration = focusContext.getIteration();
    String iterationToken = focusContext.getIterationToken();
    ObjectDeltaObject<F> focusOdo = focusContext.getObjectDeltaObject();
    PrismObjectDefinition<F> focusDefinition = getObjectDefinition(focusContext.getObjectTypeClass());
    LOGGER.trace("Applying {} to {}, iteration {} ({}), phase {}", objectTemplate, focusContext.getObjectNew(), iteration, iterationToken, phase);
    Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap = new HashMap<>();
    Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap = collectItemDefinitionsFromTemplate(objectTemplate, objectTemplate.toString(), task, result);
    XMLGregorianCalendar nextRecomputeTime = collectTripleFromTemplate(context, objectTemplate, phase, focusOdo, focusOdo.getNewObject(), outputTripleMap, iteration, iterationToken, now, objectTemplate.toString(), task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("outputTripleMap before item delta computation:\n{}", DebugUtil.debugDumpMapMultiLine(outputTripleMap));
    }
    String contextDesc = "object template " + objectTemplate + " for focus " + focusOdo.getAnyObject();
    Collection<ItemDelta<?, ?>> itemDeltas = computeItemDeltas(outputTripleMap, itemDefinitionsMap, focusOdo.getObjectDelta(), focusOdo.getNewObject(), focusDefinition, contextDesc);
    focusContext.applyProjectionWaveSecondaryDeltas(itemDeltas);
    if (nextRecomputeTime != null) {
        boolean alreadyHasTrigger = false;
        PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
        if (objectCurrent != null) {
            for (TriggerType trigger : objectCurrent.asObjectable().getTrigger()) {
                if (RecomputeTriggerHandler.HANDLER_URI.equals(trigger.getHandlerUri()) && nextRecomputeTime.equals(trigger.getTimestamp())) {
                    alreadyHasTrigger = true;
                    break;
                }
            }
        }
        if (!alreadyHasTrigger) {
            PrismObjectDefinition<F> objectDefinition = focusContext.getObjectDefinition();
            PrismContainerDefinition<TriggerType> triggerContDef = objectDefinition.findContainerDefinition(ObjectType.F_TRIGGER);
            ContainerDelta<TriggerType> triggerDelta = triggerContDef.createEmptyDelta(new ItemPath(ObjectType.F_TRIGGER));
            PrismContainerValue<TriggerType> triggerCVal = triggerContDef.createValue();
            triggerDelta.addValueToAdd(triggerCVal);
            TriggerType triggerType = triggerCVal.asContainerable();
            triggerType.setTimestamp(nextRecomputeTime);
            triggerType.setHandlerUri(RecomputeTriggerHandler.HANDLER_URI);
            focusContext.swallowToProjectionWaveSecondaryDelta(triggerDelta);
        }
    }
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) HashMap(java.util.HashMap) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with TriggerType

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

the class TriggerScannerTaskHandler method fireTriggers.

private void fireTriggers(AbstractScannerResultHandler<ObjectType> handler, PrismObject<ObjectType> object, Task workerTask, Task coordinatorTask, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ObjectAlreadyExistsException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    PrismContainer<TriggerType> triggerContainer = object.findContainer(F_TRIGGER);
    if (triggerContainer == null) {
        LOGGER.warn("Strange thing, attempt to fire triggers on {}, but it does not have trigger container", object);
    } else {
        List<PrismContainerValue<TriggerType>> triggerCVals = triggerContainer.getValues();
        if (triggerCVals.isEmpty()) {
            LOGGER.warn("Strange thing, attempt to fire triggers on {}, but it does not have any triggers in trigger container", object);
        } else {
            LOGGER.trace("Firing triggers for {} ({} triggers)", object, triggerCVals.size());
            List<TriggerType> triggers = getSortedTriggers(triggerCVals);
            for (TriggerType trigger : triggers) {
                XMLGregorianCalendar timestamp = trigger.getTimestamp();
                if (timestamp == null) {
                    LOGGER.warn("Trigger without a timestamp in {}", object);
                } else {
                    if (isHot(handler, timestamp)) {
                        fireTrigger(trigger, object, triggerContainer.getDefinition(), workerTask, coordinatorTask, result);
                    } else {
                        LOGGER.trace("Trigger {} is not hot (timestamp={}, thisScanTimestamp={}, lastScanTimestamp={})", trigger, timestamp, handler.getThisScanTimestamp(), handler.getLastScanTimestamp());
                    }
                }
            }
        }
    }
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue)

Example 4 with TriggerType

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

the class TriggerScannerTaskHandler method removeTrigger.

private void removeTrigger(PrismObject<ObjectType> object, PrismContainerValue<TriggerType> triggerCVal, Task task, PrismContainerDefinition<TriggerType> triggerContainerDef) {
    ContainerDelta<TriggerType> triggerDelta = triggerContainerDef.createEmptyDelta(new ItemPath(F_TRIGGER));
    triggerDelta.addValuesToDelete(triggerCVal.clone());
    Collection<? extends ItemDelta> modifications = MiscSchemaUtil.createCollection(triggerDelta);
    // This is detached result. It will not take part of the task result. We do not really care.
    OperationResult result = new OperationResult(TriggerScannerTaskHandler.class.getName() + ".removeTrigger");
    try {
        repositoryService.modifyObject(object.getCompileTimeClass(), object.getOid(), modifications, result);
        result.computeStatus();
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
    } catch (ObjectNotFoundException e) {
        // Object is gone. Ergo there are no triggers left. Ergo the trigger was removed.
        // Ergo this is not really an error.
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
        LOGGER.trace("Unable to remove trigger from {}: {} (but this is probably OK)", object, e.getMessage(), e);
    } catch (SchemaException | ObjectAlreadyExistsException e) {
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
        LOGGER.error("Unable to remove trigger from {}: {}", object, e.getMessage(), e);
    } catch (Throwable t) {
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
        throw t;
    } finally {
        // maybe OK (absolute correctness is not quite important here)
        task.markObjectActionExecutedBoundary();
    }
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with TriggerType

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

the class AbstractModelIntegrationTest method assertTrigger.

protected <O extends ObjectType> void assertTrigger(PrismObject<O> object, String handlerUri, XMLGregorianCalendar mid, long tolerance) throws ObjectNotFoundException, SchemaException {
    XMLGregorianCalendar start = XmlTypeConverter.addMillis(mid, -tolerance);
    XMLGregorianCalendar end = XmlTypeConverter.addMillis(mid, tolerance);
    for (TriggerType trigger : object.asObjectable().getTrigger()) {
        if (handlerUri.equals(trigger.getHandlerUri()) && MiscUtil.isBetween(trigger.getTimestamp(), start, end)) {
            return;
        }
    }
    AssertJUnit.fail("Expected that " + object + " will have a trigger but it has not");
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType)

Aggregations

TriggerType (com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType)9 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)1 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 DeltaSetTriple (com.evolveum.midpoint.prism.delta.DeltaSetTriple)1 ROExtPolyString (com.evolveum.midpoint.repo.sql.data.common.any.ROExtPolyString)1 ROExtString (com.evolveum.midpoint.repo.sql.data.common.any.ROExtString)1 ROperationExecution (com.evolveum.midpoint.repo.sql.data.common.container.ROperationExecution)1 RTrigger (com.evolveum.midpoint.repo.sql.data.common.container.RTrigger)1 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1