Search in sources :

Example 1 with Relationship

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

the class JPARelationshipTypeDAO method delete.

@Override
public void delete(final String key) {
    RelationshipType type = find(key);
    if (type == null) {
        return;
    }
    findRelationshipsByType(type).stream().map(relationship -> {
        if (relationship instanceof URelationship) {
            ((URelationship) relationship).getLeftEnd().getRelationships().remove((URelationship) relationship);
        } else if (relationship instanceof UMembership) {
            ((UMembership) relationship).getLeftEnd().getMemberships().remove((UMembership) relationship);
        } else if (relationship instanceof ARelationship) {
            ((ARelationship) relationship).getLeftEnd().getRelationships().remove((ARelationship) relationship);
        } else if (relationship instanceof AMembership) {
            ((AMembership) relationship).getLeftEnd().getMemberships().remove((AMembership) relationship);
        }
        relationship.setLeftEnd(null);
        return relationship;
    }).forEachOrdered(relationship -> entityManager().remove(relationship));
    entityManager().remove(type);
}
Also used : RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) Collection(java.util.Collection) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) List(java.util.List) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) Relationship(org.apache.syncope.core.persistence.api.entity.Relationship) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship) JPARelationshipType(org.apache.syncope.core.persistence.jpa.entity.JPARelationshipType) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) Repository(org.springframework.stereotype.Repository) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) JPARelationshipType(org.apache.syncope.core.persistence.jpa.entity.JPARelationshipType) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 TypedQuery (javax.persistence.TypedQuery)1 RelationshipTypeDAO (org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO)1 Relationship (org.apache.syncope.core.persistence.api.entity.Relationship)1 RelationshipType (org.apache.syncope.core.persistence.api.entity.RelationshipType)1 AMembership (org.apache.syncope.core.persistence.api.entity.anyobject.AMembership)1 ARelationship (org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship)1 UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)1 URelationship (org.apache.syncope.core.persistence.api.entity.user.URelationship)1 JPARelationshipType (org.apache.syncope.core.persistence.jpa.entity.JPARelationshipType)1 JPAARelationship (org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship)1 JPAURelationship (org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship)1 Repository (org.springframework.stereotype.Repository)1