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