Search in sources :

Example 1 with GroupDAO

use of org.apache.syncope.core.persistence.api.dao.GroupDAO in project syncope by apache.

the class JPAExternalResourceDAO method delete.

@Override
public void delete(final String name) {
    ExternalResource resource = find(name);
    if (resource == null) {
        return;
    }
    taskDAO().deleteAll(resource, TaskType.PROPAGATION);
    taskDAO().deleteAll(resource, TaskType.PULL);
    taskDAO().deleteAll(resource, TaskType.PUSH);
    realmDAO().findByResource(resource).forEach(realm -> realm.getResources().remove(resource));
    anyObjectDAO().findByResource(resource).forEach(anyObject -> anyObject.getResources().remove(resource));
    userDAO().findByResource(resource).forEach(user -> user.getResources().remove(resource));
    groupDAO().findByResource(resource).forEach(group -> group.getResources().remove(resource));
    policyDAO().findByResource(resource).forEach(policy -> policy.getResources().remove(resource));
    resource.getProvisions().stream().filter(provision -> provision.getMapping() != null).peek(provision -> provision.getMapping().getItems().forEach(item -> item.setMapping(null))).peek(provision -> {
        provision.getMapping().getItems().clear();
        provision.setMapping(null);
        provision.setResource(null);
    }).forEachOrdered(provision -> virSchemaDAO().findByProvision(provision).forEach(schema -> virSchemaDAO().delete(schema.getKey())));
    externalResourceHistoryConfDAO().deleteByEntity(resource);
    if (resource.getConnector() != null && resource.getConnector().getResources() != null && !resource.getConnector().getResources().isEmpty()) {
        resource.getConnector().getResources().remove(resource);
    }
    resource.setConnector(null);
    entityManager().remove(resource);
}
Also used : JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) JPAExternalResource(org.apache.syncope.core.persistence.jpa.entity.resource.JPAExternalResource) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) ConnectorRegistry(org.apache.syncope.core.provisioning.api.ConnectorRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) TypedQuery(javax.persistence.TypedQuery) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) JPAProvision(org.apache.syncope.core.persistence.jpa.entity.resource.JPAProvision) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Repository(org.springframework.stereotype.Repository) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAMapping(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMapping) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) Set(java.util.Set) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) ExternalResourceHistoryConfDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceHistoryConfDAO) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) JPAExternalResource(org.apache.syncope.core.persistence.jpa.entity.resource.JPAExternalResource) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Example 2 with GroupDAO

use of org.apache.syncope.core.persistence.api.dao.GroupDAO in project syncope by apache.

the class JPAAnyObjectDAO method findDynGroups.

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final String key) {
    Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.ADYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, key);
    List<Group> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
        Group group = groupDAO().find(actualKey.toString());
        if (group == null) {
            LOG.error("Could not find group with id {}, even though returned by the native query", actualKey);
        } else if (!result.contains(group)) {
            result.add(group);
        }
    });
    return result;
}
Also used : Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) TypedQuery(javax.persistence.TypedQuery) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Repository(org.springframework.stereotype.Repository) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) Set(java.util.Set) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) Collectors(java.util.stream.Collectors) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) Relationship(org.apache.syncope.core.persistence.api.entity.Relationship) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with GroupDAO

use of org.apache.syncope.core.persistence.api.dao.GroupDAO in project syncope by apache.

the class JPAUserDAO method findDynGroups.

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final String key) {
    Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.UDYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, key);
    List<Group> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
        Group group = groupDAO().find(actualKey.toString());
        if (group == null) {
            LOG.error("Could not find group with id {}, even though returned by the native query", actualKey);
        } else if (!result.contains(group)) {
            result.add(group);
        }
    });
    return result;
}
Also used : AccountRule(org.apache.syncope.core.persistence.api.dao.AccountRule) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) JPAUser(org.apache.syncope.core.persistence.jpa.entity.user.JPAUser) Repository(org.springframework.stereotype.Repository) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) Role(org.apache.syncope.core.persistence.api.entity.Role) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) AccountPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.AccountPolicyException) Collectors(java.util.stream.Collectors) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) List(java.util.List) Query(javax.persistence.Query) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.PasswordPolicyException) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) TypedQuery(javax.persistence.TypedQuery) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Propagation(org.springframework.transaction.annotation.Propagation) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) PasswordRule(org.apache.syncope.core.persistence.api.dao.PasswordRule) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)3 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)3 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)3 ApplicationContextProvider (org.apache.syncope.core.spring.ApplicationContextProvider)3 AuthContextUtils (org.apache.syncope.core.spring.security.AuthContextUtils)3 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)3 Repository (org.springframework.stereotype.Repository)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Date (java.util.Date)2 Map (java.util.Map)2 NoResultException (javax.persistence.NoResultException)2