use of org.dcm4che3.json.JSONReader in project dcm4chee-arc-light by dcm4che.
the class QueryServiceImpl method addSOPInstanceRefsFromMetadata.
private static void addSOPInstanceRefsFromMetadata(Sequence refSeriesSeq, String studyUID, String seriesUID, String sopUID, String storageID, String storagePath, StorageCache storageCache) {
Sequence refSOPSeq = null;
Storage storage = storageCache.getStorage(storageID);
try (ZipInputStream seriesMetadataStream = openZipInputStream(storage, storagePath, studyUID)) {
ZipEntry entry;
while ((entry = seriesMetadataStream.getNextEntry()) != null) {
if (sopUID == null || sopUID.equals(entry.getName())) {
JSONReader jsonReader = new JSONReader(Json.createParser(new InputStreamReader(seriesMetadataStream, StandardCharsets.UTF_8)));
jsonReader.setSkipBulkDataURI(true);
Attributes metadata = jsonReader.readDataset(null);
if (refSOPSeq == null) {
Attributes refSeries = new Attributes(2);
refSeries.setString(Tag.SeriesInstanceUID, VR.UI, seriesUID);
refSOPSeq = refSeries.newSequence(Tag.ReferencedSOPSequence, 10);
refSeriesSeq.add(refSeries);
}
Attributes refSOP = new Attributes(4);
refSOP.setString(Tag.RetrieveAETitle, VR.AE, metadata.getString(Tag.RetrieveAETitle));
refSOP.setString(Tag.InstanceAvailability, VR.CS, metadata.getString(Tag.InstanceAvailability));
refSOP.setString(Tag.ReferencedSOPClassUID, VR.UI, metadata.getString(Tag.SOPClassUID));
refSOP.setString(Tag.ReferencedSOPInstanceUID, VR.UI, entry.getName());
refSOPSeq.add(refSOP);
}
seriesMetadataStream.closeEntry();
}
} catch (IOException e) {
throw new RuntimeException("Failed to read Series Metadata " + storagePath + "@" + storage.getStorageDescriptor(), e);
}
}
use of org.dcm4che3.json.JSONReader in project vdmj by nickbattle.
the class RPCTest method testUnknownMethod.
@Test
public void testUnknownMethod() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"wibble\", \"params\": {\"subtrahend\": 23, \"minuend\": 42}, \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
JSONObject error = responses.get(0).get("error");
assertEquals(error.get("code"), new Long(-32601));
}
use of org.dcm4che3.json.JSONReader in project vdmj by nickbattle.
the class RPCTest method test2.
@Test
public void test2() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [ 23, 42 ], \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
d.register(new RPCHandler() {
@Override
public RPCMessageList request(RPCRequest request) throws IOException {
JSONArray params = request.get("params");
Long minuend = params.index(0);
Long subtrahend = params.index(1);
return new RPCMessageList(RPCResponse.result(request, minuend.longValue() - subtrahend.longValue()));
}
@Override
public void response(RPCResponse message) {
}
}, "subtract");
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
assertEquals(new Long(-19), responses.get(0).get("result"));
}
use of org.dcm4che3.json.JSONReader in project vdmj by nickbattle.
the class RPCTest method test1.
@Test
public void test1() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": {\"subtrahend\": 23, \"minuend\": 42}, \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
d.register(new RPCHandler() {
@Override
public RPCMessageList request(RPCRequest request) throws IOException {
JSONObject params = request.get("params");
Long minuend = params.get("minuend");
Long subtrahend = params.get("subtrahend");
return new RPCMessageList(RPCResponse.result(request, minuend.longValue() - subtrahend.longValue()));
}
@Override
public void response(RPCResponse message) {
}
}, "subtract");
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
assertEquals(new Long(19), responses.get(0).get("result"));
}
use of org.dcm4che3.json.JSONReader in project dcm4che by dcm4che.
the class JsonImageReaderConfiguration method loadDeviceExtension.
@Override
public boolean loadDeviceExtension(Device device, JsonReader reader, ConfigurationDelegate config) {
if (!reader.getString().equals("dcmImageReader"))
return false;
ImageReaderFactory factory = new ImageReaderFactory();
reader.next();
reader.expect(JsonParser.Event.START_ARRAY);
while (reader.next() == JsonParser.Event.START_OBJECT) {
String tsuid = null;
String formatName = null;
String className = null;
String patchJPEGLS = null;
String[] imageReadParam = {};
while (reader.next() == JsonParser.Event.KEY_NAME) {
switch(reader.getString()) {
case "dicomTransferSyntax":
tsuid = reader.stringValue();
break;
case "dcmIIOFormatName":
formatName = reader.stringValue();
break;
case "dcmJavaClassName":
className = reader.stringValue();
break;
case "dcmPatchJPEGLS":
patchJPEGLS = reader.stringValue();
break;
case "dcmImageReadParam":
imageReadParam = reader.stringArray();
break;
default:
reader.skipUnknownProperty();
}
}
reader.expect(JsonParser.Event.END_OBJECT);
factory.put(tsuid, new ImageReaderFactory.ImageReaderParam(formatName, className, patchJPEGLS, imageReadParam));
}
device.addDeviceExtension(new ImageReaderExtension(factory));
return true;
}
Aggregations