Search in sources :

Example 61 with ItemPath

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

the class TestMappingDynamicSysVar method testPasswordPolyString.

@Test
public void testPasswordPolyString() throws Exception {
    // WHEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = evaluator.evaluateMappingDynamicReplace("mapping-script-system-variables-password.xml", "testPasswordPolyString", // target
    UserType.F_ADDITIONAL_NAME.getLocalPart(), // changed property
    new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), // changed values
    evaluator.createProtectedString("weighAnch0r"));
    // THEN
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("weighAnch0r"));
    PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("d3adM3nT3llN0Tal3s"));
}
Also used : ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 62 with ItemPath

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

the class TestAbstractAssignmentEvaluator method test130DirectExpressionReplaceDescriptionFromNull.

@Test
public void test130DirectExpressionReplaceDescriptionFromNull() throws Exception {
    final String TEST_NAME = "test130DirectExpressionReplaceDescriptionFromNull";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
    assignmentType.setDescription(null);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    //		// We need to make sure that the assignment has a parent
    //		PrismContainerDefinition<AssignmentType> assignmentContainerDefinition = user.getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT);
    //		PrismContainer<AssignmentType> assignmentContainer = assignmentContainerDefinition.instantiate();
    //		assignmentContainer.add(assignmentType.asPrismContainerValue().clone());
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "sailor");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
    assertEquals(1, construction.getAttributeMappings().size());
    PrismValueDeltaSetTripleProducer<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (PrismValueDeltaSetTripleProducer<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "The best sailor the world has ever seen");
    PrismAsserts.assertTripleMinus(outputTriple, "The best man the world has ever seen");
    // the same using other words
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best sailor the world has ever seen");
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best man the world has ever seen");
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) PrismValueDeltaSetTripleProducer(com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 63 with ItemPath

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

the class Search method createFilterForSearchValue.

private ObjectFilter createFilterForSearchValue(SearchItem item, DisplayableValue searchValue, PrismContext ctx) {
    ItemDefinition definition = item.getDefinition();
    ItemPath path = item.getPath();
    if (definition instanceof PrismReferenceDefinition) {
        return QueryBuilder.queryFor(ObjectType.class, ctx).item(path, definition).ref((PrismReferenceValue) searchValue.getValue()).buildFilter();
    }
    PrismPropertyDefinition propDef = (PrismPropertyDefinition) definition;
    if ((propDef.getAllowedValues() != null && !propDef.getAllowedValues().isEmpty()) || DOMUtil.XSD_BOOLEAN.equals(propDef.getTypeName())) {
        //we're looking for enum value, therefore equals filter is ok
        //or if it's boolean value
        DisplayableValue displayableValue = (DisplayableValue) searchValue.getValue();
        Object value = displayableValue.getValue();
        return QueryBuilder.queryFor(ObjectType.class, ctx).item(path, propDef).eq(value).buildFilter();
    } else if (DOMUtil.XSD_INT.equals(propDef.getTypeName()) || DOMUtil.XSD_INTEGER.equals(propDef.getTypeName()) || DOMUtil.XSD_LONG.equals(propDef.getTypeName()) || DOMUtil.XSD_SHORT.equals(propDef.getTypeName())) {
        String text = (String) searchValue.getValue();
        if (!StringUtils.isNumeric(text) && (searchValue instanceof SearchValue)) {
            ((SearchValue) searchValue).clear();
            return null;
        }
        Object value = Long.parseLong((String) searchValue.getValue());
        return QueryBuilder.queryFor(ObjectType.class, ctx).item(path, propDef).eq(value).buildFilter();
    } else if (DOMUtil.XSD_STRING.equals(propDef.getTypeName())) {
        String text = (String) searchValue.getValue();
        return QueryBuilder.queryFor(ObjectType.class, ctx).item(path, propDef).contains(text).matchingCaseIgnore().buildFilter();
    } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(propDef.getTypeName())) {
        //we're looking for string value, therefore substring filter should be used
        String text = (String) searchValue.getValue();
        PolyStringNormalizer normalizer = ctx.getDefaultPolyStringNormalizer();
        String value = normalizer.normalize(text);
        return QueryBuilder.queryFor(ObjectType.class, ctx).item(path, propDef).contains(text).matchingNorm().buildFilter();
    }
    if (searchValue instanceof SearchValue) {
        ((SearchValue) searchValue).clear();
    }
    return null;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PolyStringNormalizer(com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)

Example 64 with ItemPath

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

the class SearchFactory method createSearch.

public static <T extends ObjectType> Search createSearch(Class<T> type, ResourceShadowDiscriminator discriminator, ModelServiceLocator modelServiceLocator, boolean useDefsFromSuperclass) {
    PrismObjectDefinition objectDef = findObjectDefinition(type, discriminator, modelServiceLocator);
    Map<ItemPath, ItemDefinition> availableDefs = getAvailableDefinitions(objectDef, useDefsFromSuperclass);
    boolean isFullTextSearchEnabled = isFullTextSearchEnabled(modelServiceLocator, type);
    Search search = new Search(type, availableDefs, isFullTextSearchEnabled, getDefaultSearchType(modelServiceLocator, type));
    SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
    PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ObjectType.class);
    PrismPropertyDefinition def = objDef.findPropertyDefinition(ObjectType.F_NAME);
    SearchItem item = search.addItem(def);
    if (item != null) {
        item.setFixed(true);
    }
    return search;
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 65 with ItemPath

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

the class SearchFactory method getAvailableDefinitions.

private static <T extends ObjectType> Map<ItemPath, ItemDefinition> getAvailableDefinitions(PrismObjectDefinition<T> objectDef, boolean useDefsFromSuperclass) {
    Map<ItemPath, ItemDefinition> map = new HashMap<>();
    map.putAll(createExtensionDefinitionList(objectDef));
    Class<T> typeClass = objectDef.getCompileTimeClass();
    while (typeClass != null && !com.evolveum.prism.xml.ns._public.types_3.ObjectType.class.equals(typeClass)) {
        List<ItemPath> paths = SEARCHABLE_OBJECTS.get(typeClass);
        if (paths != null) {
            for (ItemPath path : paths) {
                ItemDefinition def = objectDef.findItemDefinition(path);
                if (def != null) {
                    map.put(path, def);
                }
            }
        }
        if (!useDefsFromSuperclass) {
            break;
        }
        typeClass = (Class<T>) typeClass.getSuperclass();
    }
    return map;
}
Also used : HashMap(java.util.HashMap) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) 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