use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPAUserDAO method countByRealm.
@Override
public Map<String, Integer> countByRealm() {
Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM " + JPAUser.class.getSimpleName() + " e GROUP BY e.realm");
@SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
return results.stream().collect(Collectors.toMap(result -> ((Realm) result[0]).getFullPath(), result -> ((Number) result[1]).intValue()));
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPARealmDAO method findSamePolicyChildren.
private <T extends Policy> List<Realm> findSamePolicyChildren(final Realm realm, final T policy) {
List<Realm> result = new ArrayList<>();
for (Realm child : findChildren(realm)) {
if ((policy instanceof AccountPolicy && child.getAccountPolicy() == null || policy.equals(child.getAccountPolicy())) || (policy instanceof PasswordPolicy && child.getPasswordPolicy() == null || policy.equals(child.getPasswordPolicy()))) {
result.add(child);
result.addAll(findSamePolicyChildren(child, policy));
}
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPARealmDAO method delete.
@Override
public void delete(final String key) {
Realm realm = find(key);
if (realm == null) {
return;
}
delete(realm);
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPARealmDAO method findByFullPath.
@Transactional(readOnly = true)
@Override
public Realm findByFullPath(final String fullPath) {
if (SyncopeConstants.ROOT_REALM.equals(fullPath)) {
return getRoot();
}
if (StringUtils.isBlank(fullPath) || !PATH_PATTERN.matcher(fullPath).matches()) {
throw new MalformedPathException(fullPath);
}
Realm root = getRoot();
if (root == null) {
return null;
}
Realm current = root;
for (final String pathElement : fullPath.substring(1).split("/")) {
Optional<Realm> first = findChildren(current).stream().filter(realm -> pathElement.equals(realm.getName())).findFirst();
if (first.isPresent()) {
current = first.get();
} else {
return null;
}
}
return current;
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPARealmDAO method findDescendants.
private void findDescendants(final List<Realm> result, final Realm realm) {
result.add(realm);
List<Realm> children = findChildren(realm);
if (children != null) {
for (Realm child : children) {
findDescendants(result, child);
}
}
}
Aggregations