Search in sources :

Example 1 with UserDAO

use of org.apache.syncope.core.persistence.api.dao.UserDAO 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 UserDAO

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

the class JPAGroupDAO method delete.

@Override
public void delete(final Group group) {
    dynRealmDAO().removeDynMemberships(group.getKey());
    findAMemberships(group).forEach(membership -> {
        AnyObject leftEnd = membership.getLeftEnd();
        leftEnd.getMemberships().remove(membership);
        membership.setRightEnd(null);
        leftEnd.getPlainAttrs(membership).stream().map(attr -> {
            leftEnd.remove(attr);
            attr.setOwner(null);
            attr.setMembership(null);
            return attr;
        }).forEachOrdered(attr -> plainAttrDAO.delete(attr));
        anyObjectDAO().save(leftEnd);
        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
    });
    findUMemberships(group).forEach(membership -> {
        User leftEnd = membership.getLeftEnd();
        leftEnd.getMemberships().remove(membership);
        membership.setRightEnd(null);
        leftEnd.getPlainAttrs(membership).stream().map(attr -> {
            leftEnd.remove(attr);
            attr.setOwner(null);
            attr.setMembership(null);
            return attr;
        }).forEachOrdered(attr -> plainAttrDAO.delete(attr));
        userDAO().save(leftEnd);
        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
    });
    clearUDynMembers(group);
    clearADynMembers(group);
    entityManager().remove(group);
    publisher.publishEvent(new AnyDeletedEvent(this, AnyTypeKind.GROUP, group.getKey(), AuthContextUtils.getDomain()));
}
Also used : AopUtils(org.springframework.aop.support.AopUtils) 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) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) 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) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) JPATypeExtension(org.apache.syncope.core.persistence.jpa.entity.group.JPATypeExtension) JPAUMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPAUMembership) Repository(org.springframework.stereotype.Repository) JPAADynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAMembership(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAMembership) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Query(javax.persistence.Query) Group(org.apache.syncope.core.persistence.api.entity.group.Group) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) TypedQuery(javax.persistence.TypedQuery) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RealmUtils(org.apache.syncope.core.provisioning.api.utils.RealmUtils) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) JPAUDynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) Transactional(org.springframework.transaction.annotation.Transactional) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User)

Aggregations

Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 StandardEntitlement (org.apache.syncope.common.lib.types.StandardEntitlement)2 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)2 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)2 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)2 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)2 ApplicationContextProvider (org.apache.syncope.core.spring.ApplicationContextProvider)2 AuthContextUtils (org.apache.syncope.core.spring.security.AuthContextUtils)2 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Repository (org.springframework.stereotype.Repository)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1