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