Search in sources :

Example 6 with UMembership

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

the class UserTest method ships.

@Test
public void ships() {
    User user = userDAO.findByUsername("bellini");
    assertNotNull(user);
    assertEquals(1, user.getMemberships().size());
    assertEquals("bf825fe1-7320-4a54-bd64-143b5c18ab97", user.getMemberships().get(0).getRightEnd().getKey());
    user.getMemberships().remove(0);
    UMembership newM = entityFactory.newEntity(UMembership.class);
    newM.setLeftEnd(user);
    newM.setRightEnd(groupDAO.find("ba9ed509-b1f5-48ab-a334-c8530a6422dc"));
    user.add(newM);
    userDAO.save(user);
    userDAO.flush();
    user = userDAO.findByUsername("bellini");
    assertEquals(1, user.getMemberships().size());
    assertEquals("ba9ed509-b1f5-48ab-a334-c8530a6422dc", user.getMemberships().get(0).getRightEnd().getKey());
    assertEquals(1, user.getRelationships().size());
    assertEquals("fc6dbc3a-6c07-4965-8781-921e7401a4a5", user.getRelationships().get(0).getRightEnd().getKey());
    user.getRelationships().remove(0);
    URelationship newR = entityFactory.newEntity(URelationship.class);
    newR.setType(relationshipTypeDAO.find("neighborhood"));
    newR.setLeftEnd(user);
    newR.setRightEnd(anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8"));
    user.add(newR);
    userDAO.save(user);
    userDAO.flush();
    user = userDAO.findByUsername("bellini");
    assertEquals(1, user.getRelationships().size());
    assertEquals("8559d14d-58c2-46eb-a2d4-a7d35161e8f8", user.getRelationships().get(0).getRightEnd().getKey());
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 7 with UMembership

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

the class NotificationManagerImpl method getRecipientEmail.

private String getRecipientEmail(final String recipientAttrName, final User user) {
    String email = null;
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
        return email;
    }
    if ("username".equals(intAttrName.getField())) {
        email = user.getUsername();
    } else if (intAttrName.getSchemaType() != null) {
        UMembership membership = null;
        if (intAttrName.getMembershipOfGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
            if (group != null) {
                membership = user.getMembership(group.getKey()).orElse(null);
            }
        }
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
                if (attr.isPresent()) {
                    email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
                }
                break;
            case DERIVED:
                DerSchema schema = derSchemaDAO.find(recipientAttrName);
                if (schema == null) {
                    LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
                }
                break;
            case VIRTUAL:
                VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
                if (virSchema == null) {
                    LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
                    email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
                }
                break;
            default:
        }
    }
    return email;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Optional(java.util.Optional) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 8 with UMembership

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

UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)8 URelationship (org.apache.syncope.core.persistence.api.entity.user.URelationship)6 List (java.util.List)4 Group (org.apache.syncope.core.persistence.api.entity.group.Group)4 User (org.apache.syncope.core.persistence.api.entity.user.User)4 RelationshipType (org.apache.syncope.core.persistence.api.entity.RelationshipType)3 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Date (java.util.Date)2 Optional (java.util.Optional)2 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)2 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 Role (org.apache.syncope.core.persistence.api.entity.Role)2 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)2