use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class DerSchemaTest method findByName.
@Test
public void findByName() {
DerSchema attributeSchema = derSchemaDAO.find("cn");
assertNotNull(attributeSchema);
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class DerSchemaTest method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
DerSchema schema = entityFactory.newEntity(DerSchema.class);
schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
try {
derSchemaDAO.save(schema);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
}
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema 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.DerSchema in project syncope by apache.
the class AnyTypeClassDataBinderImpl method update.
@Override
public void update(final AnyTypeClass anyTypeClass, final AnyTypeClassTO anyTypeClassTO) {
if (anyTypeClass.getKey() == null) {
anyTypeClass.setKey(anyTypeClassTO.getKey());
}
plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getPlainSchemas().clear();
anyTypeClassTO.getPlainSchemas().forEach(schemaName -> {
PlainSchema schema = plainSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach((schema) -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getDerSchemas().clear();
anyTypeClassTO.getDerSchemas().forEach(schemaName -> {
DerSchema schema = derSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + DerSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getVirSchemas().clear();
anyTypeClassTO.getVirSchemas().forEach(schemaName -> {
VirSchema schema = virSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + VirSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class DerAttrHandlerImpl method getValues.
private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) {
Map<DerSchema, String> result = new HashMap<>(schemas.size());
for (DerSchema schema : schemas) {
JexlContext jexlContext = new MapContext();
JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
JexlUtils.addFieldsToContext(any, jexlContext);
result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext));
}
return result;
}
Aggregations