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);
}
}
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);
}
}
}
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());
}
}
}
}
}
}
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();
}
}
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");
}
Aggregations