Search in sources :

Example 1 with MalformedPathException

use of org.apache.syncope.core.persistence.api.dao.MalformedPathException 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;
}
Also used : SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) NoResultException(javax.persistence.NoResultException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Autowired(org.springframework.beans.factory.annotation.Autowired) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm) TypedQuery(javax.persistence.TypedQuery) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) ArrayList(java.util.ArrayList) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) MalformedPathException(org.apache.syncope.core.persistence.api.dao.MalformedPathException) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Optional(java.util.Optional) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) Repository(org.springframework.stereotype.Repository) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) MalformedPathException(org.apache.syncope.core.persistence.api.dao.MalformedPathException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 NoResultException (javax.persistence.NoResultException)1 TypedQuery (javax.persistence.TypedQuery)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)1 MalformedPathException (org.apache.syncope.core.persistence.api.dao.MalformedPathException)1 RealmDAO (org.apache.syncope.core.persistence.api.dao.RealmDAO)1 RoleDAO (org.apache.syncope.core.persistence.api.dao.RoleDAO)1 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)1 Realm (org.apache.syncope.core.persistence.api.entity.Realm)1 AccountPolicy (org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy)1 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)1 Policy (org.apache.syncope.core.persistence.api.entity.policy.Policy)1 PullPolicy (org.apache.syncope.core.persistence.api.entity.policy.PullPolicy)1 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)1 JPARealm (org.apache.syncope.core.persistence.jpa.entity.JPARealm)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1