Search in sources :

Example 1 with AttributeSet

use of org.dcm4chee.arc.conf.AttributeSet in project dcm4chee-arc-light by dcm4che.

the class QueryAttributeSets method listAttributeSets.

@GET
@NoCache
@Path("/{type}")
@Produces("application/json")
public Response listAttributeSets(@PathParam("type") String type) {
    logRequest();
    try {
        ArchiveDeviceExtension arcDev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
        final AttributeSet.Type attrSetType = AttributeSet.Type.valueOf(type);
        return Response.ok((StreamingOutput) out -> {
            JsonGenerator gen = Json.createGenerator(out);
            gen.writeStartArray();
            for (AttributeSet attrSet : sortedAttributeSets(arcDev.getAttributeSet(attrSetType))) {
                JsonWriter writer = new JsonWriter(gen);
                gen.writeStartObject();
                writer.writeNotNullOrDef("type", attrSet.getType().name(), null);
                writer.writeNotNullOrDef("id", attrSet.getID(), null);
                writer.writeNotNullOrDef("description", attrSet.getDescription(), null);
                writer.writeNotNullOrDef("title", attrSet.getTitle(), null);
                attrSet.getProperties().forEach((key, value) -> writer.writeNotNullOrDef(key, value, null));
                gen.writeEnd();
            }
            gen.writeEnd();
            gen.flush();
        }).build();
    } catch (IllegalStateException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (IllegalArgumentException e) {
        return errResponse("Attribute Set of type : " + type + " not found.", Response.Status.NOT_FOUND);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) AttributeSet(org.dcm4chee.arc.conf.AttributeSet) JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) JsonWriter(org.dcm4che3.conf.json.JsonWriter) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

JsonGenerator (javax.json.stream.JsonGenerator)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 JsonWriter (org.dcm4che3.conf.json.JsonWriter)1 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)1 AttributeSet (org.dcm4chee.arc.conf.AttributeSet)1 NoCache (org.jboss.resteasy.annotations.cache.NoCache)1