use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class UserProfileServiceImpl method findByUsername.
private PrismObject<UserType> findByUsername(String username, OperationResult result) throws SchemaException, ObjectNotFoundException {
PolyString usernamePoly = new PolyString(username);
ObjectQuery query = ObjectQueryUtil.createNormNameQuery(usernamePoly, prismContext);
LOGGER.trace("Looking for user, query:\n" + query.debugDump());
List<PrismObject<UserType>> list = repositoryService.searchObjects(UserType.class, query, null, result);
LOGGER.trace("Users found: {}.", list.size());
if (list.size() != 1) {
return null;
}
return list.get(0);
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestParseDiffPatch method testUserReal.
@Test
public void testUserReal() throws SchemaException, SAXException, IOException, JAXBException {
System.out.println("===[ testUserReal ]===");
String userBeforeXml = MiscUtil.readFile(new File(TEST_DIR, "user-real-before.xml"));
String userAfterXml = MiscUtil.readFile(new File(TEST_DIR, "user-real-after.xml"));
// WHEN
ObjectDelta<UserType> userDelta = DiffUtil.diff(userBeforeXml, userAfterXml, UserType.class, getPrismContext());
// THEN
System.out.println("DELTA:");
System.out.println(userDelta.debugDump());
userDelta.checkConsistence();
assertEquals("Wrong delta OID", "2f9b9299-6f45-498f-bc8e-8d17c6b93b20", userDelta.getOid());
assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
Collection<? extends ItemDelta> modifications = userDelta.getModifications();
assertEquals("Unexpected number of modifications", 4, modifications.size());
PrismAsserts.assertPropertyReplace(userDelta, new QName(SchemaConstants.NS_C, "emailAddress"), "jack@blackpearl.com");
PrismAsserts.assertPropertyReplace(userDelta, new QName(SchemaConstants.NS_C, "locality"), new PolyString("World's End", "worlds end"));
PrismAsserts.assertPropertyReplace(userDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ActivationStatusType.DISABLED);
PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "organizationalUnit"), new PolyString("Brethren of the Coast", "brethren of the coast"));
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestJaxbParsing method testParseUserFromJaxb.
@Test
public void testParseUserFromJaxb() throws SchemaException, SAXException, IOException, JAXBException {
PrismContext prismContext = PrismTestUtil.getPrismContext();
// Try to use the schema to validate Jack
UserType userType = PrismTestUtil.parseObjectable(new File(TestConstants.COMMON_DIR, "user-jack.xml"), UserType.class);
// WHEN
PrismObject<UserType> user = userType.asPrismObject();
user.revive(prismContext);
// THEN
System.out.println("Parsed user:");
System.out.println(user.debugDump());
user.checkConsistence();
assertPropertyValue(user, UserType.F_NAME, PrismTestUtil.createPolyString("jack"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "fullName"), new PolyString("Jack Sparrow", "jack sparrow"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "givenName"), new PolyString("Jack", "jack"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "familyName"), new PolyString("Sparrow", "sparrow"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
assertPropertyValue(user.findContainer(UserType.F_EXTENSION), new QName(NS_FOO, "bar"), "BAR");
PrismProperty<ProtectedStringType> password = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new QName(NS_FOO, "password"));
assertNotNull(password);
// TODO: check inside
assertPropertyValue(user.findOrCreateContainer(UserType.F_EXTENSION), new QName(NS_FOO, "num"), 42);
PrismProperty<?> multi = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new QName(NS_FOO, "multi"));
assertEquals(3, multi.getValues().size());
// WHEN
// Node domNode = user.serializeToDom();
//
// //THEN
// System.out.println("\nSerialized user:");
// System.out.println(DOMUtil.serializeDOMToString(domNode));
//
// Element userEl = DOMUtil.getFirstChildElement(domNode);
// assertEquals(SchemaConstants.I_USER, DOMUtil.getQName(userEl));
// TODO: more asserts
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestMappingTime method testAfterTimeTo.
@Test
public void testAfterTimeTo() throws Exception {
final String TEST_NAME = "testAfterTimeTo";
System.out.println("===[ " + TEST_NAME + "]===");
// GIVEN
ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_EMPLOYEE_TYPE, evaluator.getPrismContext(), "CAPTAIN");
Mapping.Builder<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> builder = evaluator.createMappingBuilder(MAPPING_TIME_FROM_TO_FILENAME, TEST_NAME, "title", delta);
builder.setNow(TIME_FUTURE);
Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = builder.build();
OperationResult opResult = new OperationResult(TEST_NAME);
// WHEN
mapping.evaluate(null, opResult);
// THEN
PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
assertNullTriple(outputTriple);
assertNextRecompute(mapping, null);
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestMappingDynamicSysVar method testEmployeeNumberPolyString.
@Test
public void testEmployeeNumberPolyString() throws Exception {
final String TEST_NAME = "testEmployeeNumberPolyString";
System.out.println("===[ " + TEST_NAME + "]===");
// WHEN
PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = evaluator.evaluateMappingDynamicReplace("mapping-script-system-variables-employee-number.xml", TEST_NAME, // target
"additionalName", // changed property
"employeeNumber", // changed values
"666");
// THEN
PrismAsserts.assertTripleNoZero(outputTriple);
PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("666"));
PrismAsserts.assertTripleNoMinus(outputTriple);
// Make sure it is recomputed
PolyString plusval = outputTriple.getPlusSet().iterator().next().getValue();
System.out.println("Plus polystring\n" + plusval.debugDump());
assertEquals("Wrong norm value", "666", plusval.getNorm());
}
Aggregations