Search in sources :

Example 1 with SchemaTO

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[] {}));
}
Also used : AnyTypeService(org.apache.syncope.common.rest.api.service.AnyTypeService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SchemaService(org.apache.syncope.common.rest.api.service.SchemaService) SchemaType(org.apache.syncope.common.lib.types.SchemaType) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) List(java.util.List) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) EntityTO(org.apache.syncope.common.lib.to.EntityTO) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) SchemaQuery(org.apache.syncope.common.rest.api.beans.SchemaQuery) Collections(java.util.Collections) AnyTypeService(org.apache.syncope.common.rest.api.service.AnyTypeService) ArrayList(java.util.ArrayList) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO)

Example 2 with SchemaTO

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();
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 3 with SchemaTO

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;
}
Also used : Field(java.lang.reflect.Field) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) BooleanPropertyColumn(org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.BooleanPropertyColumn) PropertyColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn) ArrayList(java.util.ArrayList) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) ResourceModel(org.apache.wicket.model.ResourceModel)

Example 4 with SchemaTO

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();
}
Also used : SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) URI(java.net.URI)

Example 5 with SchemaTO

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;
}
Also used : AbstractResource(org.apache.wicket.request.resource.AbstractResource) IOException(java.io.IOException) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) SyncopeService(org.apache.syncope.common.rest.api.service.SyncopeService) SchemaService(org.apache.syncope.common.rest.api.service.SchemaService) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) SchemaResponse(org.apache.syncope.client.enduser.model.SchemaResponse) CustomAttributesInfo(org.apache.syncope.client.enduser.model.CustomAttributesInfo) IResource(org.apache.wicket.request.resource.IResource)

Aggregations

SchemaTO (org.apache.syncope.common.lib.to.SchemaTO)5 ArrayList (java.util.ArrayList)2 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)2 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)2 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)2 SchemaService (org.apache.syncope.common.rest.api.service.SchemaService)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 StringUtils (org.apache.commons.lang3.StringUtils)1 BooleanPropertyColumn (org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.BooleanPropertyColumn)1 CustomAttributesInfo (org.apache.syncope.client.enduser.model.CustomAttributesInfo)1 SchemaResponse (org.apache.syncope.client.enduser.model.SchemaResponse)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)1 EntityTO (org.apache.syncope.common.lib.to.EntityTO)1