use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final Membership membership, final MembershipTO membershipTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
membershipTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema != null) {
GroupablePlainAttr attr = (GroupablePlainAttr) GroupableRelatable.class.cast(any).getPlainAttr(schema.getKey(), membership).orElse(null);
if (attr == null) {
attr = anyUtils.newPlainAttr();
attr.setOwner(any);
attr.setMembership(membership);
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);
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class AbstractAnyDataBinder method checkMandatoryOnResources.
private SyncopeClientException checkMandatoryOnResources(final Any<?> any, final Collection<? extends ExternalResource> resources) {
SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
resources.forEach(resource -> {
Optional<? extends Provision> provision = resource.getProvision(any.getType());
if (resource.isEnforceMandatoryCondition() && provision.isPresent()) {
List<String> missingAttrNames = evaluateMandatoryCondition(provision.get(), any);
if (!missingAttrNames.isEmpty()) {
LOG.error("Mandatory schemas {} not provided with values", missingAttrNames);
reqValMissing.getElements().addAll(missingAttrNames);
}
}
});
return reqValMissing;
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- VIRTUAL -----------------
private VirSchema fill(final VirSchema schema, final VirSchemaTO schemaTO) {
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
if (schemaTO.getAnyTypeClass() != null && (schema.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(schema.getAnyTypeClass().getKey()))) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
if (anyTypeClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
} else {
anyTypeClass.add(schema);
schema.setAnyTypeClass(anyTypeClass);
}
} else if (schemaTO.getAnyTypeClass() == null && schema.getAnyTypeClass() != null) {
schema.getAnyTypeClass().getVirSchemas().remove(schema);
schema.setAnyTypeClass(null);
}
ExternalResource resource = resourceDAO.find(schemaTO.getResource());
if (resource == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("Resource " + schemaTO.getResource() + " not found");
throw sce;
}
AnyType anyType = anyTypeDAO.find(schemaTO.getAnyType());
if (anyType == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("AnyType " + schemaTO.getAnyType() + " not found");
throw sce;
}
Provision provision = resource.getProvision(anyType).orElse(null);
if (provision == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("Provision for AnyType" + schemaTO.getAnyType() + " not found in " + schemaTO.getResource());
throw sce;
}
schema.setProvision(provision);
return virSchemaDAO.save(schema);
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class SchemaDataBinderImpl method update.
@Override
public PlainSchema update(final PlainSchemaTO schemaTO, final PlainSchema schema) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
boolean hasAttrs = false;
for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind);
hasAttrs |= plainSchemaDAO.findAttrs(schema, anyUtils.plainAttrClass()).isEmpty();
}
if (hasAttrs) {
if (schema.getType() != schemaTO.getType()) {
SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
e.getElements().add("Cannot change type since " + schema.getKey() + " has attributes");
scce.addException(e);
}
if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) {
SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
e.getElements().add("Cannot alter unique contraint since " + schema.getKey() + " has attributes");
scce.addException(e);
}
}
if (scce.hasExceptions()) {
throw scce;
}
return fill(schema, schemaTO);
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- PLAIN -----------------
private PlainSchema fill(final PlainSchema schema, final PlainSchemaTO schemaTO) {
if (!JexlUtils.isExpressionValid(schemaTO.getMandatoryCondition())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidValues);
sce.getElements().add(schemaTO.getMandatoryCondition());
throw sce;
}
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
if (schemaTO.getValidator() == null) {
schema.setValidator(null);
} else {
Implementation validator = implementationDAO.find(schemaTO.getValidator());
if (validator == null) {
LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", schemaTO.getValidator());
} else {
schema.setValidator(validator);
}
}
PlainSchema merged = plainSchemaDAO.save(schema);
if (schemaTO.getAnyTypeClass() != null && (merged.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(merged.getAnyTypeClass().getKey()))) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
if (anyTypeClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
} else {
anyTypeClass.add(merged);
merged.setAnyTypeClass(anyTypeClass);
}
} else if (schemaTO.getAnyTypeClass() == null && merged.getAnyTypeClass() != null) {
merged.getAnyTypeClass().getPlainSchemas().remove(merged);
merged.setAnyTypeClass(null);
}
return merged;
}
Aggregations