Search in sources :

Example 1 with ADR

use of io.github.adr.embedded.ADR in project winery by eclipse.

the class PropertiesResource method getProperties.

/**
 * Gets the defined properties. If no properties are defined, an empty JSON object is returned. If k/v properties
 * are defined, then a JSON is returned. Otherwise an XML is returned.
 *
 * @return Key/Value map in the case of Winery WPD mode - else instance of XML Element in case of non-key/value
 * properties
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@NonNull
public Response getProperties() {
    TEntityType tempType = RepositoryFactory.getRepository().getTypeForTemplate(this.template);
    WinerysPropertiesDefinition wpd = tempType.getWinerysPropertiesDefinition();
    TEntityTemplate.Properties props = this.template.getProperties();
    if (wpd == null) {
        // These can be null resulting in 200 No Content at the caller
        if (props == null) {
            return Response.ok().entity("{}").type(MediaType.APPLICATION_JSON).build();
        } else {
            @Nullable final Object any = props.getAny();
            if (any == null) {
                LOGGER.debug("XML properties expected, but none found. Returning empty JSON.");
                return Response.ok().entity("{}").type(MediaType.APPLICATION_JSON).build();
            }
            try {
                @ADR(6) String xmlAsString = BackendUtils.getXMLAsString(TEntityTemplate.Properties.class, props, true);
                return Response.ok().entity(xmlAsString).type(MediaType.TEXT_XML).build();
            } catch (Exception e) {
                throw new WebApplicationException(e);
            }
        }
    } else {
        Map<String, String> kvProperties = this.template.getProperties().getKVProperties();
        return Response.ok().entity(kvProperties).type(MediaType.APPLICATION_JSON).build();
    }
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TEntityType(org.eclipse.winery.model.tosca.TEntityType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.kvproperties.WinerysPropertiesDefinition) Nullable(org.eclipse.jdt.annotation.Nullable) ADR(io.github.adr.embedded.ADR) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

ADR (io.github.adr.embedded.ADR)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)1 TEntityType (org.eclipse.winery.model.tosca.TEntityType)1 WinerysPropertiesDefinition (org.eclipse.winery.model.tosca.kvproperties.WinerysPropertiesDefinition)1