From 99a12455005e96b3d1bfa2b8f40f186fad9f950b Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Mon, 18 Mar 2013 11:12:35 +0000
Subject: [PATCH] BIS-151/SP-550 : openbis.js - represent Long fields as
 strings in JSON - make both dependency checks and GWT compilation work

SVN: 28630
---
 .../shared/api/v1/util/JsonPropertyUtil.java  | 18 ++++++++-
 .../openbis/generic/shared/basic/TechId.java  |  2 +-
 .../shared/basic/dto/DatabaseInstance.java    |  2 +-
 .../dto/ExternalDataManagementSystem.java     |  2 +-
 .../generic/shared/basic/dto/Metaproject.java |  2 +-
 .../generic/shared/basic/dto/Vocabulary.java  |  4 +-
 .../shared/basic/dto/VocabularyTerm.java      |  2 +-
 .../shared/basic/util/JsonPropertyUtil.java   | 40 +++++++++++++++++++
 8 files changed, 63 insertions(+), 9 deletions(-)
 create mode 100644 openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/util/JsonPropertyUtil.java

diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/util/JsonPropertyUtil.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/util/JsonPropertyUtil.java
index 9a9fa01391d..5c86a450a8d 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/util/JsonPropertyUtil.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/util/JsonPropertyUtil.java
@@ -22,14 +22,28 @@ package ch.systemsx.cisd.openbis.generic.shared.api.v1.util;
 public class JsonPropertyUtil
 {
 
+    /*
+     * Unfortunately some of our API DTOs are not in the API packages or refer to classes that are
+     * not in the API packages (for instance classes in
+     * ch.systemsx.cisd.openbis.generic.shared.basic.dto package). To make things even worse these
+     * classes are reused in both the API and in GWT. Creating a utility class that is reused by all
+     * these DTOs is therefore impossible. If that utility class is located in the API package then
+     * it won't be available in GWT. On the other hand if it is located in a GWT module then is
+     * breaks the API code independence. Until we don't fix the DTOs the best we can do is to have
+     * two JsonPropertyUtil classes. Once we have all API DTOs is the API packages the other
+     * JsonPropertyUtil class can be removed.
+     */
+
     public static final String toStringOrNull(final Long longOrNull)
     {
-        return longOrNull == null ? null : longOrNull.toString();
+        return ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil
+                .toStringOrNull(longOrNull);
     }
 
     public static final Long toLongOrNull(final String stringOrNull)
     {
-        return stringOrNull == null ? null : Long.valueOf(stringOrNull);
+        return ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil
+                .toLongOrNull(stringOrNull);
     }
 
 }
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/TechId.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/TechId.java
index de3a659fd24..9815bebc76c 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/TechId.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/TechId.java
@@ -25,8 +25,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ServiceVersionHolder;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * Technical identifier of an entity.
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java
index e42a640697a..4e3c24b6c5b 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java
@@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * @author Franz-Josef Elmer
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExternalDataManagementSystem.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExternalDataManagementSystem.java
index 5db1d028ef8..4d362e4ddea 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExternalDataManagementSystem.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExternalDataManagementSystem.java
@@ -22,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * @author Pawel Glyzewski
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Metaproject.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Metaproject.java
index b72ceabe65f..66ef8871cab 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Metaproject.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Metaproject.java
@@ -23,8 +23,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IIdAndCodeHolder;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * @author Pawel Glyzewski
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Vocabulary.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Vocabulary.java
index d4151b159e7..94e12da5830 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Vocabulary.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Vocabulary.java
@@ -16,7 +16,7 @@
 
 package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
 
-import java.util.ArrayList;
+ import java.util.ArrayList;
 import java.util.List;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
 import ch.systemsx.cisd.common.reflection.CollectionMapping;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * Controlled vocabulary.
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTerm.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTerm.java
index 1a8b0272cbd..5d727916114 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTerm.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTerm.java
@@ -21,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
 import ch.systemsx.cisd.common.parser.BeanProperty;
-import ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil;
+import ch.systemsx.cisd.openbis.generic.shared.basic.util.JsonPropertyUtil;
 
 /**
  * A vocabulary term.
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/util/JsonPropertyUtil.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/util/JsonPropertyUtil.java
new file mode 100644
index 00000000000..c89ba067ba7
--- /dev/null
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/util/JsonPropertyUtil.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2013 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.shared.basic.util;
+
+/**
+ * @author pkupczyk
+ */
+public class JsonPropertyUtil
+{
+
+    /*
+     * This class should be removed once we clean our API DTOs - see comment in {@link
+     * ch.systemsx.cisd.openbis.generic.shared.api.v1.util.JsonPropertyUtil}
+     */
+
+    public static final String toStringOrNull(final Long longOrNull)
+    {
+        return longOrNull == null ? null : longOrNull.toString();
+    }
+
+    public static final Long toLongOrNull(final String stringOrNull)
+    {
+        return stringOrNull == null ? null : Long.valueOf(stringOrNull);
+    }
+
+}
-- 
GitLab