Search in sources :

Example 1 with JsonProperty

use of org.codehaus.jackson.annotate.JsonProperty in project openhab1-addons by openhab.

the class SystemsResponse method getOperational_at.

/**
     * "operational_at": 1304566098
     */
@JsonProperty("operational_at")
public Calendar getOperational_at() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(this.operational_at * 1000);
    return calendar;
}
Also used : Calendar(java.util.Calendar) JsonProperty(org.codehaus.jackson.annotate.JsonProperty)

Example 2 with JsonProperty

use of org.codehaus.jackson.annotate.JsonProperty in project oxTrust by GluuFederation.

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<SchemaAttribute>();
        // 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<SchemaAttribute>());
                // 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(org.gluu.oxtrust.model.scim2.Meta) JsonProperty(org.codehaus.jackson.annotate.JsonProperty) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) Schema(org.gluu.oxtrust.model.scim2.annotations.Schema) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) NullType(javax.lang.model.type.NullType) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) SchemaResource(org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)

Example 3 with JsonProperty

use of org.codehaus.jackson.annotate.JsonProperty in project openhab1-addons by openhab.

the class SystemsResponse method getLast_report_at.

/**
     * "last_report_at": 1424743838
     */
@JsonProperty("last_report_at")
public Calendar getLast_report_at() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(this.last_report_at * 1000);
    return calendar;
}
Also used : Calendar(java.util.Calendar) JsonProperty(org.codehaus.jackson.annotate.JsonProperty)

Example 4 with JsonProperty

use of org.codehaus.jackson.annotate.JsonProperty in project openhab1-addons by openhab.

the class SystemsResponse method getSummary_date.

/**
     * "summary_date": "2015-02-23"
     */
@JsonProperty("summary_date")
public Calendar getSummary_date() {
    final SimpleDateFormat format = new SimpleDateFormat(enphaseDateFormatString);
    Calendar calendar = Calendar.getInstance();
    try {
        Date date = format.parse(this.summary_date);
        calendar.setTime(date);
    } catch (ParseException e) {
        logger.debug("summary_date {} has an unknown format", this.summary_date);
    }
    return calendar;
}
Also used : Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JsonProperty(org.codehaus.jackson.annotate.JsonProperty)

Aggregations

JsonProperty (org.codehaus.jackson.annotate.JsonProperty)4 Calendar (java.util.Calendar)3 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 NullType (javax.lang.model.type.NullType)1 Meta (org.gluu.oxtrust.model.scim2.Meta)1 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)1 Schema (org.gluu.oxtrust.model.scim2.annotations.Schema)1 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)1 SchemaAttribute (org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute)1 SchemaResource (org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)1