Search in sources :

Example 1 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class ItemWrapperComparator method compare.

@Override
public int compare(ItemWrapper p1, ItemWrapper p2) {
    ItemDefinition def1 = p1.getItemDefinition();
    ItemDefinition def2 = p2.getItemDefinition();
    if (isMainContainer(p1)) {
        return -1;
    }
    if (isMainContainer(p2)) {
        return 1;
    }
    Integer index1 = def1.getDisplayOrder();
    Integer index2 = def2.getDisplayOrder();
    if (index1 != null && index2 != null) {
        return index1 - index2;
    } else if (index1 != null && index2 == null) {
        return -1;
    } else if (index1 == null && index2 != null) {
        return 1;
    }
    return String.CASE_INSENSITIVE_ORDER.compare(getDisplayName(def1), getDisplayName(def2));
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition)

Example 2 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class DynamicFieldGroupPanel method createItemWrapper.

private ItemWrapper createItemWrapper(AbstractFormItemType formField, ObjectWrapper objectWrapper) {
    ItemPathType itemPathType = GuiImplUtil.getPathType(formField);
    if (itemPathType == null) {
        getSession().error("Bad form item definition. It has to contain reference to the real attribute");
        LOGGER.error("Bad form item definition. It has to contain reference to the real attribute");
        throw new RestartResponseException(getPageBase());
    }
    ItemPath path = itemPathType.getItemPath();
    ItemDefinition itemDef = objectWrapper.getObject().getDefinition().findItemDefinition(path);
    ItemWrapper itemWrapper = null;
    if (itemDef instanceof PrismContainerDefinition) {
        itemWrapper = objectWrapper.findContainerWrapper(path);
    } else {
        itemWrapper = objectWrapper.findPropertyWrapper(path);
    }
    if (itemWrapper == null) {
        getSession().error("Bad form item definition. No attribute with path: " + path + " was found");
        LOGGER.error("Bad form item definition. No attribute with path: " + path + " was found");
        throw new RestartResponseException(getPageBase());
    }
    applyFormDefinition(itemWrapper, formField);
    return itemWrapper;
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class OutboundProcessor method evaluateMapping.

private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> Mapping<V, D> evaluateMapping(final Mapping.Builder<V, D> mappingBuilder, QName mappingQName, D targetDefinition, ObjectDeltaObject<F> focusOdo, ObjectDeltaObject<ShadowType> projectionOdo, String operation, RefinedObjectClassDefinition rOcDef, RefinedObjectClassDefinition assocTargetObjectClassDefinition, LensContext<F> context, LensProjectionContext projCtx, final Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    if (!mappingBuilder.isApplicableToChannel(context.getChannel())) {
        LOGGER.trace("Skipping outbound mapping for {} because the channel does not match", mappingQName);
        return null;
    }
    // TODO: check access
    // This is just supposed to be an optimization. The consolidation should deal with the weak mapping
    // even if it is there. But in that case we do not need to evaluate it at all.
    // Edit 2017-02-16 pmed: It's not quite true. If the attribute is non-tolerant, it will get removed if we would
    // skip evaluation of this mapping. So we really need to do this.
    //		if (mappingBuilder.getStrength() == MappingStrengthType.WEAK && projCtx.hasValueForAttribute(mappingQName)) {
    //			LOGGER.trace("Skipping outbound mapping for {} because it is weak", mappingQName);
    //			return null;
    //		}
    mappingBuilder.setDefaultTargetDefinition(targetDefinition);
    mappingBuilder.setSourceContext(focusOdo);
    mappingBuilder.setMappingQName(mappingQName);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_USER, focusOdo);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focusOdo);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, projectionOdo);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, projectionOdo);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, projectionOdo);
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration());
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION, LensUtil.getIterationVariableValue(projCtx));
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, LensUtil.getIterationTokenVariableValue(projCtx));
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, projCtx.getResource());
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_OPERATION, operation);
    if (assocTargetObjectClassDefinition != null) {
        mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION, assocTargetObjectClassDefinition);
    }
    mappingBuilder.setRootNode(focusOdo);
    mappingBuilder.setOriginType(OriginType.OUTBOUND);
    mappingBuilder.setRefinedObjectClassDefinition(rOcDef);
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        private ItemPath outputPath;

        private ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            if (mappingBuilder.getMappingType().getExpression() != null) {
                List<JAXBElement<?>> evaluators = mappingBuilder.getMappingType().getExpression().getExpressionEvaluator();
                for (JAXBElement jaxbEvaluator : evaluators) {
                    Object object = jaxbEvaluator.getValue();
                    if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
                        ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
                        try {
                            ValuePolicyType valuePolicyType = mappingBuilder.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + "value", task, new OperationResult("Resolving value policy"));
                            if (valuePolicyType != null) {
                                return valuePolicyType.getStringPolicy();
                            }
                        } catch (CommonException ex) {
                            throw new SystemException(ex.getMessage(), ex);
                        }
                    }
                }
            }
            return null;
        }
    };
    mappingBuilder.setStringPolicyResolver(stringPolicyResolver);
    // (e.g. in old values in ADD situations and new values in DELETE situations).
    if (focusOdo.getOldObject() == null) {
        mappingBuilder.setConditionMaskOld(false);
    }
    if (focusOdo.getNewObject() == null) {
        mappingBuilder.setConditionMaskNew(false);
    }
    Mapping<V, D> mapping = mappingBuilder.build();
    mappingEvaluator.evaluateMapping(mapping, context, projCtx, task, result);
    return mapping;
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JAXBElement(javax.xml.bind.JAXBElement) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) GenerateExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class SearchPanel method createPropertiesList.

private List<Property> createPropertiesList() {
    List<Property> list = new ArrayList<>();
    Search search = getModelObject();
    List<ItemDefinition> defs = search.getAllDefinitions();
    for (ItemDefinition def : defs) {
        list.add(new Property(def));
    }
    Collections.sort(list);
    return list;
}
Also used : ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition)

Example 5 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class PrismAsserts method assertDefinition.

public static void assertDefinition(Item item, QName type, int minOccurs, int maxOccurs) {
    ItemDefinition definition = item.getDefinition();
    assertDefinition(definition, item.getElementName(), type, minOccurs, maxOccurs);
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition)

Aggregations

ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)35 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 QName (javax.xml.namespace.QName)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)5 ArrayList (java.util.ArrayList)5 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismValue (com.evolveum.midpoint.prism.PrismValue)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)3 Task (com.evolveum.midpoint.task.api.Task)3