use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass 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.AnyTypeClass in project syncope by apache.
the class AnyTypeClassLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPECLASS_DELETE + "')")
public AnyTypeClassTO delete(final String key) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(key);
if (anyTypeClass == null) {
LOG.error("Could not find anyTypeClass '" + key + "'");
throw new NotFoundException(key);
}
AnyTypeClassTO deleted = binder.getAnyTypeClassTO(anyTypeClass);
anyTypeClassDAO.delete(key);
return deleted;
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass 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.AnyTypeClass in project syncope by apache.
the class JPADerSchemaDAO method findByAnyTypeClasses.
@Override
public List<DerSchema> findByAnyTypeClasses(final Collection<AnyTypeClass> anyTypeClasses) {
StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPADerSchema.class.getSimpleName()).append(" e WHERE ");
for (AnyTypeClass anyTypeClass : anyTypeClasses) {
queryString.append("e.anyTypeClass.id='").append(anyTypeClass.getKey()).append("' OR ");
}
TypedQuery<DerSchema> query = entityManager().createQuery(queryString.substring(0, queryString.length() - 4), DerSchema.class);
return query.getResultList();
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class AnyTypeClassTest method find.
@Test
public void find() {
AnyTypeClass minimalGroup = anyTypeClassDAO.find("minimal group");
assertNotNull(minimalGroup);
assertFalse(minimalGroup.getPlainSchemas().isEmpty());
assertFalse(minimalGroup.getDerSchemas().isEmpty());
assertFalse(minimalGroup.getVirSchemas().isEmpty());
}
Aggregations