From bdef3de0fd9e52481f035046a60ee0eaeaf77e33 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Mon, 4 Apr 2016 19:21:34 +0000 Subject: [PATCH] SSDM-3395 : V3 AS API - controlled vocabulary terms - more js-tests for vocabularies + fix json serialization problem (decycle each method call parameter separately as jackson does not recognize object ids accross different parameters) SVN: 36074 --- .../openbis-v3-api-test/html/test/common.js | 10 +++++- .../html/test/test-delete.js | 5 +++ .../delete/VocabularyTermReplacement.js | 4 ++- .../public/resources/api/v3/openbis.js | 15 +++++++- .../delete/VocabularyTermReplacement.java | 34 ++++++++++++++----- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js index 3a758cd222a..e6b26804e14 100644 --- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js @@ -267,7 +267,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, openbis, options.setReason("test reason"); return facade.deleteMaterials([ id ], options); }.bind(this); - + this.deleteVocabularyTerm = function(facade, id) { var c = this; var options = new dtos.VocabularyTermDeletionOptions(); @@ -275,6 +275,14 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, openbis, return facade.deleteVocabularyTerms([ id ], options); }.bind(this); + this.replaceVocabularyTerm = function(facade, id) { + var c = this; + var options = new dtos.VocabularyTermDeletionOptions(); + options.setReason("test reason"); + options.replace(id, new c.VocabularyTermPermId("TEST-TERM-1", "TEST-VOCABULARY")); + return facade.deleteVocabularyTerms([ id ], options); + }.bind(this); + this.getObjectProperty = function(object, propertyName) { var propertyNames = propertyName.split('.'); for ( var pn in propertyNames) { diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js index 527a0b2430c..9c6b4b55770 100644 --- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js @@ -157,6 +157,11 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common' ], function($, _, open QUnit.test("deleteVocabularyTerm()", function(assert) { var c = new common(assert); testDeleteWithoutTrash(c, c.createVocabularyTerm, c.findVocabularyTerm, c.deleteVocabularyTerm); + }); + + QUnit.test("replaceVocabularyTerm()", function(assert) { + var c = new common(assert); + testDeleteWithoutTrash(c, c.createVocabularyTerm, c.findVocabularyTerm, c.replaceVocabularyTerm); }); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/vocabulary/delete/VocabularyTermReplacement.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/vocabulary/delete/VocabularyTermReplacement.js index 889edf6f4f1..52dcf741b6e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/vocabulary/delete/VocabularyTermReplacement.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/vocabulary/delete/VocabularyTermReplacement.js @@ -1,5 +1,7 @@ define([ "stjs" ], function(stjs) { - var VocabularyTermReplacement = function() { + var VocabularyTermReplacement = function(replacedId, replacementId) { + this.replacedId = replacedId ? replacedId : null; + this.replacementId = replacementId ? replacementId : null; }; stjs.extend(VocabularyTermReplacement, null, [], function(constructor, prototype) { prototype['@type'] = 'as.dto.vocabulary.delete.VocabularyTermReplacement'; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js index c40a8a237b8..6ddd105b645 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js @@ -17,7 +17,20 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) { var data = settings.data; data["id"] = "1"; data["jsonrpc"] = "2.0"; - settings.data = JSON.stringify(stjsUtil.decycle(data)); + + // decycle each parameter separately (jackson does not recognize + // object ids across different parameters) + + if (data.params && data.params.length > 0) { + var newParams = []; + data.params.forEach(function(param) { + var newParam = stjsUtil.decycle(param); + newParams.push(newParam); + }); + data.params = newParams; + } + + settings.data = JSON.stringify(data); var originalSuccess = settings.success || function() { }; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/delete/VocabularyTermReplacement.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/delete/VocabularyTermReplacement.java index 1ca53b3f1e1..9273d3cd538 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/delete/VocabularyTermReplacement.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/delete/VocabularyTermReplacement.java @@ -18,6 +18,8 @@ package ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.delete; import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonProperty; + import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.IVocabularyTermId; import ch.systemsx.cisd.base.annotation.JsonObject; @@ -30,19 +32,12 @@ public class VocabularyTermReplacement implements Serializable private static final long serialVersionUID = 1L; + @JsonProperty private IVocabularyTermId replacedId; + @JsonProperty private IVocabularyTermId replacementId; - // - // JSON-RPC - // - - @SuppressWarnings("unused") - private VocabularyTermReplacement() - { - } - public VocabularyTermReplacement(IVocabularyTermId replacedId, IVocabularyTermId replacementId) { this.replacedId = replacedId; @@ -59,4 +54,25 @@ public class VocabularyTermReplacement implements Serializable return replacementId; } + // + // JSON-RPC + // + + @SuppressWarnings("unused") + private VocabularyTermReplacement() + { + } + + @SuppressWarnings("unused") + private void setReplacedId(IVocabularyTermId replacedId) + { + this.replacedId = replacedId; + } + + @SuppressWarnings("unused") + private void setReplacementId(IVocabularyTermId replacementId) + { + this.replacementId = replacementId; + } + } -- GitLab