use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
// 0. aux classes
any.getAuxClasses().clear();
anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
} else {
any.add(auxClass);
}
});
// 1. attributes
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema != null) {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
attr.setSchema(schema);
}
fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
if (attr.getValuesAsStrings().isEmpty()) {
attr.setOwner(null);
} else {
any.add(attr);
}
}
});
if (!invalidValues.isEmpty()) {
scce.addException(invalidValues);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
// 2. resources
anyTO.getResources().forEach(resourceKey -> {
ExternalResource resource = resourceDAO.find(resourceKey);
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
} else {
any.add(resource);
}
});
requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class AbstractAnyDataBinder method checkMandatory.
private SyncopeClientException checkMandatory(final Any<?> any, final AnyUtils anyUtils) {
SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
// Check if there is some mandatory schema defined for which no value has been provided
AllowedSchemas<PlainSchema> allowedPlainSchemas = anyUtils.getAllowedSchemas(any, PlainSchema.class);
allowedPlainSchemas.getForSelf().forEach(schema -> {
checkMandatory(schema, any.getPlainAttr(schema.getKey()).orElse(null), any, reqValMissing);
});
if (any instanceof GroupableRelatable) {
allowedPlainSchemas.getForMemberships().forEach((group, schemas) -> {
GroupableRelatable<?, ?, ?, ?, ?> groupable = GroupableRelatable.class.cast(any);
Membership<?> membership = groupable.getMembership(group.getKey()).orElse(null);
schemas.forEach(schema -> {
checkMandatory(schema, groupable.getPlainAttr(schema.getKey(), membership).orElse(null), any, reqValMissing);
});
});
}
return reqValMissing;
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class SchemaLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) {
if (StringUtils.isBlank(schemaTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add("Schema key");
throw sce;
}
if (doesSchemaExist(schemaType, schemaTO.getKey())) {
throw new DuplicateException(schemaType + "/" + schemaTO.getKey());
}
T created;
switch(schemaType) {
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO));
created = (T) binder.getVirSchemaTO(virSchema);
break;
case DERIVED:
DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO));
created = (T) binder.getDerSchemaTO(derSchema);
break;
case PLAIN:
default:
PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO));
created = (T) binder.getPlainSchemaTO(plainSchema);
}
return created;
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class SchemaLogic method search.
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public <T extends SchemaTO> List<T> search(final SchemaType schemaType, final List<String> anyTypeClasses, final String keyword) {
List<AnyTypeClass> classes = new ArrayList<>(anyTypeClasses == null ? 0 : anyTypeClasses.size());
if (anyTypeClasses != null) {
anyTypeClasses.remove(AnyTypeKind.USER.name());
anyTypeClasses.remove(AnyTypeKind.GROUP.name());
anyTypeClasses.forEach(anyTypeClass -> {
AnyTypeClass clazz = anyTypeClassDAO.find(anyTypeClass);
if (clazz == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), anyTypeClass);
} else {
classes.add(clazz);
}
});
}
List<T> result;
switch(schemaType) {
case VIRTUAL:
result = (classes.isEmpty() ? keyword == null ? virSchemaDAO.findAll() : virSchemaDAO.findByKeyword(keyword) : virSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<VirSchema, T>() {
@Override
public T apply(final VirSchema schema) {
return (T) binder.getVirSchemaTO(schema);
}
}).collect(Collectors.toList());
break;
case DERIVED:
result = (classes.isEmpty() ? keyword == null ? derSchemaDAO.findAll() : derSchemaDAO.findByKeyword(keyword) : derSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<DerSchema, T>() {
@Override
public T apply(final DerSchema schema) {
return (T) binder.getDerSchemaTO(schema);
}
}).collect(Collectors.toList());
break;
case PLAIN:
default:
result = (classes.isEmpty() ? keyword == null ? plainSchemaDAO.findAll() : plainSchemaDAO.findByKeyword(keyword) : plainSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<PlainSchema, T>() {
@Override
public T apply(final PlainSchema schema) {
return (T) binder.getPlainSchemaTO(schema);
}
}).collect(Collectors.toList());
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class JPAAnyTypeClassDAO method delete.
@Override
public void delete(final String key) {
AnyTypeClass anyTypeClass = find(key);
if (anyTypeClass == null) {
return;
}
for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) {
type.getClasses().remove(anyTypeClass);
}
for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) {
typeExt.getAuxClasses().remove(anyTypeClass);
if (typeExt.getAuxClasses().isEmpty()) {
typeExt.getGroup().getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) {
provision.getAuxClasses().remove(anyTypeClass);
}
entityManager().remove(anyTypeClass);
}
Aggregations