use of org.apache.syncope.common.lib.to.SchemaTO in project syncope by apache.
the class SchemaRestClient method getSchemas.
public <T extends SchemaTO> List<T> getSchemas(final SchemaType schemaType, final AnyTypeKind kind) {
final AnyTypeService client = getService(AnyTypeService.class);
final List<String> classes = new ArrayList<>();
switch(kind) {
case USER:
case GROUP:
final AnyTypeTO type = client.read(kind.name());
if (type != null) {
classes.addAll(type.getClasses());
}
break;
default:
new AnyTypeRestClient().listAnyTypes().stream().filter(anyTypeTO -> (anyTypeTO.getKind() != AnyTypeKind.USER && anyTypeTO.getKind() != AnyTypeKind.GROUP)).forEach((anyTypeTO) -> {
classes.addAll(anyTypeTO.getClasses());
});
}
return getSchemas(schemaType, null, classes.toArray(new String[] {}));
}
use of org.apache.syncope.common.lib.to.SchemaTO in project syncope by apache.
the class SchemaLogic method resolveReference.
@Override
protected SchemaTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof SchemaTO) {
key = ((SchemaTO) args[i]).getKey();
}
}
}
if (key != null) {
try {
SchemaTO result = null;
PlainSchema plainSchema = plainSchemaDAO.find(key);
if (plainSchema == null) {
DerSchema derSchema = derSchemaDAO.find(key);
if (derSchema == null) {
VirSchema virSchema = virSchemaDAO.find(key);
if (virSchema != null) {
result = binder.getVirSchemaTO(virSchema);
}
} else {
result = binder.getDerSchemaTO(derSchema);
}
} else {
result = binder.getPlainSchemaTO(plainSchema);
}
return result;
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
use of org.apache.syncope.common.lib.to.SchemaTO in project syncope by apache.
the class SchemaTypePanel method getColumns.
@Override
protected List<IColumn<SchemaTO, String>> getColumns() {
final List<IColumn<SchemaTO, String>> columns = new ArrayList<>();
for (final String field : COL_NAMES.get(schemaType)) {
final Field clazzField = ReflectionUtils.findField(schemaType.getToClass(), field);
if (clazzField != null) {
if (clazzField.getType().equals(Boolean.class) || clazzField.getType().equals(boolean.class)) {
columns.add(new BooleanPropertyColumn<>(new ResourceModel(field), field, field));
} else {
final IColumn<SchemaTO, String> column = new PropertyColumn<SchemaTO, String>(new ResourceModel(field), field, field) {
private static final long serialVersionUID = 3282547854226892169L;
@Override
public String getCssClass() {
String css = super.getCssClass();
if ("key".equals(field)) {
css = StringUtils.isBlank(css) ? "col-xs-1" : css + " col-xs-1";
}
return css;
}
};
columns.add(column);
}
}
}
return columns;
}
use of org.apache.syncope.common.lib.to.SchemaTO in project syncope by apache.
the class SchemaServiceImpl method create.
@Override
public Response create(final SchemaType schemaType, final SchemaTO schemaTO) {
SchemaTO created = logic.create(schemaType, schemaTO);
URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
use of org.apache.syncope.common.lib.to.SchemaTO in project syncope by apache.
the class SchemaResource method newResourceResponse.
@Override
protected AbstractResource.ResourceResponse newResourceResponse(final IResource.Attributes attributes) {
LOG.debug("Search all {} any type kind related schemas", AnyTypeKind.USER.name());
ResourceResponse response = new AbstractResource.ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN does not match");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
return response;
}
List<String> classes = Collections.emptyList();
String group = attributes.getParameters().get("group").toString();
if (group != null) {
try {
TypeExtensionTO typeExt = SyncopeEnduserSession.get().getService(SyncopeService.class).readUserTypeExtension(group);
classes = typeExt.getAuxClasses();
} catch (Exception e) {
LOG.error("Could not read User type extension for Group {}", group);
}
} else {
String anyTypeClass = attributes.getParameters().get("anyTypeClass").toString();
if (anyTypeClass != null) {
classes = Collections.singletonList(anyTypeClass);
} else {
classes = SyncopeEnduserSession.get().getService(SyncopeService.class).platform().getUserClasses();
}
}
// USER from customization, if empty or null ignore it, use it to filter attributes otherwise
Map<String, CustomAttributesInfo> customForm = SyncopeEnduserApplication.get().getCustomForm();
SchemaService schemaService = SyncopeEnduserSession.get().getService(SchemaService.class);
final List<SchemaTO> plainSchemas = classes.isEmpty() ? Collections.<SchemaTO>emptyList() : customForm == null || customForm.isEmpty() || customForm.get(SchemaType.PLAIN.name()) == null ? schemaService.search(new SchemaQuery.Builder().type(SchemaType.PLAIN).anyTypeClasses(classes).build()) : customForm.get(SchemaType.PLAIN.name()).isShow() ? customizeSchemas(schemaService.search(new SchemaQuery.Builder().type(SchemaType.PLAIN).anyTypeClasses(classes).build()), group, customForm.get(SchemaType.PLAIN.name()).getAttributes()) : Collections.<SchemaTO>emptyList();
final List<SchemaTO> derSchemas = classes.isEmpty() ? Collections.<SchemaTO>emptyList() : customForm == null || customForm.isEmpty() || customForm.get(SchemaType.DERIVED.name()) == null ? schemaService.search(new SchemaQuery.Builder().type(SchemaType.DERIVED).anyTypeClasses(classes).build()) : customForm.get(SchemaType.DERIVED.name()).isShow() ? customizeSchemas(schemaService.search(new SchemaQuery.Builder().type(SchemaType.DERIVED).anyTypeClasses(classes).build()), group, customForm.get(SchemaType.DERIVED.name()).getAttributes()) : Collections.<SchemaTO>emptyList();
final List<SchemaTO> virSchemas = classes.isEmpty() ? Collections.<SchemaTO>emptyList() : customForm == null || customForm.isEmpty() || customForm.get(SchemaType.VIRTUAL.name()) == null ? schemaService.search(new SchemaQuery.Builder().type(SchemaType.VIRTUAL).anyTypeClasses(classes).build()) : customForm.get(SchemaType.VIRTUAL.name()).isShow() ? customizeSchemas(schemaService.search(new SchemaQuery.Builder().type(SchemaType.VIRTUAL).anyTypeClasses(classes).build()), group, customForm.get(SchemaType.VIRTUAL.name()).getAttributes()) : Collections.<SchemaTO>emptyList();
if (group != null) {
plainSchemas.forEach(schema -> {
schema.setKey(compositeSchemaKey(group, schema.getKey()));
});
derSchemas.forEach(schema -> {
schema.setKey(compositeSchemaKey(group, schema.getKey()));
});
virSchemas.forEach(schema -> {
schema.setKey(compositeSchemaKey(group, schema.getKey()));
});
}
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final IResource.Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(new SchemaResponse().plainSchemas(plainSchemas).derSchemas(derSchemas).virSchemas(virSchemas)));
}
});
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving {} any type kind related schemas", AnyTypeKind.USER.name(), e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
}
return response;
}
Aggregations