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