/** * Find the directory user that corresponds to the given model. * * @param directoryName the name of the directory where to perform the search * @param user the user model * @return the requested directory group or {@code null} if no such group exists */ private DirectoryUser findDirectoryUser(String directoryName, User user) { DirectoryUser result = null; String namespace = user.getNamespace(); if (user.isSetDomainEntryId()) { result = getUserById(directoryName, namespace, user.getDomainEntryId()); } else if (user.isSetId()) { result = getUserById(directoryName, namespace, user.getId()); } else if (user.isSetPrincipal()) { result = getEntity(DirectoryUser.class, QueryType.GetDirectoryUserByPrincipal, new GetDirectoryUserByPrincipalParameters(directoryName, user.getPrincipal()), user.getPrincipal()); } else if (user.isSetUserName()) { result = getEntity( DirectoryUser.class, SearchType.DirectoryUser, getDirectoryUserSearchPattern( AuthzUtils.getEntityNameWithoutAuthz(user.getUserName(), directoryName), user.getNamespace(), directoryName) ); } return result; }
@Mapping(from = User.class, to = DbUser.class) public static DbUser map(User model, DbUser template) { DbUser entity = template != null? template: new DbUser(); if (model.isSetPrincipal()) { entity.setLoginName(model.getPrincipal()); } else if (model.isSetName()) { entity.setLoginName(model.getName()); } if (model.isSetId()) { String id = model.getId(); entity.setId(GuidUtils.asGuid(id)); } if (model.isSetDomain()) { Domain domain = model.getDomain(); if (domain.isSetName()) { entity.setDomain(domain.getName()); } } if (model.isSetDomainEntryId()) { entity.setExternalId(DirectoryEntryIdUtils.decode(model.getDomainEntryId())); } if (model.isSetNamespace()) { entity.setNamespace(model.getNamespace()); } return entity; }
to.setNamespace(from.getNamespace());