Search in sources :

Example 6 with PolyString

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 7 with PolyString

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"));
}
Also used : QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with PolyString

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
}
Also used : QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 9 with PolyString

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);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 10 with PolyString

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());
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8