Search in sources :

Example 1 with SchemaTypeLoadingFactory

use of org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory in project oxTrust by GluuFederation.

the class SchemaWebService method listSchemas.

/**
     * Retrieves the complete schema.
     *
     * @param authorization
     * @return
     * @throws Exception
     */
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listSchemas(@HeaderParam("Authorization") String authorization) throws Exception {
    log.info(" listSchemas() ");
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    List<SchemaType> schemaTypes = SchemaTypeMapping.getSchemaInstances();
    List<Resource> resources = new ArrayList<Resource>();
    SchemaTypeLoadingFactory factory = new SchemaTypeLoadingFactory();
    for (SchemaType schemaType : schemaTypes) {
        factory.load(appConfiguration, schemaType);
        resources.add(schemaType);
    }
    listResponse.setResources(resources);
    listResponse.setTotalResults(schemaTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas");
    // Serialize to JSON
    String json = serialize(listResponse);
    return Response.ok(json).location(location).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) SchemaTypeLoadingFactory(org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) URI(java.net.URI) SchemaType(org.gluu.oxtrust.model.scim2.schema.SchemaType) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with SchemaTypeLoadingFactory

use of org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory in project oxTrust by GluuFederation.

the class SchemaWebService method getSchemaById.

/**
     * Retrieves a schema via its id/urn.
     *
     * @param authorization
     * @param id
     * @return
     * @throws Exception
     */
@GET
@Path("{id}")
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getSchemaById(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
    log.info(" getSchemaById(), id = '" + id + "'");
    SchemaTypeLoadingFactory factory = new SchemaTypeLoadingFactory();
    SchemaType schemaType = factory.load(appConfiguration, id);
    if (schemaType == null) {
        log.info(" NOT FOUND: schema with id = '" + id + "'");
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + id);
    // Serialize to JSON
    String json = serialize(schemaType);
    return Response.ok(json).location(location).build();
}
Also used : SchemaTypeLoadingFactory(org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory) URI(java.net.URI) SchemaType(org.gluu.oxtrust.model.scim2.schema.SchemaType) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

URI (java.net.URI)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 HeaderParam (javax.ws.rs.HeaderParam)2 Produces (javax.ws.rs.Produces)2 SchemaType (org.gluu.oxtrust.model.scim2.schema.SchemaType)2 SchemaTypeLoadingFactory (org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory)2 ArrayList (java.util.ArrayList)1 Path (javax.ws.rs.Path)1 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)1 Resource (org.gluu.oxtrust.model.scim2.Resource)1