Search in sources :

Example 1 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class ResourceActivationEditor method prepareActivationObject.

private void prepareActivationObject(ResourceActivationDefinitionType activation) {
    if (activation.getExistence() == null) {
        activation.setExistence(new ResourceBidirectionalMappingType());
    } else {
        for (MappingType mapping : activation.getExistence().getInbound()) {
            if (mapping.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(EXISTENCE_DEFAULT_SOURCE));
                mapping.getSource().add(source);
            }
        }
    }
    if (activation.getAdministrativeStatus() == null) {
        activation.setAdministrativeStatus(new ResourceBidirectionalMappingType());
    } else {
        for (MappingType outbound : activation.getAdministrativeStatus().getOutbound()) {
            if (outbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(ADM_STATUS_OUT_SOURCE_DEFAULT));
                outbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(ADM_STATUS_OUT_TARGET_DEFAULT));
                outbound.setTarget(target);
            }
        }
        for (MappingType inbound : activation.getAdministrativeStatus().getInbound()) {
            if (inbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(ADM_STATUS_IN_SOURCE_DEFAULT));
                inbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(ADM_STATUS_IN_TARGET_DEFAULT));
                inbound.setTarget(target);
            }
        }
    }
    if (activation.getValidFrom() == null) {
        activation.setValidFrom(new ResourceBidirectionalMappingType());
    } else {
        for (MappingType outbound : activation.getValidFrom().getOutbound()) {
            if (outbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(VALID_FROM_OUT_SOURCE_DEFAULT));
                outbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(VALID_FROM_OUT_TARGET_DEFAULT));
                outbound.setTarget(target);
            }
        }
        for (MappingType inbound : activation.getValidFrom().getInbound()) {
            if (inbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(VALID_FROM_IN_SOURCE_DEFAULT));
                inbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(VALID_FROM_IN_TARGET_DEFAULT));
                inbound.setTarget(target);
            }
        }
    }
    if (activation.getValidTo() == null) {
        activation.setValidTo(new ResourceBidirectionalMappingType());
    } else {
        for (MappingType outbound : activation.getValidTo().getOutbound()) {
            if (outbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(VALID_TO_OUT_SOURCE_DEFAULT));
                outbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(VALID_TO_OUT_TARGET_DEFAULT));
                outbound.setTarget(target);
            }
        }
        for (MappingType inbound : activation.getValidTo().getInbound()) {
            if (inbound.equals(new MappingType())) {
                VariableBindingDefinitionType source = new VariableBindingDefinitionType();
                source.setPath(new ItemPathType(VALID_TO_IN_SOURCE_DEFAULT));
                inbound.getSource().add(source);
                VariableBindingDefinitionType target = new VariableBindingDefinitionType();
                target.setPath(new ItemPathType(VALID_TO_IN_TARGET_DEFAULT));
                inbound.setTarget(target);
            }
        }
    }
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 2 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class DeltaConvertor method createItemDelta.

public static <IV extends PrismValue, ID extends ItemDefinition> ItemDelta<IV, ID> createItemDelta(ItemDeltaType propMod, PrismContainerDefinition<?> pcDef, boolean allowRawValues) throws SchemaException {
    ItemPathType parentPathType = propMod.getPath();
    ItemPath parentPath = null;
    if (parentPathType != null) {
        parentPath = parentPathType.getItemPath();
    } else {
        throw new IllegalStateException("Path argument in the itemDelta HAVE TO BE specified.");
    }
    if (propMod.getValue() == null) {
        throw new IllegalArgumentException("No value in item delta (path: " + parentPath + ") while creating a property delta");
    }
    ItemDefinition containingPcd = pcDef.findItemDefinition(parentPath);
    PrismContainerDefinition containerDef = null;
    if (containingPcd == null) {
        containerDef = pcDef.findContainerDefinition(parentPath.allUpToLastNamed());
        if (containerDef == null) {
            if (allowRawValues) {
                return null;
            }
            throw new SchemaException("No definition for " + parentPath.allUpToLastNamed().lastNamed().getName() + " (while creating delta for " + pcDef + ")");
        }
    }
    QName elementName = parentPath.lastNamed().getName();
    //propMod.getValue().getParsedValue(containingPcd);
    Item item = RawTypeUtil.getParsedItem(containingPcd, propMod.getValue(), elementName, containerDef);
    ItemDelta<IV, ID> itemDelta = item.createDelta(parentPath);
    if (propMod.getModificationType() == ModificationTypeType.ADD) {
        itemDelta.addValuesToAdd(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
    } else if (propMod.getModificationType() == ModificationTypeType.DELETE) {
        itemDelta.addValuesToDelete(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
    } else if (propMod.getModificationType() == ModificationTypeType.REPLACE) {
        itemDelta.setValuesToReplace(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
    }
    if (!propMod.getEstimatedOldValue().isEmpty()) {
        Item oldItem = RawTypeUtil.getParsedItem(containingPcd, propMod.getEstimatedOldValue(), elementName, containerDef);
        itemDelta.addEstimatedOldValues(PrismValue.resetParentCollection(PrismValue.cloneCollection(oldItem.getValues())));
    }
    return itemDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class DeltaConvertor method toItemDeltaTypes.

public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta, DeltaConversionOptions options) throws SchemaException {
    if (InternalsConfig.consistencyChecks) {
        delta.checkConsistence();
    }
    if (!delta.isEmpty() && delta.getPrismContext() == null) {
        throw new IllegalStateException("Non-empty ItemDelta with no prismContext cannot be converted to ItemDeltaType.");
    }
    Collection<ItemDeltaType> mods = new ArrayList<>();
    ItemPathType path = new ItemPathType(delta.getPath());
    if (delta.getValuesToReplace() != null) {
        ItemDeltaType mod = new ItemDeltaType();
        mod.setPath(path);
        mod.setModificationType(ModificationTypeType.REPLACE);
        try {
            addModValues(delta, mod, delta.getValuesToReplace(), options);
        } catch (SchemaException e) {
            throw new SchemaException(e.getMessage() + " while converting property " + delta.getElementName(), e);
        }
        addOldValues(delta, mod, delta.getEstimatedOldValues(), options);
        mods.add(mod);
    }
    if (delta.getValuesToAdd() != null) {
        ItemDeltaType mod = new ItemDeltaType();
        mod.setPath(path);
        mod.setModificationType(ModificationTypeType.ADD);
        try {
            addModValues(delta, mod, delta.getValuesToAdd(), options);
        } catch (SchemaException e) {
            throw new SchemaException(e.getMessage() + " while converting property " + delta.getElementName(), e);
        }
        addOldValues(delta, mod, delta.getEstimatedOldValues(), options);
        mods.add(mod);
    }
    if (delta.getValuesToDelete() != null) {
        ItemDeltaType mod = new ItemDeltaType();
        mod.setPath(path);
        mod.setModificationType(ModificationTypeType.DELETE);
        try {
            addModValues(delta, mod, delta.getValuesToDelete(), options);
        } catch (SchemaException e) {
            throw new SchemaException(e.getMessage() + " while converting property " + delta.getElementName(), e);
        }
        addOldValues(delta, mod, delta.getEstimatedOldValues(), options);
        mods.add(mod);
    }
    return mods;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 4 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class ItemPathTypeDeserializer method deserialize.

@Override
public ItemPathType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    if (jp.getCurrentToken() != JsonToken.VALUE_STRING) {
        throw new JsonParseException("Cannot parse path value. Expected that the value will be string but it is: " + jp.getCurrentTokenId(), jp.getCurrentLocation());
    }
    String path = jp.getText();
    if (StringUtils.isBlank(path)) {
        throw new IllegalStateException("Error while deserializing path. No path specified.");
    }
    //System.out.println("path: " + path);
    //		if (path.startsWith("declare.*")){
    XPathHolder holder = new XPathHolder(path);
    ItemPath itemPath = holder.toItemPath();
    ItemPathType itemPathType = new ItemPathType(itemPath);
    return itemPathType;
//		ItemPathType itemPathType = new ItemPathType();
//		itemPathType.getContent().add(jp.getText());
//		
//		return itemPathType;
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class QueryConvertor method getPath.

private static ItemPath getPath(MapXNode clauseXMap, QName key) throws SchemaException {
    XNode xnode = clauseXMap.get(key);
    if (xnode == null) {
        return null;
    }
    if (!(xnode instanceof PrimitiveXNode<?>)) {
        throw new SchemaException("Expected that field " + key + " will be primitive, but it is " + xnode.getDesc());
    }
    ItemPathType itemPathType = clauseXMap.getParsedPrimitiveValue(key, ItemPathType.COMPLEX_TYPE);
    return itemPathType != null ? itemPathType.getItemPath() : null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)114 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)58 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)27 Test (org.testng.annotations.Test)27 QName (javax.xml.namespace.QName)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)21 List (java.util.List)18 NotNull (org.jetbrains.annotations.NotNull)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)15 ArrayList (java.util.ArrayList)15 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)13 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13 Collectors (java.util.stream.Collectors)13 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)11 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)11 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)11 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)11