Search in sources :

Example 16 with JSONReader

use of org.dcm4che3.json.JSONReader in project dcm4chee-arc-light by dcm4che.

the class StoreServiceEJB method restoreInstances.

private void restoreInstances(StoreSession session, Series series, String studyUID, Duration duration, List<Instance> instList) throws DicomServiceException {
    if (series == null || series.getInstancePurgeState() == Series.InstancePurgeState.NO)
        return;
    LOG.info("Restore Instance records of Series[pk={}]", series.getPk());
    Metadata metadata = series.getMetadata();
    try (ZipInputStream zip = session.getStoreService().openZipInputStream(session, metadata.getStorageID(), metadata.getStoragePath(), studyUID)) {
        ZipEntry entry;
        while ((entry = zip.getNextEntry()) != null) {
            JSONReader jsonReader = new JSONReader(Json.createParser(new InputStreamReader(zip, StandardCharsets.UTF_8)));
            jsonReader.setSkipBulkDataURI(true);
            Instance inst = restoreInstance(session, series, jsonReader.readDataset(null));
            if (instList != null)
                instList.add(inst);
        }
    } catch (IOException e) {
        LOG.warn("Failed to restore Instance records of Series[pk={}]", series.getPk(), e);
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
    series.setInstancePurgeState(Series.InstancePurgeState.NO);
    series.scheduleInstancePurge(duration);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStreamReader(java.io.InputStreamReader) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JSONReader(org.dcm4che3.json.JSONReader) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 17 with JSONReader

use of org.dcm4che3.json.JSONReader in project dcm4chee-arc-light by dcm4che.

the class PurgeStorageScheduler method instancesNotStoredOnOtherStorage.

private static int instancesNotStoredOnOtherStorage(ReadContext ctx, String storageID, String[] exportStorageID) {
    int count = 0;
    LOG.debug("Read Metadata {} from {}", ctx.getStoragePath(), ctx.getStorage().getStorageDescriptor());
    try (InputStream in = ctx.getStorage().openInputStream(ctx)) {
        ZipInputStream zip = new ZipInputStream(in);
        while (zip.getNextEntry() != null) {
            JSONReader jsonReader = new JSONReader(Json.createParser(new InputStreamReader(zip, "UTF-8")));
            Attributes metadata = jsonReader.readDataset(null);
            if (containsStorageID(metadata, PurgeStorageScheduler::matchStorageID, storageID) && !containsStorageID(metadata, PurgeStorageScheduler::matchStorageIDAndCheckStatus, exportStorageID))
                count++;
            zip.closeEntry();
        }
    } catch (Exception e) {
        LOG.error("Failed to read Metadata {} from {}", ctx.getStoragePath(), ctx.getStorage().getStorageDescriptor());
        count++;
    }
    return count;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStreamReader(java.io.InputStreamReader) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Attributes(org.dcm4che3.data.Attributes) JSONReader(org.dcm4che3.json.JSONReader) IOException(java.io.IOException)

Example 18 with JSONReader

use of org.dcm4che3.json.JSONReader in project Weasis by nroduit.

the class RsQueryResult method parseJSON.

public static List<Attributes> parseJSON(String url, AuthMethod authMethod, URLParameters urlParameters) throws Exception {
    List<Attributes> items = new ArrayList<>();
    try (HttpResponse response = NetworkUtil.getHttpResponse(url, urlParameters, authMethod);
        InputStreamReader instream = new InputStreamReader(response.getInputStream(), StandardCharsets.UTF_8)) {
        int code = response.getResponseCode();
        if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_PARTIAL) {
            JSONReader reader = new JSONReader(Json.createParser(instream));
            Callback callback = (fmi, dataset) -> items.add(dataset);
            reader.readDatasets(callback);
        }
        if (code == HttpURLConnection.HTTP_ENTITY_TOO_LARGE) {
            throw new IllegalStateException("The size of the results exceeds the maximum payload size supported by the origin server.");
        } else if (authMethod != null && code == HttpURLConnection.HTTP_UNAUTHORIZED) {
            authMethod.resetToken();
            authMethod.getToken();
        }
    }
    return items;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BundleTools(org.weasis.core.api.service.BundleTools) DicomModel(org.weasis.dicom.explorer.DicomModel) Attributes(org.dcm4che3.data.Attributes) Series(org.weasis.core.api.media.data.Series) Date(java.util.Date) TagW(org.weasis.core.api.media.data.TagW) LoggerFactory(org.slf4j.LoggerFactory) URLParameters(org.weasis.core.api.util.URLParameters) StringUtil(org.weasis.core.util.StringUtil) HttpResponse(org.weasis.core.api.util.HttpResponse) ArrayList(java.util.ArrayList) Callback(org.dcm4che3.json.JSONReader.Callback) MediaSeriesGroup(org.weasis.core.api.media.data.MediaSeriesGroup) PatientComparator(org.weasis.dicom.codec.utils.PatientComparator) DownloadPriority(org.weasis.dicom.explorer.wado.DownloadPriority) AbstractQueryResult(org.weasis.dicom.mf.AbstractQueryResult) Json(javax.json.Json) JSONReader(org.dcm4che3.json.JSONReader) MediaSeriesGroupNode(org.weasis.core.api.media.data.MediaSeriesGroupNode) Level(org.weasis.dicom.codec.TagD.Level) LinkedHashSet(java.util.LinkedHashSet) SopInstance(org.weasis.dicom.mf.SopInstance) LangUtil(org.weasis.core.util.LangUtil) SeriesDownloadPrefView(org.weasis.dicom.explorer.pref.download.SeriesDownloadPrefView) Logger(org.slf4j.Logger) DicomSeries(org.weasis.dicom.codec.DicomSeries) LoadSeries(org.weasis.dicom.explorer.wado.LoadSeries) NetworkUtil(org.weasis.core.api.util.NetworkUtil) Set(java.util.Set) SeriesInstanceList(org.weasis.dicom.explorer.wado.SeriesInstanceList) DateUtil(org.weasis.dicom.util.DateUtil) WadoParameters(org.weasis.dicom.mf.WadoParameters) InputStreamReader(java.io.InputStreamReader) AuthMethod(org.weasis.core.api.auth.AuthMethod) StandardCharsets(java.nio.charset.StandardCharsets) URLEncoder(java.net.URLEncoder) List(java.util.List) Tag(org.dcm4che3.data.Tag) TagD(org.weasis.dicom.codec.TagD) Comparator(java.util.Comparator) Multipart(org.weasis.dicom.web.Multipart) DicomMediaUtils(org.weasis.dicom.codec.utils.DicomMediaUtils) Callback(org.dcm4che3.json.JSONReader.Callback) InputStreamReader(java.io.InputStreamReader) Attributes(org.dcm4che3.data.Attributes) ArrayList(java.util.ArrayList) HttpResponse(org.weasis.core.api.util.HttpResponse) JSONReader(org.dcm4che3.json.JSONReader)

Example 19 with JSONReader

use of org.dcm4che3.json.JSONReader in project dcm4che by dcm4che.

the class JsonImageWriterConfiguration method loadDeviceExtension.

@Override
public boolean loadDeviceExtension(Device device, JsonReader reader, ConfigurationDelegate config) {
    if (!reader.getString().equals("dcmImageWriter"))
        return false;
    ImageWriterFactory factory = new ImageWriterFactory();
    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[] imageWriteParam = {};
        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 "dcmImageWriteParam":
                    imageWriteParam = reader.stringArray();
                    break;
                default:
                    reader.skipUnknownProperty();
            }
        }
        reader.expect(JsonParser.Event.END_OBJECT);
        factory.put(tsuid, new ImageWriterFactory.ImageWriterParam(formatName, className, patchJPEGLS, imageWriteParam));
    }
    device.addDeviceExtension(new ImageWriterExtension(factory));
    return true;
}
Also used : ImageWriterFactory(org.dcm4che3.imageio.codec.ImageWriterFactory) ImageWriterExtension(org.dcm4che3.net.imageio.ImageWriterExtension)

Example 20 with JSONReader

use of org.dcm4che3.json.JSONReader in project dcm4che by dcm4che.

the class JsonAuditLoggerConfiguration method loadDeviceExtension.

@Override
public boolean loadDeviceExtension(Device device, JsonReader reader, ConfigurationDelegate config) throws ConfigurationException {
    if (!reader.getString().equals("dcmAuditLogger"))
        return false;
    AuditLoggerDeviceExtension ext = new AuditLoggerDeviceExtension();
    loadFrom(ext, reader, device.listConnections(), config);
    device.addDeviceExtension(ext);
    return true;
}
Also used : AuditLoggerDeviceExtension(org.dcm4che3.net.audit.AuditLoggerDeviceExtension)

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