Search in sources :

Example 21 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class BasicExpressionFunctions method composeDn.

/**
     * Creates a valid LDAP distinguished name from the wide range of components. The method
     * can be invoked in many ways, e.g.:
     * 
     * composeDn("cn","foo","o","bar")
	 * composeDn("cn","foo",new Rdn("o","bar"))
     * composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar"))
     * composeDn(new Rdn("cn","foo"),"ou","baz","o","bar")
	 * composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar"))
     * composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
     * 
     * Note: the DN is not normalized. The case of the attribute names and white spaces are
     * preserved.
     */
public static String composeDn(Object... components) throws InvalidNameException {
    if (components == null) {
        return null;
    }
    if (components.length == 0) {
        return null;
    }
    if (components.length == 1 && components[0] == null) {
        return null;
    }
    if (components.length == 1 && (components[0] instanceof String) && StringUtils.isBlank((String) (components[0]))) {
        return null;
    }
    LinkedList<Rdn> rdns = new LinkedList<>();
    String attrName = null;
    for (Object component : components) {
        if (attrName != null && !(component instanceof String || component instanceof PolyString || component instanceof PolyStringType)) {
            throw new InvalidNameException("Invalid input to composeDn() function: expected string after '" + attrName + "' argument, but got " + component.getClass());
        }
        if (component instanceof Rdn) {
            rdns.addFirst((Rdn) component);
        } else if (component instanceof PolyString) {
            component = ((PolyString) component).toString();
        } else if (component instanceof PolyStringType) {
            component = ((PolyStringType) component).toString();
        }
        if (component instanceof String) {
            if (attrName == null) {
                attrName = (String) component;
            } else {
                rdns.addFirst(new Rdn(attrName, (String) component));
                attrName = null;
            }
        }
        if (component instanceof LdapName) {
            rdns.addAll(0, ((LdapName) component).getRdns());
        }
    }
    LdapName dn = new LdapName(rdns);
    return dn.toString();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) InvalidNameException(javax.naming.InvalidNameException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Rdn(javax.naming.ldap.Rdn) LinkedList(java.util.LinkedList) LdapName(javax.naming.ldap.LdapName)

Example 22 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class BasicExpressionFunctions method stringify.

/**
	 * Converts whatever it gets to a string. But it does it in a sensitive way.
	 * E.g. it tries to detect collections and returns the first element (if there is only one). 
	 * Never returns null. Returns empty string instead. 
	 */
public String stringify(Object whatever) {
    if (whatever == null) {
        return "";
    }
    if (whatever instanceof String) {
        return (String) whatever;
    }
    if (whatever instanceof PolyString) {
        return ((PolyString) whatever).getOrig();
    }
    if (whatever instanceof PolyStringType) {
        return ((PolyStringType) whatever).getOrig();
    }
    if (whatever instanceof Collection) {
        Collection collection = (Collection) whatever;
        if (collection.isEmpty()) {
            return "";
        }
        if (collection.size() > 1) {
            throw new IllegalArgumentException("Cannot stringify collection because it has " + collection.size() + " values");
        }
        whatever = collection.iterator().next();
    }
    Class<? extends Object> whateverClass = whatever.getClass();
    if (whateverClass.isArray()) {
        Object[] array = (Object[]) whatever;
        if (array.length == 0) {
            return "";
        }
        if (array.length > 1) {
            throw new IllegalArgumentException("Cannot stringify array because it has " + array.length + " values");
        }
        whatever = array[0];
    }
    if (whatever == null) {
        return "";
    }
    if (whatever instanceof String) {
        return (String) whatever;
    }
    if (whatever instanceof PolyString) {
        return ((PolyString) whatever).getOrig();
    }
    if (whatever instanceof PolyStringType) {
        return ((PolyStringType) whatever).getOrig();
    }
    if (whatever instanceof Element) {
        Element element = (Element) whatever;
        Element origElement = DOMUtil.getChildElement(element, PolyString.F_ORIG);
        if (origElement != null) {
            // This is most likely a PolyStringType
            return origElement.getTextContent();
        } else {
            return element.getTextContent();
        }
    }
    if (whatever instanceof Node) {
        return ((Node) whatever).getTextContent();
    }
    return whatever.toString();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Collection(java.util.Collection) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 23 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestCorrelationConfiramtionEvaluator method test004CorrelationMatchCaseInsensitive.

@Test
public void test004CorrelationMatchCaseInsensitive() throws Exception {
    String TEST_NAME = "test004CorrelationMatchCaseInsensitive";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = task.getResult();
    //		importObjectFromFile(USER_JACK_FILENAME);
    PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
    //assert jack
    assertNotNull(userType);
    ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
    ConditionalSearchFilterType query = PrismTestUtil.parseAtomicValue(new File(CORRELATION_CASE_INSENSITIVE), ConditionalSearchFilterType.COMPLEX_TYPE);
    //		List<QueryType> queries = new ArrayList<QueryType>();
    //		queries.add(query);
    //		
    ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
    resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().clear();
    resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().add(query);
    userType.asObjectable().setName(new PolyStringType("JACK"));
    ObjectSynchronizationType objectSynchronizationType = resourceType.getSynchronization().getObjectSynchronization().get(0);
    try {
        boolean matchedUsers = evaluator.matchUserCorrelationRule(UserType.class, shadow.asPrismObject(), userType, objectSynchronizationType, resourceType, getSystemConfiguration(), task, result);
        System.out.println("matched users " + matchedUsers);
        AssertJUnit.assertTrue(matchedUsers);
    } catch (Exception ex) {
        LOGGER.error("exception occured: {}", ex.getMessage(), ex);
        throw ex;
    }
//		assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
//		assertEquals("Found more than one user.", 1, matchedUsers.size());
//		
//		PrismObject<UserType> jack = matchedUsers.get(0);
//		assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "jack", "Jack Sparrow", "Jack", "Sparrow");
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 24 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestCorrelationConfiramtionEvaluator method test006CorrelationFindCaseInsensitive.

@Test
public void test006CorrelationFindCaseInsensitive() throws Exception {
    String TEST_NAME = "test006CorrelationFindCaseInsensitive";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = task.getResult();
    //		importObjectFromFile(USER_JACK_FILENAME);
    PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
    //assert jack
    assertNotNull(userType);
    ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
    ConditionalSearchFilterType query = PrismTestUtil.parseAtomicValue(new File(CORRELATION_CASE_INSENSITIVE), ConditionalSearchFilterType.COMPLEX_TYPE);
    List<ConditionalSearchFilterType> queries = new ArrayList<>();
    queries.add(query);
    //		
    ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
    //		resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().add(query);
    userType.asObjectable().setName(new PolyStringType("JACK"));
    Collection<? extends ItemDelta> modifications = PropertyDelta.createModificationReplacePropertyCollection(UserType.F_NAME, userType.getDefinition(), new PolyString("JACK", "jack"));
    repositoryService.modifyObject(UserType.class, USER_JACK_OID, modifications, result);
    List<PrismObject<UserType>> matchedUsers = evaluator.findFocusesByCorrelationRule(UserType.class, shadow, queries, resourceType, getSystemConfiguration(), task, result);
    System.out.println("matched users " + matchedUsers);
    assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
    assertEquals("Found more than one user.", 1, matchedUsers.size());
    PrismObject<UserType> jack = matchedUsers.get(0);
    assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "JACK", "Jack Sparrow", "Jack", "Sparrow");
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 25 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestIteration method assertUserNick.

private void assertUserNick(String accountName, String accountFullName, String expectedUserName, String expectedLocality) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<UserType> user = findUserByUsername(expectedUserName);
    assertNotNull("No user for " + accountName + " (" + expectedUserName + ")", user);
    display("Created user for " + accountName, user);
    assertEquals("Wrong nickname in user created for " + accountName, accountFullName, user.asObjectable().getNickName().getOrig());
    assertEquals("Wrong additionalName in user created for " + accountName, accountName, user.asObjectable().getAdditionalName().getOrig());
    PolyStringType locality = user.asObjectable().getLocality();
    if (locality == null) {
        assertEquals("Wrong locality in user created for " + accountName, expectedLocality, null);
    } else {
        assertEquals("Wrong locality in user created for " + accountName, expectedLocality, locality.getOrig());
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4