Search in sources :

Example 21 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class TestObjectQuery method testMatchEqualMultivalue.

@Test
public void testMatchEqualMultivalue() throws Exception {
    PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML);
    PrismPropertyDefinitionImpl def = new PrismPropertyDefinitionImpl(new QName("indexedString"), DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
    ObjectFilter filter = QueryBuilder.queryFor(UserType.class, PrismTestUtil.getPrismContext()).item(new ItemPath(UserType.F_EXTENSION, "indexedString"), def).eq("alpha").buildFilter();
    boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry);
    AssertJUnit.assertTrue("filter does not match object", match);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 22 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath 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 23 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class GetOperationOptions method fromRestOptions.

public static Collection<SelectorOptions<GetOperationOptions>> fromRestOptions(List<String> options, List<String> include, List<String> exclude) {
    if (CollectionUtils.isEmpty(options) && CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)) {
        return null;
    }
    Collection<SelectorOptions<GetOperationOptions>> rv = new ArrayList<>();
    GetOperationOptions rootOptions = fromRestOptions(options);
    if (rootOptions != null) {
        rv.add(SelectorOptions.create(rootOptions));
    }
    for (ItemPath includePath : ItemPath.fromStringList(include)) {
        rv.add(SelectorOptions.create(includePath, GetOperationOptions.createRetrieve()));
    }
    for (ItemPath excludePath : ItemPath.fromStringList(exclude)) {
        rv.add(SelectorOptions.create(excludePath, GetOperationOptions.createDontRetrieve()));
    }
    return rv;
}
Also used : ArrayList(java.util.ArrayList) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class TestPrismParsing method test300MeleeContext.

@Test
public void test300MeleeContext() throws Exception {
    final String TEST_NAME = "test300MeleeContext";
    PrismInternalTestUtil.displayTestTitle(TEST_NAME);
    // GIVEN
    PrismContext prismContext = constructInitializedPrismContext();
    PrismObject<UserType> userJack = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME));
    PrismContainer<Containerable> meleeContextContainer = userJack.findOrCreateContainer(new ItemPath(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT));
    PrismReference opponentRef = meleeContextContainer.findOrCreateReference(EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT);
    PrismObject<UserType> userBarbossa = prismContext.parseObject(getFile(USER_BARBOSSA_FILE_BASENAME));
    // Cosmetics to make sure the equivalence assert below works
    userBarbossa.setElementName(EXTENSION_MELEE_CONTEXT_OPPONENT_ELEMENT);
    PrismReferenceValue opponentRefValue = new PrismReferenceValue();
    opponentRefValue.setObject(userBarbossa);
    opponentRef.add(opponentRefValue);
    System.out.println("User jack:");
    System.out.println(userJack.debugDump());
    // WHEN
    String elementJack = prismContext.serializeObjectToString(userJack, getOutputFormat());
    // THEN
    System.out.println("Serialized user jack:");
    System.out.println(elementJack);
    // TODO: see that there is really the serialized barbossa
    // WHEN
    PrismObject<UserType> reparsedUserJack = prismContext.parseObject(elementJack);
    // THEN
    System.out.println("Re-parsed user jack:");
    System.out.println(reparsedUserJack.debugDump());
    PrismReference reparsedOpponentRef = reparsedUserJack.findReference(new ItemPath(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT, EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT));
    assertNotNull("No opponent ref (reparsed)", reparsedOpponentRef);
    PrismReferenceValue reparsedOpponentRefValue = reparsedOpponentRef.getValue();
    assertNotNull("No opponent ref value (reparsed)", reparsedOpponentRefValue);
    PrismObject<UserType> reparsedUserBarbossa = reparsedOpponentRefValue.getObject();
    assertNotNull("No object in opponent ref value (reparsed)", reparsedUserBarbossa);
    PrismAsserts.assertEquivalent("User barbossa", userBarbossa, reparsedUserBarbossa);
    // Make the original user jack suitable for comparison.
    // Some of the accountRef information is (intentionally) lost in re-parsing therefore erase it before comparing
    PrismReference jackAccountRef = userJack.findReference(UserType.F_ACCOUNT_REF);
    for (PrismReferenceValue accRefVal : jackAccountRef.getValues()) {
        String oid = accRefVal.getOid();
        QName targetType = accRefVal.getTargetType();
        accRefVal.setObject(null);
        accRefVal.setOid(oid);
        accRefVal.setTargetType(targetType);
    }
    PrismAsserts.assertEquivalent("User jack", userJack, reparsedUserJack);
}
Also used : QName(javax.xml.namespace.QName) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 25 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class MappingTestEvaluator method createMappingBuilder.

public <T> Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> createMappingBuilder(String filename, String testName, final StringPolicyType policy, ItemPath defaultTargetPropertyPath, ObjectDelta<UserType> userDelta, PrismObject<UserType> userOld) throws SchemaException, IOException, JAXBException {
    MappingType mappingType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), MappingType.COMPLEX_TYPE);
    Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> mappingBuilder = mappingFactory.createMappingBuilder(mappingType, testName);
    // Source context: user
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userOld, userDelta, null);
    userOdo.recompute();
    mappingBuilder.setSourceContext(userOdo);
    // Variable $user
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_USER, userOdo);
    // Variable $account
    PrismObject<ShadowType> account = getAccount();
    ObjectDeltaObject<ShadowType> accountOdo = new ObjectDeltaObject<ShadowType>(account, null, null);
    accountOdo.recompute();
    mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, accountOdo);
    // Target context: user
    PrismObjectDefinition<UserType> userDefinition = getUserDefinition();
    mappingBuilder.setTargetContext(userDefinition);
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        ItemPath outputPath;

        ItemDefinition outputDefinition;

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

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

        @Override
        public StringPolicyType resolve() {
            return policy;
        }
    };
    mappingBuilder.setStringPolicyResolver(stringPolicyResolver);
    // Default target
    if (defaultTargetPropertyPath != null) {
        PrismPropertyDefinition<T> targetDefDefinition = userDefinition.findItemDefinition(defaultTargetPropertyPath);
        if (targetDefDefinition == null) {
            throw new IllegalArgumentException("The item path '" + defaultTargetPropertyPath + "' does not have a definition in " + userDefinition);
        }
        mappingBuilder.setDefaultTargetDefinition(targetDefDefinition);
    }
    return mappingBuilder;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)693 Test (org.testng.annotations.Test)184 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)143 QName (javax.xml.namespace.QName)137 Task (com.evolveum.midpoint.task.api.Task)104 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)84 ArrayList (java.util.ArrayList)79 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)71 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)68 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)61 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)48 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)46 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)41 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)38 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)38 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)33 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)31 NotNull (org.jetbrains.annotations.NotNull)30