Search in sources :

Example 1 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class DefaultGroupWorkflowAdapter method doCreate.

@Override
protected WorkflowResult<String> doCreate(final GroupTO groupTO) {
    Group group = entityFactory.newEntity(Group.class);
    dataBinder.create(group, groupTO);
    group = groupDAO.save(group);
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.set(ResourceOperation.CREATE, groupDAO.findAllResourceKeys(group.getKey()));
    return new WorkflowResult<>(group.getKey(), propByRes, "create");
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource)

Example 2 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class JPAGroupDAO method save.

@Override
public Group save(final Group group) {
    Group merged = super.save(group);
    publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
    // refresh dynamic memberships
    clearUDynMembers(merged);
    if (merged.getUDynMembership() != null) {
        SearchCond cond = buildDynMembershipCond(merged.getUDynMembership().getFIQLCond(), merged.getRealm());
        int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.USER);
        for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
            List<User> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER);
            matching.forEach(user -> {
                Query insert = entityManager().createNativeQuery("INSERT INTO " + UDYNMEMB_TABLE + " VALUES(?, ?)");
                insert.setParameter(1, user.getKey());
                insert.setParameter(2, merged.getKey());
                insert.executeUpdate();
                publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, user, AuthContextUtils.getDomain()));
            });
        }
    }
    clearADynMembers(merged);
    merged.getADynMemberships().stream().forEach(memb -> {
        SearchCond cond = buildDynMembershipCond(memb.getFIQLCond(), merged.getRealm());
        int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.ANY_OBJECT);
        for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
            List<AnyObject> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT);
            matching.forEach(anyObject -> {
                Query insert = entityManager().createNativeQuery("INSERT INTO " + ADYNMEMB_TABLE + " VALUES(?, ?, ?)");
                insert.setParameter(1, anyObject.getType().getKey());
                insert.setParameter(2, anyObject.getKey());
                insert.setParameter(3, merged.getKey());
                insert.executeUpdate();
                publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, anyObject, AuthContextUtils.getDomain()));
            });
        }
    });
    dynRealmDAO().refreshDynMemberships(merged);
    return merged;
}
Also used : JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond)

Example 3 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class JPAGroupDAO method removeDynMemberships.

@Override
public Set<String> removeDynMemberships(final User user) {
    List<Group> dynGroups = userDAO().findDynGroups(user.getKey());
    Query delete = entityManager().createNativeQuery("DELETE FROM " + UDYNMEMB_TABLE + " WHERE any_id=?");
    delete.setParameter(1, user.getKey());
    delete.executeUpdate();
    Set<String> before = new HashSet<>();
    dynGroups.forEach(group -> {
        before.add(group.getKey());
        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, group, AuthContextUtils.getDomain()));
    });
    return before;
}
Also used : JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) HashSet(java.util.HashSet)

Example 4 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group 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)

Example 5 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class JPAGroupDAO method findUDynMembers.

@Override
@SuppressWarnings("unchecked")
public List<String> findUDynMembers(final Group group) {
    if (group.getUDynMembership() == null) {
        return Collections.emptyList();
    }
    Query query = entityManager().createNativeQuery("SELECT any_id FROM " + UDYNMEMB_TABLE + " WHERE group_id=?");
    query.setParameter(1, group.getKey());
    List<String> result = new ArrayList<>();
    query.getResultList().stream().map(key -> key instanceof Object[] ? (String) ((Object[]) key)[0] : ((String) key)).forEachOrdered(actualKey -> result.add(actualKey.toString()));
    return result;
}
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) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)

Aggregations

Group (org.apache.syncope.core.persistence.api.entity.group.Group)65 User (org.apache.syncope.core.persistence.api.entity.user.User)32 Transactional (org.springframework.transaction.annotation.Transactional)28 List (java.util.List)24 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)24 ArrayList (java.util.ArrayList)20 HashSet (java.util.HashSet)20 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)20 Test (org.junit.jupiter.api.Test)20 Collectors (java.util.stream.Collectors)19 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)17 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)17 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)17 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)17 Collections (java.util.Collections)16 Set (java.util.Set)16 Map (java.util.Map)15 Pair (org.apache.commons.lang3.tuple.Pair)15