Search in sources :

Example 6 with RelationshipType

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

the class RelationshipTypeLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.RELATIONSHIPTYPE_DELETE + "')")
public RelationshipTypeTO delete(final String key) {
    RelationshipType relationshipType = relationshipTypeDAO.find(key);
    if (relationshipType == null) {
        LOG.error("Could not find relationshipType '" + key + "'");
        throw new NotFoundException(key);
    }
    RelationshipTypeTO deleted = binder.getRelationshipTypeTO(relationshipType);
    relationshipTypeDAO.delete(key);
    return deleted;
}
Also used : RelationshipTypeTO(org.apache.syncope.common.lib.to.RelationshipTypeTO) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with RelationshipType

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

the class RelationshipTypeTest method save.

@Test
public void save() {
    RelationshipType newType = entityFactory.newEntity(RelationshipType.class);
    newType.setKey("new type");
    newType.setDescription("description");
    newType = relationshipTypeDAO.save(newType);
    assertNotNull(newType);
    assertEquals("description", newType.getDescription());
}
Also used : RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with RelationshipType

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

the class RelationshipTypeTest method saveInvalidName.

@Test
public void saveInvalidName() {
    assertThrows(InvalidEntityException.class, () -> {
        RelationshipType newType = entityFactory.newEntity(RelationshipType.class);
        newType.setKey("membership");
        relationshipTypeDAO.save(newType);
    });
}
Also used : RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 9 with RelationshipType

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

the class RelationshipTypeLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.RELATIONSHIPTYPE_UPDATE + "')")
public RelationshipTypeTO update(final RelationshipTypeTO relationshipTypeTO) {
    RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTypeTO.getKey());
    if (relationshipType == null) {
        LOG.error("Could not find relationshipType '" + relationshipTypeTO.getKey() + "'");
        throw new NotFoundException(relationshipTypeTO.getKey());
    }
    binder.update(relationshipType, relationshipTypeTO);
    relationshipType = relationshipTypeDAO.save(relationshipType);
    return binder.getRelationshipTypeTO(relationshipType);
}
Also used : RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with RelationshipType

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

RelationshipType (org.apache.syncope.core.persistence.api.entity.RelationshipType)13 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)5 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)5 Test (org.junit.jupiter.api.Test)5 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 Group (org.apache.syncope.core.persistence.api.entity.group.Group)4 Collection (java.util.Collection)3 List (java.util.List)3 AMembership (org.apache.syncope.core.persistence.api.entity.anyobject.AMembership)3 ARelationship (org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship)3 UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)3 URelationship (org.apache.syncope.core.persistence.api.entity.user.URelationship)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2