use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- DERIVED -----------------
private DerSchema fill(final DerSchema schema, final DerSchemaTO schemaTO) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
if (StringUtils.isBlank(schemaTO.getExpression())) {
SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
requiredValuesMissing.getElements().add("expression");
scce.addException(requiredValuesMissing);
} else if (!JexlUtils.isExpressionValid(schemaTO.getExpression())) {
SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidValues);
e.getElements().add(schemaTO.getExpression());
scce.addException(e);
}
if (scce.hasExceptions()) {
throw scce;
}
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
DerSchema merged = derSchemaDAO.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().getDerSchemas().remove(merged);
merged.setAnyTypeClass(null);
}
return merged;
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema 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.DerSchema 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.DerSchema 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);
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class AbstractAnyDAO method findByDerAttrValue.
@Override
public List<A> findByDerAttrValue(final String schemaKey, final String value) {
DerSchema schema = derSchemaDAO().find(schemaKey);
if (schema == null) {
LOG.error("Invalid schema name '{}'", schemaKey);
return Collections.<A>emptyList();
}
// query string
StringBuilder querystring = new StringBuilder();
boolean subquery = false;
for (String clause : getWhereClause(schema.getExpression(), value)) {
if (querystring.length() > 0) {
subquery = true;
querystring.append(" AND a.owner_id IN ( ");
}
querystring.append("SELECT a.owner_id ").append("FROM ").append(anyUtils().plainAttrClass().getSimpleName().substring(3)).append(" a, ").append(anyUtils().plainAttrValueClass().getSimpleName().substring(3)).append(" v, ").append(PlainSchema.class.getSimpleName()).append(" s ").append("WHERE ").append(clause);
if (subquery) {
querystring.append(')');
}
}
List<A> result = new ArrayList<>();
if (querystring.length() > 0) {
Query query = entityManager().createNativeQuery(querystring.toString());
for (Object anyKey : query.getResultList()) {
A any = find(anyKey.toString());
if (!result.contains(any)) {
result.add(any);
}
}
}
return result;
}
Aggregations