use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class JPAVirSchemaDAO method findByAnyTypeClasses.
@Override
public List<VirSchema> findByAnyTypeClasses(final Collection<AnyTypeClass> anyTypeClasses) {
StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPAVirSchema.class.getSimpleName()).append(" e WHERE ");
for (AnyTypeClass anyTypeClass : anyTypeClasses) {
queryString.append("e.anyTypeClass.id='").append(anyTypeClass.getKey()).append("' OR ");
}
TypedQuery<VirSchema> query = entityManager().createQuery(queryString.substring(0, queryString.length() - 4), VirSchema.class);
return query.getResultList();
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class JPAPlainSchemaDAO method findByAnyTypeClasses.
@Override
public List<PlainSchema> findByAnyTypeClasses(final Collection<AnyTypeClass> anyTypeClasses) {
StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPAPlainSchema.class.getSimpleName()).append(" e WHERE ");
for (AnyTypeClass anyTypeClass : anyTypeClasses) {
queryString.append("e.anyTypeClass.id='").append(anyTypeClass.getKey()).append("' OR ");
}
TypedQuery<PlainSchema> query = entityManager().createQuery(queryString.substring(0, queryString.length() - 4), PlainSchema.class);
return query.getResultList();
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected PropagationByResource fill(final Any any, final AnyPatch anyPatch, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
PropagationByResource propByRes = new PropagationByResource();
// 1. anyTypeClasses
for (StringPatchItem patch : anyPatch.getAuxClasses()) {
AnyTypeClass auxClass = anyTypeClassDAO.find(patch.getValue());
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", patch.getValue());
} else {
switch(patch.getOperation()) {
case ADD_REPLACE:
any.add(auxClass);
break;
case DELETE:
default:
any.getAuxClasses().remove(auxClass);
}
}
}
// 2. resources
for (StringPatchItem patch : anyPatch.getResources()) {
ExternalResource resource = resourceDAO.find(patch.getValue());
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", patch.getValue());
} else {
switch(patch.getOperation()) {
case ADD_REPLACE:
propByRes.add(ResourceOperation.CREATE, resource.getKey());
any.add(resource);
break;
case DELETE:
default:
propByRes.add(ResourceOperation.DELETE, resource.getKey());
any.getResources().remove(resource);
}
}
}
Set<ExternalResource> resources = anyUtils.getAllResources(any);
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
// 3. plain attributes
anyPatch.getPlainAttrs().stream().filter(patch -> patch.getAttrTO() != null).forEach(patch -> {
PlainSchema schema = getPlainSchema(patch.getAttrTO().getSchema());
if (schema == null) {
LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...", patch.getAttrTO().getSchema());
} else {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
LOG.debug("No plain attribute found for schema {}", schema);
if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
attr.setSchema(schema);
any.add(attr);
}
}
if (attr != null) {
processAttrPatch(any, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
}
}
});
if (!invalidValues.isEmpty()) {
scce.addException(invalidValues);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
requiredValuesMissing = checkMandatoryOnResources(any, resources);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
return propByRes;
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass 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.core.persistence.api.entity.AnyTypeClass 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