Search in sources :

Example 21 with JsonGenerator

use of javax.json.stream.JsonGenerator in project dcm4chee-arc-light by dcm4che.

the class StudyMgtRS method updateSeries.

@PUT
@Path("/studies/{study}/series/{series}")
@Consumes("application/dicom+json,application/json")
@Produces("application/json")
public StreamingOutput updateSeries(@PathParam("study") String studyUID, @PathParam("series") String seriesUID, InputStream in) {
    logRequest();
    ArchiveAEExtension arcAE = getArchiveAE();
    final Attributes attrs = toAttributes(in);
    IDWithIssuer patientID = IDWithIssuer.pidOf(attrs);
    if (patientID == null || !attrs.containsValue(Tag.SeriesInstanceUID))
        throw new WebApplicationException(errResponse("Missing Patient ID or Series Instance UID in request payload", Response.Status.BAD_REQUEST));
    if (!seriesUID.equals(attrs.getString(Tag.SeriesInstanceUID)))
        throw new WebApplicationException(errResponse("Series UID in request does not match Series UID in request payload", Response.Status.BAD_REQUEST));
    Patient patient = patientService.findPatient(patientID);
    if (patient == null)
        throw new WebApplicationException(errResponse("Patient[id=" + patientID + "] does not exist.", Response.Status.NOT_FOUND));
    try {
        StudyMgtContext ctx = studyService.createStudyMgtContextWEB(HttpServletRequestInfo.valueOf(request), arcAE.getApplicationEntity());
        ctx.setPatient(patient);
        ctx.setAttributes(attrs);
        ctx.setStudyInstanceUID(studyUID);
        ctx.setSeriesInstanceUID(seriesUID);
        studyService.updateSeries(ctx);
        rsForward.forward(RSOperation.UpdateSeries, arcAE, attrs, request);
        return out -> {
            try (JsonGenerator gen = Json.createGenerator(out)) {
                arcAE.encodeAsJSONNumber(new JSONWriter(gen)).write(attrs);
            }
        };
    } catch (StudyMissingException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.NOT_FOUND));
    } catch (PatientMismatchException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.BAD_REQUEST));
    } catch (Exception e) {
        throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) Attributes(org.dcm4che3.data.Attributes) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyMgtContext(org.dcm4chee.arc.study.StudyMgtContext) Inject(javax.inject.Inject) RSOperation(org.dcm4chee.arc.conf.RSOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONWriter(org.dcm4che3.json.JSONWriter) JSONReader(org.dcm4che3.json.JSONReader) InvokeValidate(org.dcm4chee.arc.validation.constraints.InvokeValidate) Json(javax.json.Json) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) DeletionService(org.dcm4chee.arc.delete.DeletionService) RSForward(org.dcm4chee.arc.rs.client.RSForward) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) PrintWriter(java.io.PrintWriter) Patient(org.dcm4chee.arc.entity.Patient) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) StringWriter(java.io.StringWriter) ValidValueOf(org.dcm4chee.arc.validation.constraints.ValidValueOf) StudyService(org.dcm4chee.arc.study.StudyService) StreamingOutput(javax.ws.rs.core.StreamingOutput) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) Device(org.dcm4che3.net.Device) DateTimeParseException(java.time.format.DateTimeParseException) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Tag(org.dcm4che3.data.Tag) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) RequestScoped(javax.enterprise.context.RequestScoped) IDWithIssuer(org.dcm4che3.data.IDWithIssuer) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Pattern(javax.validation.constraints.Pattern) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) UriInfo(javax.ws.rs.core.UriInfo) JsonParsingException(javax.json.stream.JsonParsingException) org.dcm4chee.arc.patient(org.dcm4chee.arc.patient) InputStream(java.io.InputStream) JSONWriter(org.dcm4che3.json.JSONWriter) IDWithIssuer(org.dcm4che3.data.IDWithIssuer) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyMgtContext(org.dcm4chee.arc.study.StudyMgtContext) Attributes(org.dcm4che3.data.Attributes) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) Patient(org.dcm4chee.arc.entity.Patient) JsonGenerator(javax.json.stream.JsonGenerator) NoResultException(javax.persistence.NoResultException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) DateTimeParseException(java.time.format.DateTimeParseException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) JsonParsingException(javax.json.stream.JsonParsingException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException)

Example 22 with JsonGenerator

use of javax.json.stream.JsonGenerator in project dcm4chee-arc-light by dcm4che.

the class SyslogSearchRS method writeTo.

private void writeTo(Response response, OutputStream out) {
    JsonGenerator gen = Json.createGenerator(out);
    gen.writeStartArray();
    // TODO
    gen.writeEnd();
    gen.flush();
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator)

Example 23 with JsonGenerator

use of javax.json.stream.JsonGenerator in project dcm4chee-arc-light by dcm4che.

the class ImportImpaxReportRS method buildResponse.

private Response buildResponse(List<String> xmlReports, Attributes response, ApplicationEntity ae) {
    Response.Status status = !response.contains(Tag.ReferencedSOPSequence) ? Response.Status.CONFLICT : !xmlReports.isEmpty() && !response.contains(Tag.FailedSOPSequence) ? Response.Status.OK : Response.Status.ACCEPTED;
    return Response.status(status).entity((StreamingOutput) out -> {
        JsonGenerator gen = Json.createGenerator(out);
        ae.getAEExtensionNotNull(ArchiveAEExtension.class).encodeAsJSONNumber(new JSONWriter(gen)).write(response);
        gen.flush();
    }).build();
}
Also used : Response(javax.ws.rs.core.Response) JSONWriter(org.dcm4che3.json.JSONWriter) JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 24 with JsonGenerator

use of javax.json.stream.JsonGenerator in project dcm4chee-arc-light by dcm4che.

the class IDGeneratorRS method nextVal.

@POST
@Path("/{name}/nextval")
public Response nextVal(@PathParam("name") String idGeneratorName) {
    logRequest();
    try {
        return Response.ok((StreamingOutput) out -> {
            JsonGenerator gen = Json.createGenerator(out);
            gen.writeStartObject();
            gen.write(idGeneratorName, idService.createID(idGeneratorName));
            gen.writeEnd();
            gen.flush();
        }).build();
    } catch (IllegalArgumentException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 25 with JsonGenerator

use of javax.json.stream.JsonGenerator in project dcm4chee-arc-light by dcm4che.

the class QueryIDGenerators method query.

@GET
@NoCache
@Produces("application/json")
public Response query() {
    logRequest();
    try {
        return Response.ok((StreamingOutput) out -> {
            JsonGenerator gen = Json.createGenerator(out);
            gen.writeStartObject();
            Set<String> idGenerators = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class).getIDGenerators().keySet();
            if (!idGenerators.isEmpty()) {
                gen.writeStartArray("ID Generators");
                idGenerators.stream().map(Object::toString).forEach(gen::write);
                gen.writeEnd();
            }
            gen.writeEnd();
            gen.flush();
        }).build();
    } catch (IllegalStateException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

JsonGenerator (javax.json.stream.JsonGenerator)82 StreamingOutput (javax.ws.rs.core.StreamingOutput)23 StringWriter (java.io.StringWriter)21 NoCache (org.jboss.resteasy.annotations.cache.NoCache)19 JsonWriter (org.dcm4che3.conf.json.JsonWriter)13 JSONWriter (org.dcm4che3.json.JSONWriter)13 HashMap (java.util.HashMap)10 JsonGeneratorFactory (javax.json.stream.JsonGeneratorFactory)9 JsonParsingException (javax.json.stream.JsonParsingException)9 IOException (java.io.IOException)7 PrintWriter (java.io.PrintWriter)7 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 Test (org.junit.Test)7 Json (javax.json.Json)6 Attributes (org.dcm4che3.data.Attributes)6 RequestScoped (javax.enterprise.context.RequestScoped)5 Inject (javax.inject.Inject)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Pattern (javax.validation.constraints.Pattern)5