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