use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.
the class TestParseObjectTemplate method assertObjectTemplateInternals.
// checks raw values of mappings
// should be called only on reparsed values in order to catch some raw-data-related serialization issues (MID-2196)
private void assertObjectTemplateInternals(PrismObject<ObjectTemplateType> object, QName elementName) throws SchemaException {
int assignmentValuesFound = 0;
for (ObjectTemplateMappingType mappingType : object.asObjectable().getMapping()) {
if (mappingType.getExpression() != null) {
if (mappingType.getTarget() != null && mappingType.getTarget().getPath() != null && new ItemPath(UserType.F_ASSIGNMENT).equivalent(mappingType.getTarget().getPath().getItemPath())) {
ItemDefinition assignmentDef = PrismTestUtil.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findItemDefinition(UserType.F_ASSIGNMENT);
for (JAXBElement evaluator : mappingType.getExpression().getExpressionEvaluator()) {
if (evaluator.getValue() instanceof RawType) {
RawType rawType = (RawType) evaluator.getValue();
Item assignment = rawType.getParsedItem(assignmentDef);
System.out.println("assignment:\n" + assignment.debugDump());
assignmentValuesFound++;
}
}
}
}
}
assertEquals("wrong # of assignment values found in mapping", 2, assignmentValuesFound);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.
the class ObjectPolicyPanel method createObjectTemplateList.
protected IModel<List<ObjectTemplateConfigTypeReferenceDto>> createObjectTemplateList() {
return new AbstractReadOnlyModel<List<ObjectTemplateConfigTypeReferenceDto>>() {
@Override
public List<ObjectTemplateConfigTypeReferenceDto> getObject() {
List<PrismObject<ObjectTemplateType>> templateList = null;
List<ObjectTemplateConfigTypeReferenceDto> list = new ArrayList<>();
OperationResult result = new OperationResult(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
try {
templateList = getPageBase().getModelService().searchObjects(ObjectTemplateType.class, new ObjectQuery(), null, task, result);
result.recomputeStatus();
} catch (Exception e) {
result.recordFatalError("Could not get list of object templates", e);
LoggingUtils.logUnexpectedException(LOGGER, "Could not get list of object templates", e);
// TODO - show this error in GUI
}
if (templateList != null) {
ObjectTemplateType template;
for (PrismObject<ObjectTemplateType> obj : templateList) {
template = obj.asObjectable();
list.add(new ObjectTemplateConfigTypeReferenceDto(template.getOid(), WebComponentUtil.getName(template)));
}
}
return list;
}
};
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType 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.ObjectTemplateType in project midpoint by Evolveum.
the class ObjectTemplateProcessor method collectTripleFromMappings.
private <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> XMLGregorianCalendar collectTripleFromMappings(Collection<ObjectTemplateMappingType> mappings, ObjectTemplateMappingEvaluationPhaseType phase, LensContext<F> context, ObjectTemplateType objectTemplateType, ObjectDeltaObject<F> focusOdo, PrismObject<T> target, Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, int iteration, String iterationToken, XMLGregorianCalendar now, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, PolicyViolationException {
XMLGregorianCalendar nextRecomputeTime = null;
for (ObjectTemplateMappingType mappingType : mappings) {
ObjectTemplateMappingEvaluationPhaseType mappingPhase = mappingType.getEvaluationPhase();
if (mappingPhase == null) {
mappingPhase = ObjectTemplateMappingEvaluationPhaseType.BEFORE_ASSIGNMENTS;
}
if (phase != null && mappingPhase != phase) {
continue;
}
LOGGER.trace("Starting evaluation of mapping '{}' in {}", mappingType.getName(), contextDesc);
// for mapping chaining
ObjectDeltaObject<F> updatedFocusOdo = getUpdatedFocusOdo(context, focusOdo, outputTripleMap, mappingType, contextDesc);
Mapping<V, D> mapping = mappingEvaluator.createFocusMapping(mappingFactory, context, mappingType, objectTemplateType, updatedFocusOdo, target, null, iteration, iterationToken, context.getSystemConfiguration(), now, contextDesc, task, result);
if (mapping == null) {
continue;
}
Boolean timeConstraintValid = mapping.evaluateTimeConstraintValid(task, result);
if (timeConstraintValid != null && !timeConstraintValid) {
// Delayed mapping. Just schedule recompute time
XMLGregorianCalendar mappingNextRecomputeTime = mapping.getNextRecomputeTime();
LOGGER.trace("Evaluation of mapping {} delayed to {}", mapping, mappingNextRecomputeTime);
if (mappingNextRecomputeTime != null) {
if (nextRecomputeTime == null || nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
nextRecomputeTime = mappingNextRecomputeTime;
}
}
continue;
}
mappingEvaluator.evaluateMapping(mapping, context, task, result);
ItemPath itemPath = mapping.getOutputPath();
if (itemPath == null) {
continue;
}
DeltaSetTriple<ItemValueWithOrigin<V, D>> outputTriple = ItemValueWithOrigin.createOutputTriple(mapping);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Output triple for {}:\n{}", mapping, DebugUtil.debugDump(outputTriple));
}
if (outputTriple == null) {
continue;
}
DeltaSetTriple<ItemValueWithOrigin<V, D>> mapTriple = (DeltaSetTriple<ItemValueWithOrigin<V, D>>) outputTripleMap.get(itemPath);
if (mapTriple == null) {
outputTripleMap.put(itemPath, outputTriple);
} else {
mapTriple.merge(outputTriple);
}
}
return nextRecomputeTime;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.
the class ObjectTemplateProcessor method collectMappings.
private List<ObjectTemplateMappingType> collectMappings(ObjectTemplateType objectTemplateType) {
List<ObjectTemplateMappingType> mappings = new ArrayList<ObjectTemplateMappingType>();
mappings.addAll(objectTemplateType.getMapping());
for (ObjectTemplateItemDefinitionType templateItemDefType : objectTemplateType.getItem()) {
for (ObjectTemplateMappingType mapping : templateItemDefType.getMapping()) {
VariableBindingDefinitionType target = mapping.getTarget();
if (target == null) {
target = new VariableBindingDefinitionType();
target.setPath(templateItemDefType.getRef());
mapping.setTarget(target);
} else if (target.getPath() == null) {
target = target.clone();
target.setPath(templateItemDefType.getRef());
mapping.setTarget(target);
}
mappings.add(mapping);
}
}
return mappings;
}
Aggregations