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();
}
}
Aggregations