Search in sources :

Example 1 with JSONReader

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);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) Storage(org.dcm4chee.arc.storage.Storage) InputStreamReader(java.io.InputStreamReader) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JSONReader(org.dcm4che3.json.JSONReader)

Example 2 with JSONReader

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));
}
Also used : JSONWriter(json.JSONWriter) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with JSONReader

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"));
}
Also used : JSONWriter(json.JSONWriter) JSONArray(json.JSONArray) IOException(java.io.IOException) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with JSONReader

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"));
}
Also used : JSONWriter(json.JSONWriter) IOException(java.io.IOException) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with JSONReader

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;
}
Also used : ImageReaderFactory(org.dcm4che3.imageio.codec.ImageReaderFactory) ImageReaderExtension(org.dcm4che3.net.imageio.ImageReaderExtension)

Aggregations

JSONReader (org.dcm4che3.json.JSONReader)10 InputStreamReader (java.io.InputStreamReader)8 IOException (java.io.IOException)5 Attributes (org.dcm4che3.data.Attributes)4 PrintWriter (java.io.PrintWriter)3 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)3 ZipEntry (java.util.zip.ZipEntry)3 ZipInputStream (java.util.zip.ZipInputStream)3 JSONObject (json.JSONObject)3 JSONReader (json.JSONReader)3 JSONWriter (json.JSONWriter)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URLEncoder (java.net.URLEncoder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1