// search user by attributes specified into the policy
NodeCond searchCondition = null;
for (String schema : policySpec.getAlternativeSearchAttrs()) {
Attribute value = extValues.get(schema);
AttributeCond.Type type;
String expression = null;
if (value == null || value.getValue() == null || value.getValue().isEmpty()
|| (value.getValue().size() == 1 && value.getValue().get(0) == null)) {
type = AttributeCond.Type.ISNULL;
} else {
type = AttributeCond.Type.EQ;
expression = value.getValue().size() > 1
? value.getValue().toString()
: value.getValue().get(0).toString();
}
NodeCond nodeCond;
// just Username or SyncopeUserId can be selected to be used
if ("id".equalsIgnoreCase(schema) || "username".equalsIgnoreCase(schema)) {
final SyncopeUserCond cond = new SyncopeUserCond();
cond.setSchema(schema);
cond.setType(type);
cond.setExpression(expression);
nodeCond = NodeCond.getLeafCond(cond);
} else {
final AttributeCond cond = new AttributeCond();
cond.setSchema(schema);
cond.setType(type);
cond.setExpression(expression);
nodeCond = NodeCond.getLeafCond(cond);
}
searchCondition = searchCondition != null
? NodeCond.getAndCond(searchCondition, nodeCond)
: nodeCond;
}
List<SyncopeUser> users = userSearchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
searchCondition);
for (SyncopeUser user : users) {
result.add(user.getId());
}
} else {
final SyncopeUser found;
List<SyncopeUser> users;
final SchemaMapping accountIdMap = SchemaMappingUtil.getAccountIdMapping(syncTask.getResource()
.getMappings());
switch (accountIdMap.getIntMappingType()) {
case Username:
found = userDAO.find(uid);
if (found != null) {
result.add(found.getId());
}
break;
case SyncopeUserId:
found = userDAO.find(Long.parseLong(uid));
if (found != null) {
result.add(found.getId());
}
break;
case UserSchema:
final UAttrValue value = new UAttrValue();
USchema schema = schemaDAO.find(accountIdMap.getIntAttrName(), USchema.class);
if (schema == null) {
value.setStringValue(uid);
} else {
try {
value.parseValue(schema, uid);
} catch (ParsingValidationException e) {
LOG.error("While parsing provided __UID__ {}", uid, e);
value.setStringValue(uid);
}
}
users = userDAO.findByAttrValue(accountIdMap.getIntAttrName(), value);
for (SyncopeUser user : users) {