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"));
}
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());
}
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;
}
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;
}
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;
}
Aggregations