Package: src:orthanc-imagej
Version: 1.2+dfsg-1
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi,

I'd like to transition json-simple 3.1.1 to unstable, but orthanc-imagej is a 
blocker since it builds against libjson-simple-java << 3 only.

The json-simple classes used by orthanc-imagej were deprecated in version 2.0.0 
[1]. There were removed in versions 3.x [2].

[1] https://github.com/cliftonlabs/json-simple/blob/json-simple-2.0.0/README.txt
[2] https://github.com/cliftonlabs/json-simple/blob/json-simple-3.0.1/CHANGELOG

Please find attached a patch proposal to use the current json-simple classes. 
I've tested that the package builds correctly against libjson-simple-java 
version 2.3.0-1 from unstable and version 3.1.1-1~exp2 currently in 
experimental. But I don't known how to test the package afterward.

Thanks in advance for considering.

_g.

- -- System Information:
Debian Release: buster/sid
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.6.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), 
LANGUAGE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEoJObzArDE05WtIyR7+hsbH/+z4MFAl69xOcACgkQ7+hsbH/+
z4M05QgArerRja+IdHaKJdRugPYsdrg7UkATnA6+fdfZqZ556z0PEfspvQBMDUIO
fCUymwo0IozDmxNq5COn2w0AbExgwOTwsnf/Pg3t0xGw0AjdBsckvqS0P1H9APWz
m/uZHlFA8TZ2V1SPtoRK4HnE8Ru8K0ho1yexl1jSPenLFFaAWpPJK1Vib/M+2c+3
DKIjQQ2gW2g2N4+IHkinKW5KLuYr+4AErPNRP7VdVAxUcplYk1WpfRcbyMDhogTF
ZGK35Bew9eXc71Wg3WNPZSwM/RnD/sgx0MMeknOeJxtFgMt3CyoKWtWIALMuNq62
S0omjztsZNfsU6LcS+cUMvPLRteAOA==
=UUGZ
-----END PGP SIGNATURE-----
diff -Nru orthanc-imagej-1.2+dfsg/debian/changelog 
orthanc-imagej-1.2+dfsg/debian/changelog
--- orthanc-imagej-1.2+dfsg/debian/changelog    2018-10-31 08:28:01.000000000 
+0100
+++ orthanc-imagej-1.2+dfsg/debian/changelog    2020-05-14 23:29:49.000000000 
+0200
@@ -1,3 +1,10 @@
+orthanc-imagej (1.2+dfsg-1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * tentative patch to build against json-simple 3
+
+ -- Gilles Filippini <p...@debian.org>  Thu, 14 May 2020 23:29:49 +0200
+
 orthanc-imagej (1.2+dfsg-1) unstable; urgency=medium
 
   * New upstream version. (Closes: #912363)
diff -Nru orthanc-imagej-1.2+dfsg/debian/patches/json-simple-3.patch 
orthanc-imagej-1.2+dfsg/debian/patches/json-simple-3.patch
--- orthanc-imagej-1.2+dfsg/debian/patches/json-simple-3.patch  1970-01-01 
01:00:00.000000000 +0100
+++ orthanc-imagej-1.2+dfsg/debian/patches/json-simple-3.patch  2020-05-14 
23:29:49.000000000 +0200
@@ -0,0 +1,359 @@
+Description: Migrate away from deprecated json-simple 1.x classes
+ See json-simple 2.0.0 changelog:
+ > * Deprecated JSONParse and JSONValue in favor of Jsoner.
+ > * Deprecated JSONStreamAware and JSONAware in favor of Jsonable.
+ > * Deprecated JSONObject in favor of JsonObject.
+ > * Deprecated JSONArray in favor of JsonArray.
+ .
+ This patch uses the new json-simple Json* classes. It is compatible with
+ both 2.x and 3.x json-simple releases, with a few ajustments regarding
+ backward incompatible changes in json-simple 3.x:
+ - The package name, changed to com.github.cliftonlabs.json_simple
+ - The exception DeserializationExcetpion renamed as JsonException
+ These two changes are handled using place-holders @JSON_SIMPLE_PACKAGE@
+ and @JSON_EXCETPION@ which are substituted at build time by debian/rules.
+ .
+ With these tricks the package is compatible with json-simple 2.x and 3.x.
+Author: Gilles Filippini <p...@debian.org>
+Index: orthanc-imagej-1.2+dfsg/com/orthancserver/DicomDecoder.java
+===================================================================
+--- orthanc-imagej-1.2+dfsg.orig/com/orthancserver/DicomDecoder.java
++++ orthanc-imagej-1.2+dfsg/com/orthancserver/DicomDecoder.java
+@@ -28,7 +28,8 @@ import ij.process.ShortProcessor;
+ import ij.process.ColorProcessor;
+ import ij.io.FileInfo;
+ import ij.measure.Calibration;
+-import org.json.simple.*;
++import @JSON_SIMPLE_PACKAGE@.JsonObject;
++import @JSON_SIMPLE_PACKAGE@.JsonArray;
+ import java.util.List;
+ import java.util.ArrayList;
+ import java.util.Collections;
+@@ -92,10 +93,10 @@ public class DicomDecoder
+   };
+ 
+   private static void ExtractCalibration(ImagePlus image,
+-                                         JSONObject tags)
++                                         JsonObject tags)
+   {
+-    JSONObject rescaleIntercept = (JSONObject) tags.get("0028,1052");
+-    JSONObject rescaleSlope = (JSONObject) tags.get("0028,1053");
++    JsonObject rescaleIntercept = (JsonObject) tags.get("0028,1052");
++    JsonObject rescaleSlope = (JsonObject) tags.get("0028,1053");
+     if (rescaleIntercept != null &&
+         rescaleSlope != null)
+     {
+@@ -108,9 +109,9 @@ public class DicomDecoder
+   }
+ 
+   private static void ExtractPixelSpacing(ImagePlus image,
+-                                          JSONObject tags)
++                                          JsonObject tags)
+   {
+-    JSONObject pixelSpacing = (JSONObject) tags.get("0028,0030");
++    JsonObject pixelSpacing = (JsonObject) tags.get("0028,0030");
+     if (pixelSpacing != null)
+     {
+       String[] tokens = ((String) pixelSpacing.get("Value")).split("\\\\");
+@@ -130,7 +131,7 @@ public class DicomDecoder
+   }
+ 
+   private static void ExtractDicomInfo(ImagePlus image,
+-                                       JSONObject tags)
++                                       JsonObject tags)
+   {
+     String info = new String();
+ 
+@@ -143,7 +144,7 @@ public class DicomDecoder
+     Collections.sort(tagsIndex);
+     for (String tag : tagsIndex) 
+     {
+-      JSONObject value = (JSONObject) tags.get(tag);
++      JsonObject value = (JsonObject) tags.get(tag);
+ 
+       if (((String) value.get("Type")).equals("String"))
+       {
+@@ -232,7 +233,7 @@ public class DicomDecoder
+ 
+ 
+   private String[]  SortSlicesBy3D(OrthancConnection c, 
+-                                   JSONArray instances) throws IOException
++                                   JsonArray instances) throws IOException
+   {
+     ArrayList<Slice> slices = new ArrayList<Slice>();
+     float normal[] = null;
+@@ -243,7 +244,7 @@ public class DicomDecoder
+     for (int i = 0; i < instances.size(); i++)
+     {
+       String uuid = (String) instances.get(i);
+-      JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid + 
"/tags?simplify");
++      JsonObject instance = (JsonObject) c.ReadJson("/instances/" + uuid + 
"/tags?simplify");
+       if (!instance.containsKey("ImageOrientationPatient") ||
+           !instance.containsKey("ImagePositionPatient"))
+       {
+@@ -298,14 +299,14 @@ public class DicomDecoder
+ 
+ 
+   private String[]  SortSlicesByNumber(OrthancConnection c, 
+-                                       JSONArray instances) throws IOException
++                                       JsonArray instances) throws IOException
+   {
+     ArrayList<Slice> slices = new ArrayList<Slice>();
+ 
+     for (int i = 0; i < instances.size(); i++)
+     {
+       String uuid = (String) instances.get(i);
+-      JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid);
++      JsonObject instance = (JsonObject) c.ReadJson("/instances/" + uuid);
+       Long index = (Long) instance.get("IndexInSeries");
+       slices.add(new Slice((float) index, uuid));
+     }
+@@ -316,7 +317,7 @@ public class DicomDecoder
+ 
+ 
+   private String[] GetSlices(OrthancConnection c, 
+-                             JSONArray instances) throws IOException
++                             JsonArray instances) throws IOException
+   {
+     String[] result;
+ 
+@@ -345,30 +346,30 @@ public class DicomDecoder
+                       String uuid) throws IOException, InterruptedException, 
ExecutionException
+   {
+     ImageStack stack = null;
+-    JSONObject tags = null;
++    JsonObject tags = null;
+     String tagsUri, name;
+ 
+     if (isInstance)
+     {
+       name = "Instance " + uuid;
+-      tags = (JSONObject) c.ReadJson("/instances/" + uuid + "/tags");
++      tags = (JsonObject) c.ReadJson("/instances/" + uuid + "/tags");
+       stack = AddSlice(stack, c, uuid);
+     }
+     else
+     {
+       name = "Series " + uuid;
+ 
+-      JSONObject series = (JSONObject) c.ReadJson("/series/" + uuid);
+-      JSONArray instances = (JSONArray) series.get("Instances");
++      JsonObject series = (JsonObject) c.ReadJson("/series/" + uuid);
++      JsonArray instances = (JsonArray) series.get("Instances");
+ 
+       try
+       {
+-        tags = (JSONObject) c.ReadJson("/series/" + uuid + "/shared-tags");
++        tags = (JsonObject) c.ReadJson("/series/" + uuid + "/shared-tags");
+       }
+       catch (Exception e)
+       {
+         // Fallback for old versions of Orthanc, without "shared-tags"
+-        tags = (JSONObject) c.ReadJson("/instances/" + (String) 
instances.get(0) + "/tags");
++        tags = (JsonObject) c.ReadJson("/instances/" + (String) 
instances.get(0) + "/tags");
+       }
+ 
+       final String[] slices = GetSlices(c, instances);
+Index: 
orthanc-imagej-1.2+dfsg/com/orthancserver/OrthancConfigurationDialog.java
+===================================================================
+--- 
orthanc-imagej-1.2+dfsg.orig/com/orthancserver/OrthancConfigurationDialog.java
++++ orthanc-imagej-1.2+dfsg/com/orthancserver/OrthancConfigurationDialog.java
+@@ -44,7 +44,7 @@ import javax.swing.JTree;
+ import javax.swing.SwingWorker;
+ import javax.swing.border.EmptyBorder;
+ 
+-import org.json.simple.JSONObject;
++import @JSON_SIMPLE_PACKAGE@.JsonObject;
+ 
+ 
+ public class OrthancConfigurationDialog extends JDialog 
+@@ -110,7 +110,7 @@ public class OrthancConfigurationDialog
+             OrthancConnection orthanc = CreateConnection();
+             try
+             {
+-              JSONObject system = (JSONObject) orthanc.ReadJson("system");
++              JsonObject system = (JsonObject) orthanc.ReadJson("system");
+               JOptionPane.showMessageDialog(null, "Successfully connected to 
this Orthanc server " +
+                                             "(version: " + (String) 
system.get("Version") + ")!", 
+                                             "Success", 
JOptionPane.INFORMATION_MESSAGE);
+Index: orthanc-imagej-1.2+dfsg/com/orthancserver/OrthancConnection.java
+===================================================================
+--- orthanc-imagej-1.2+dfsg.orig/com/orthancserver/OrthancConnection.java
++++ orthanc-imagej-1.2+dfsg/com/orthancserver/OrthancConnection.java
+@@ -31,8 +31,9 @@ import java.net.URL;
+ import java.net.URLConnection;
+ import java.util.Base64;
+ import javax.imageio.ImageIO;
+-import org.json.simple.JSONObject;
+-import org.json.simple.JSONValue;
++import @JSON_SIMPLE_PACKAGE@.JsonObject;
++import @JSON_SIMPLE_PACKAGE@.Jsoner;
++import @JSON_SIMPLE_PACKAGE@.@JSON_EXCEPTION@;
+ 
+ public class OrthancConnection
+ {
+@@ -194,7 +195,13 @@ public class OrthancConnection
+   public Object ReadJson(String uri) throws IOException
+   {
+     String content = ReadString(uri);
+-    Object json = JSONValue.parse(content);
++    Object json;
++    try {
++        json = Jsoner.deserialize(content);
++    }
++    catch (@JSON_EXCEPTION@ e) {
++        json = null;
++    }
+ 
+     if (json == null)
+     {
+@@ -222,9 +229,9 @@ public class OrthancConnection
+     name_ = name;
+   }
+ 
+-  public JSONObject Serialize()
++  public JsonObject Serialize()
+   {
+-    JSONObject json = new JSONObject();
++    JsonObject json = new JsonObject();
+     json.put("Name", name_);
+     json.put("Url", baseUrl_);
+ 
+@@ -236,7 +243,7 @@ public class OrthancConnection
+     return json;
+   }
+ 
+-  public static OrthancConnection Unserialize(JSONObject json)
++  public static OrthancConnection Unserialize(JsonObject json)
+   {
+     OrthancConnection c = new OrthancConnection();
+     c.SetInsecure(true);  // Fix issue 9 (cannot connect to self-signed 
certificates)
+Index: orthanc-imagej-1.2+dfsg/com/orthancserver/SelectImageDialog.java
+===================================================================
+--- orthanc-imagej-1.2+dfsg.orig/com/orthancserver/SelectImageDialog.java
++++ orthanc-imagej-1.2+dfsg/com/orthancserver/SelectImageDialog.java
+@@ -21,9 +21,9 @@
+ 
+ package com.orthancserver;
+ 
+-import org.json.simple.JSONValue;
+-import org.json.simple.JSONArray;
+-import org.json.simple.JSONObject;
++import @JSON_SIMPLE_PACKAGE@.Jsoner;
++import @JSON_SIMPLE_PACKAGE@.JsonArray;
++import @JSON_SIMPLE_PACKAGE@.JsonObject;
+ import java.io.IOException;
+ import java.util.ArrayList;
+ import java.util.Base64;
+@@ -109,8 +109,8 @@ public class SelectImageDialog extends J
+       {
+         try
+         {
+-          JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + 
uuid_);
+-          JSONArray instances = (JSONArray) series.get("Instances");
++          JsonObject series = (JsonObject) orthanc_.ReadJson("series/" + 
uuid_);
++          JsonArray instances = (JsonArray) series.get("Instances");
+           if (instances.size() > 0)
+           {
+             preview.Load(orthanc_, "/instances/" + instances.get(0) + 
"/preview");
+@@ -150,12 +150,12 @@ public class SelectImageDialog extends J
+     {
+       List<MyTreeNode> children = new ArrayList<MyTreeNode>();
+ 
+-      JSONArray patients = (JSONArray) orthanc_.ReadJson("patients");
++      JsonArray patients = (JsonArray) orthanc_.ReadJson("patients");
+       for (int i = 0; i < patients.size(); i++)
+       {
+         String uuid = (String) patients.get(i);
+-        JSONObject patient = (JSONObject) orthanc_.ReadJson("patients/" + 
uuid);
+-        JSONObject main = (JSONObject) patient.get("MainDicomTags");
++        JsonObject patient = (JsonObject) orthanc_.ReadJson("patients/" + 
uuid);
++        JsonObject main = (JsonObject) patient.get("MainDicomTags");
+ 
+         String s = new String();
+         s = AddComponent(s, (String) main.get("PatientID"));
+@@ -171,13 +171,13 @@ public class SelectImageDialog extends J
+     {
+       List<MyTreeNode> children = new ArrayList<MyTreeNode>();
+ 
+-      JSONObject patient = (JSONObject) orthanc_.ReadJson("patients/" + 
uuid_);
+-      JSONArray studies = (JSONArray) patient.get("Studies");
++      JsonObject patient = (JsonObject) orthanc_.ReadJson("patients/" + 
uuid_);
++      JsonArray studies = (JsonArray) patient.get("Studies");
+       for (int i = 0; i < studies.size(); i++)
+       {
+         String uuid = (String) studies.get(i);
+-        JSONObject study = (JSONObject) orthanc_.ReadJson("studies/" + uuid);
+-        JSONObject main = (JSONObject) study.get("MainDicomTags");
++        JsonObject study = (JsonObject) orthanc_.ReadJson("studies/" + uuid);
++        JsonObject main = (JsonObject) study.get("MainDicomTags");
+ 
+         String s = new String();
+         s = AddComponent(s, (String) main.get("StudyDescription"));
+@@ -193,13 +193,13 @@ public class SelectImageDialog extends J
+     {
+       List<MyTreeNode> children = new ArrayList<MyTreeNode>();
+ 
+-      JSONObject study = (JSONObject) orthanc_.ReadJson("studies/" + uuid_);
+-      JSONArray seriesSet = (JSONArray) study.get("Series");
++      JsonObject study = (JsonObject) orthanc_.ReadJson("studies/" + uuid_);
++      JsonArray seriesSet = (JsonArray) study.get("Series");
+       for (int i = 0; i < seriesSet.size(); i++)
+       {
+         String uuid = (String) seriesSet.get(i);
+-        JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + uuid);
+-        JSONObject main = (JSONObject) series.get("MainDicomTags");
++        JsonObject series = (JsonObject) orthanc_.ReadJson("series/" + uuid);
++        JsonObject main = (JsonObject) series.get("MainDicomTags");
+ 
+         String s = new String();
+         s = AddComponent(s, (String) main.get("Modality"));
+@@ -215,12 +215,12 @@ public class SelectImageDialog extends J
+     {
+       List<MyTreeNode> children = new ArrayList<MyTreeNode>();
+ 
+-      JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + uuid_);
+-      JSONArray instances = (JSONArray) series.get("Instances");
++      JsonObject series = (JsonObject) orthanc_.ReadJson("series/" + uuid_);
++      JsonArray instances = (JsonArray) series.get("Instances");
+       for (int i = 0; i < instances.size(); i++)
+       {
+         String uuid = (String) instances.get(i);
+-        JSONObject instance = (JSONObject) orthanc_.ReadJson("instances/" + 
uuid);
++        JsonObject instance = (JsonObject) orthanc_.ReadJson("instances/" + 
uuid);
+         Long index = (Long) instance.get("IndexInSeries");
+         String s;
+         if (index == null)
+@@ -556,12 +556,12 @@ public class SelectImageDialog extends J
+       // https://stackoverflow.com/a/13109632/881731
+       String decoded = OrthancConnection.DecodeBase64(s);
+       
+-      JSONArray config = (JSONArray) JSONValue.parse(decoded);
++      JsonArray config = Jsoner.deserialize(decoded, (JsonArray) null);
+       if (config != null)
+       {
+         for (int i = 0; i < config.size(); i++)
+         {
+-          AddOrthancServer(OrthancConnection.Unserialize((JSONObject) 
config.get(i)));
++          AddOrthancServer(OrthancConnection.Unserialize((JsonObject) 
config.get(i)));
+         }
+       }
+     }
+@@ -569,7 +569,7 @@ public class SelectImageDialog extends J
+ 
+   public String Serialize()
+   {
+-    JSONArray servers = new JSONArray();
++    JsonArray servers = new JsonArray();
+ 
+     for (int i = 0; i < root_.getChildCount(); i++)
+     {
+@@ -577,7 +577,7 @@ public class SelectImageDialog extends J
+       servers.add(node.GetConnection().Serialize());
+     }
+ 
+-    String config = servers.toJSONString();
++    String config = servers.toJson();
+ 
+     // https://stackoverflow.com/a/13109632/881731
+     return new String(Base64.getEncoder().encode(config.getBytes()));
diff -Nru orthanc-imagej-1.2+dfsg/debian/patches/series 
orthanc-imagej-1.2+dfsg/debian/patches/series
--- orthanc-imagej-1.2+dfsg/debian/patches/series       2018-10-31 
08:27:19.000000000 +0100
+++ orthanc-imagej-1.2+dfsg/debian/patches/series       2020-05-14 
23:29:49.000000000 +0200
@@ -1 +1,2 @@
 json-simple
+json-simple-3.patch
diff -Nru orthanc-imagej-1.2+dfsg/debian/rules 
orthanc-imagej-1.2+dfsg/debian/rules
--- orthanc-imagej-1.2+dfsg/debian/rules        2018-10-31 08:28:01.000000000 
+0100
+++ orthanc-imagej-1.2+dfsg/debian/rules        2020-05-14 23:29:49.000000000 
+0200
@@ -2,12 +2,35 @@
 
 JSON_SIMPLE_JAR = /usr/share/java/json-simple.jar
 
+JSON_SIMPLE_VERSION = $(shell dpkg -l libjson-simple-java | grep '^ii' | awk 
'{print $$3}')
+JSON_SIMPLE_3 = $(shell dpkg --compare-versions '$(JSON_SIMPLE_VERSION)' '>' 
'3.1.1-1~' && echo yes || echo no)
+ifeq (yes,$(JSON_SIMPLE_3))
+JSON_SIMPLE_PACKAGE = com.github.cliftonlabs.json_simple
+JSON_EXCEPTION = JsonException
+else
+JSON_SIMPLE_PACKAGE = org.json.simple
+JSON_EXCEPTION = DeserializationException
+endif
+
 %:
        dh $@ --parallel --builddirectory=Build
 
+override_dh_auto_clean:
+       dh_auto_clean
+       find . -type f -name \*.java.json-simple \
+         -exec sh -c 'file={} && mv $$file $${file%.json-simple}' \; -print
+
 override_dh_auto_configure:
        dh_auto_configure -- -DCMAKE_JAVA_INCLUDE_PATH=${JSON_SIMPLE_JAR}
 
+override_dh_auto_build:
+       find . -type f -name \*.java -exec grep -q 'import 
@JSON_SIMPLE_PACKAGE@' {} \; \
+         -exec sed -i.json-simple \
+                   -e 's,@JSON_SIMPLE_PACKAGE@,$(JSON_SIMPLE_PACKAGE),' \
+                   -e 's/@JSON_EXCEPTION@/$(JSON_EXCEPTION)/' \
+                   {} \; -print
+       dh_auto_build
+
 override_dh_auto_install:
        dh_auto_install
        dh_link ${JSON_SIMPLE_JAR} 
usr/share/imagej/plugins/Orthanc_Import_json-simple.jar

Reply via email to