Search in sources :

Example 31 with Meta

use of io.jans.scim.model.scim2.Meta in project jans by JanssenProject.

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz) throws Exception {
    SchemaResource resource;
    Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
    Schema annotation = ScimResourceUtil.getSchemaAnnotation(clazz);
    if (!clazz.equals(schemaCls) && annotation != null) {
        Meta meta = new Meta();
        meta.setResourceType(ScimResourceUtil.getType(schemaCls));
        meta.setLocation(endpointUrl + "/" + annotation.id());
        resource = new SchemaResource();
        resource.setId(annotation.id());
        resource.setName(annotation.name());
        resource.setDescription(annotation.description());
        resource.setMeta(meta);
        List<SchemaAttribute> attribs = new ArrayList<>();
        // paths are, happily alphabetically sorted :)
        for (String path : IntrospectUtil.allAttrs.get(clazz)) {
            SchemaAttribute schAttr = new SchemaAttribute();
            Field f = IntrospectUtil.findFieldFromPath(clazz, path);
            Attribute attrAnnot = f.getAnnotation(Attribute.class);
            if (attrAnnot != null) {
                JsonProperty jsonAnnot = f.getAnnotation(JsonProperty.class);
                schAttr.setName(jsonAnnot == null ? f.getName() : jsonAnnot.value());
                schAttr.setType(attrAnnot.type().getName());
                schAttr.setMultiValued(!attrAnnot.multiValueClass().equals(NullType.class) || IntrospectUtil.isCollection(f.getType()));
                schAttr.setDescription(attrAnnot.description());
                schAttr.setRequired(attrAnnot.isRequired());
                schAttr.setCanonicalValues(attrAnnot.canonicalValues().length == 0 ? null : Arrays.asList(attrAnnot.canonicalValues()));
                schAttr.setCaseExact(attrAnnot.isCaseExact());
                schAttr.setMutability(attrAnnot.mutability().getName());
                schAttr.setReturned(attrAnnot.returned().getName());
                schAttr.setUniqueness(attrAnnot.uniqueness().getName());
                schAttr.setReferenceTypes(attrAnnot.referenceTypes().length == 0 ? null : Arrays.asList(attrAnnot.referenceTypes()));
                if (attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX))
                    schAttr.setSubAttributes(new ArrayList<>());
                // root list
                List<SchemaAttribute> list = attribs;
                String[] parts = path.split("\\.");
                for (int i = 0; i < parts.length - 1; i++) {
                    // skip last part (real attribute name)
                    int j = list.indexOf(new SchemaAttribute(parts[i]));
                    list = list.get(j).getSubAttributes();
                }
                list.add(schAttr);
            }
        }
        resource.setAttributes(attribs);
    } else
        resource = null;
    return resource;
}
Also used : Meta(io.jans.scim.model.scim2.Meta) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Attribute(io.jans.scim.model.scim2.annotations.Attribute) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) Schema(io.jans.scim.model.scim2.annotations.Schema) ArrayList(java.util.ArrayList) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) NullType(javax.lang.model.type.NullType) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource)

Aggregations

Meta (org.gluu.oxtrust.model.scim2.Meta)20 ArrayList (java.util.ArrayList)9 Meta (io.jans.scim.model.scim2.Meta)8 DefaultValue (javax.ws.rs.DefaultValue)7 GET (javax.ws.rs.GET)7 HeaderParam (javax.ws.rs.HeaderParam)7 Produces (javax.ws.rs.Produces)7 URI (java.net.URI)5 Date (java.util.Date)4 Path (javax.ws.rs.Path)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)4 UserResource (io.jans.scim.model.scim2.user.UserResource)3 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashSet (java.util.HashSet)3 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)3 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)3 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3 GluuGroup (org.gluu.oxtrust.model.GluuGroup)3