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;
}
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());
}
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);
});
}
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);
}
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);
}
Aggregations