}
private SchemaMapping getSchemaMapping(ExternalResource resource, SchemaMappingTO mappingTO)
throws SyncopeClientCompositeErrorException {
SyncopeClientCompositeErrorException compositeErrorException = new SyncopeClientCompositeErrorException(
HttpStatus.BAD_REQUEST);
SyncopeClientException requiredValuesMissing = new SyncopeClientException(
SyncopeClientExceptionType.RequiredValuesMissing);
// this control needs to be free to get schema names
// without a complete/good resourceTO object
if (mappingTO == null || mappingTO.getIntMappingType() == null) {
LOG.error("Null mappingTO provided");
return null;
}
if (mappingTO.getIntAttrName() == null) {
switch (mappingTO.getIntMappingType()) {
case SyncopeUserId:
mappingTO.setIntAttrName(IntMappingType.SyncopeUserId.toString());
break;
case Password:
mappingTO.setIntAttrName(IntMappingType.Password.toString());
break;
case Username:
mappingTO.setIntAttrName(IntMappingType.Username.toString());
break;
default:
requiredValuesMissing.addElement("intAttrName");
}
}
// Throw composite exception if there is at least one element set
// in the composing exceptions
if (!requiredValuesMissing.isEmpty()) {
compositeErrorException.addException(requiredValuesMissing);
}
// no mandatory condition implies mandatory condition false
if (!jexlUtil.isExpressionValid(mappingTO.getMandatoryCondition() != null
? mappingTO.getMandatoryCondition()
: "false")) {
SyncopeClientException invalidMandatoryCondition = new SyncopeClientException(
SyncopeClientExceptionType.InvalidValues);
invalidMandatoryCondition.addElement(mappingTO.getMandatoryCondition());
compositeErrorException.addException(invalidMandatoryCondition);
}
if (compositeErrorException.hasExceptions()) {
throw compositeErrorException;
}
SchemaMapping mapping = new SchemaMapping();