Search in sources :

Example 1 with AnyCreatedUpdatedEvent

use of org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent in project syncope by apache.

the class JPADynRealmDAO method save.

@Override
public DynRealm save(final DynRealm dynRealm) {
    DynRealm merged = entityManager().merge(dynRealm);
    // refresh dynamic memberships
    clearDynMembers(merged);
    merged.getDynMemberships().stream().map(memb -> jpaAnySearchDAO().search(SearchCondConverter.convert(memb.getFIQLCond()), memb.getAnyType().getKind())).forEachOrdered(matching -> {
        matching.forEach(any -> {
            Query insert = entityManager().createNativeQuery("INSERT INTO " + DYNMEMB_TABLE + " VALUES(?, ?)");
            insert.setParameter(1, any.getKey());
            insert.setParameter(2, merged.getKey());
            insert.executeUpdate();
            publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, any, AuthContextUtils.getDomain()));
        });
    });
    return merged;
}
Also used : DynRealmDAO(org.apache.syncope.core.persistence.api.dao.DynRealmDAO) JPADynRealm(org.apache.syncope.core.persistence.jpa.entity.JPADynRealm) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) AopUtils(org.springframework.aop.support.AopUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) TypedQuery(javax.persistence.TypedQuery) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) List(java.util.List) Query(javax.persistence.Query) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Optional(java.util.Optional) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Repository(org.springframework.stereotype.Repository) Any(org.apache.syncope.core.persistence.api.entity.Any) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) Transactional(org.springframework.transaction.annotation.Transactional) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) JPADynRealm(org.apache.syncope.core.persistence.jpa.entity.JPADynRealm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Example 2 with AnyCreatedUpdatedEvent

use of org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent 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

List (java.util.List)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 AnySearchDAO (org.apache.syncope.core.persistence.api.dao.AnySearchDAO)2 SearchCondConverter (org.apache.syncope.core.persistence.api.search.SearchCondConverter)2 AnyCreatedUpdatedEvent (org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent)2 ApplicationContextProvider (org.apache.syncope.core.spring.ApplicationContextProvider)2 AuthContextUtils (org.apache.syncope.core.spring.security.AuthContextUtils)2 AopUtils (org.springframework.aop.support.AopUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)2 Repository (org.springframework.stereotype.Repository)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1