From 5eace4c6de5d6866debe49abc1f229ecb11e245d Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Sun, 24 Sep 2017 17:27:48 +0000
Subject: [PATCH] SSDM-5661 : AS V3 API : Support for semantic annotations -
 create/get methods - JS facade and JS tests

SVN: 38758
---
 .../openbis-v3-api-test/html/test/common.js   | 35 +++++++++++++++++++
 .../openbis-v3-api-test/html/test/dtos.js     | 10 ++++++
 .../html/test/openbis-execute-operations.js   |  8 +++++
 .../html/test/test-create.js                  | 28 +++++++++++++++
 .../openbis-v3-api-test/html/test/test-get.js | 23 ++++++++++++
 .../public/resources/api/v3/openbis.js        | 30 ++++++++++++++++
 6 files changed, 134 insertions(+)

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 c5c73b52a9b..dbd552ecb43 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
@@ -29,6 +29,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.AttachmentCreation = dtos.AttachmentCreation;
 		this.VocabularyTermCreation = dtos.VocabularyTermCreation;
 		this.TagCreation = dtos.TagCreation;
+		this.SemanticAnnotationCreation = dtos.SemanticAnnotationCreation;
 		this.DataSetCreation= dtos.DataSetCreation;
 		this.FullDataSetCreation = dtos.FullDataSetCreation;
 		this.DataSetFileCreation = dtos.DataSetFileCreation;
@@ -75,6 +76,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.VocabularyTermPermId = dtos.VocabularyTermPermId;
 		this.TagPermId = dtos.TagPermId;
 		this.TagCode = dtos.TagCode;
+		this.SemanticAnnotationsPermId = dtos.SemanticAnnotationsPermId;
 		this.SpaceSearchCriteria = dtos.SpaceSearchCriteria;
 		this.ProjectSearchCriteria = dtos.ProjectSearchCriteria;
 		this.ExperimentSearchCriteria = dtos.ExperimentSearchCriteria;
@@ -103,6 +105,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.ExternalDmsFetchOptions = dtos.ExternalDmsFetchOptions;
 		this.VocabularyTermFetchOptions = dtos.VocabularyTermFetchOptions;
 		this.TagFetchOptions = dtos.TagFetchOptions;
+		this.SemanticAnnotationFetchOptions = dtos.SemanticAnnotationFetchOptions;
 		this.DeletionFetchOptions = dtos.DeletionFetchOptions;
 		this.DeletionSearchCriteria = dtos.DeletionSearchCriteria;
 		this.CustomASServiceSearchCriteria = dtos.CustomASServiceSearchCriteria;
@@ -148,6 +151,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.CreateMaterialTypesOperation = dtos.CreateMaterialTypesOperation;
 		this.CreateVocabularyTermsOperation = dtos.CreateVocabularyTermsOperation;
 		this.CreateTagsOperation = dtos.CreateTagsOperation;
+		this.CreateSemanticAnnotationsOperation = dtos.CreateSemanticAnnotationsOperation;
 		this.CreateExternalDmsOperation = dtos.CreateExternalDmsOperation;
 
 		this.UpdateSpacesOperation = dtos.UpdateSpacesOperation;
@@ -169,6 +173,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.GetMaterialsOperation = dtos.GetMaterialsOperation;
 		this.GetVocabularyTermsOperation = dtos.GetVocabularyTermsOperation;
 		this.GetTagsOperation = dtos.GetTagsOperation;
+		this.GetSemanticAnnotationsOperation = dtos.GetSemanticAnnotationsOperation;
 		this.GetOperationExecutionsOperation = dtos.GetOperationExecutionsOperation;
 
 		this.SearchSpacesOperation = dtos.SearchSpacesOperation;
@@ -371,6 +376,21 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 				return permIds[0];
 			});
 		}.bind(this);
+		
+		this.createSemanticAnnotation = function(facade) {
+			var c = this;
+			var creation = new dtos.SemanticAnnotationCreation();
+			creation.setEntityTypeId(new dtos.EntityTypePermId("UNKNOWN", "SAMPLE"));
+			creation.setPredicateOntologyId("jsPredicateOntologyId");
+			creation.setPredicateOntologyVersion("jsPredicateOntologyVersion");
+			creation.setPredicateAccessionId("jsPredicateAccessionId");
+			creation.setDescriptorOntologyId("jsDescriptorOntologyId");
+			creation.setDescriptorOntologyVersion("jsDescriptorOntologyVersion");
+			creation.setDescriptorAccessionId("jsDescriptorAccessionId");
+			return facade.createSemanticAnnotations([ creation ]).then(function(permIds) {
+				return permIds[0];
+			});
+		}.bind(this);
 
 		this.createOperationExecution = function(facade) {
 			var c = this;
@@ -474,6 +494,13 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 			});
 		}.bind(this);
 		
+		this.findSemanticAnnotation = function(facade, id) {
+			var c = this;
+			return facade.getSemanticAnnotations([ id ], c.createSemanticAnnotationFetchOptions()).then(function(annotations) {
+				return annotations[id];
+			});
+		}.bind(this);
+		
 		this.findExternalDms = function(facade, id) {
 			var c = this;
 			return facade.getExternalDataManagementSystems([ id ], c.createExternalDmsFetchOptions()).then(function(edms) {
@@ -741,6 +768,14 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 			return fo;
 		};
 		
+		this.createSemanticAnnotationFetchOptions = function() {
+			var fo = new dtos.SemanticAnnotationFetchOptions();
+			fo.withEntityType();
+			fo.withPropertyType();
+			fo.withPropertyAssignment();
+			return fo;
+		};
+		
 		this.createExternalDmsFetchOptions = function() {
 			var fo = new dtos.ExternalDmsFetchOptions();
 			return fo;
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
index ed92bf27144..ccb6846c8d3 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
@@ -447,6 +447,16 @@ var sources = [
 	'as/dto/space/update/UpdateSpacesOperation',
 	'as/dto/space/update/UpdateSpacesOperationResult',
 	
+	'as/dto/semanticannotation/create/SemanticAnnotationCreation',
+	'as/dto/semanticannotation/create/CreateSemanticAnnotationsOperation',
+	'as/dto/semanticannotation/create/CreateSemanticAnnotationsOperationResult',
+	'as/dto/semanticannotation/fetchoptions/SemanticAnnotationFetchOptions',
+	'as/dto/semanticannotation/fetchoptions/SemanticAnnotationSortOptions',
+	'as/dto/semanticannotation/get/GetSemanticAnnotationsOperation',
+	'as/dto/semanticannotation/get/GetSemanticAnnotationsOperationResult',
+	'as/dto/semanticannotation/id/SemanticAnnotationPermId',
+	'as/dto/semanticannotation/SemanticAnnotation',
+	
 	'as/dto/tag/fetchoptions/TagFetchOptions',
 	'as/dto/tag/fetchoptions/TagSortOptions',
 	'as/dto/tag/id/TagCode',
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
index 35cf402de57..5786c2403b4 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
@@ -136,6 +136,10 @@ define([ 'jquery', 'openbis', 'test/common' ], function($, openbis, common) {
 		this.createTags = function(creations) {
 			return this._executeCreateOperation(new c.CreateTagsOperation(creations));
 		}
+		
+		this.createSemanticAnnotations = function(creations) {
+			return this._executeCreateOperation(new c.CreateSemanticAnnotationsOperation(creations));
+		}
 
 		this.updateSpaces = function(updates) {
 			return this._executeUpdateOperation(new c.UpdateSpacesOperation(updates));
@@ -208,6 +212,10 @@ define([ 'jquery', 'openbis', 'test/common' ], function($, openbis, common) {
 		this.getTags = function(ids, fetchOptions) {
 			return this._executeGetOperation(new c.GetTagsOperation(ids, fetchOptions));
 		}
+		
+		this.getSemanticAnnotations = function(ids, fetchOptions) {
+			return this._executeGetOperation(new c.GetSemanticAnnotationsOperation(ids, fetchOptions));
+		}
 
 		this.getExternalDataManagementSystems = function(ids, fetchOptions) {
 			return this._executeGetOperation(new c.GetExternalDmsOperation(ids, fetchOptions));
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-create.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-create.js
index c24fb7f1490..3326356c58c 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-create.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-create.js
@@ -537,6 +537,34 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 
 			testCreate(c, fCreate, c.findTag, fCheck);
 		});
+		
+		QUnit.test("createSemanticAnnotations()", function(assert) {
+			var c = new common(assert, openbis);
+
+			var fCreate = function(facade) {
+				var creation = new c.SemanticAnnotationCreation();
+				creation.setEntityTypeId(new c.EntityTypePermId("UNKNOWN", "SAMPLE"));
+				creation.setPredicateOntologyId("jsPredicateOntologyId");
+				creation.setPredicateOntologyVersion("jsPredicateOntologyVersion");
+				creation.setPredicateAccessionId("jsPredicateAccessionId");
+				creation.setDescriptorOntologyId("jsDescriptorOntologyId");
+				creation.setDescriptorOntologyVersion("jsDescriptorOntologyVersion");
+				creation.setDescriptorAccessionId("jsDescriptorAccessionId");
+				return facade.createSemanticAnnotations([ creation ]);
+			}
+
+			var fCheck = function(annotation) {
+				c.assertEqual(annotation.getEntityType().getCode(), "UNKNOWN", "Entity type code");
+				c.assertEqual(annotation.getPredicateOntologyId(), "jsPredicateOntologyId", "Predicate ontology id");
+				c.assertEqual(annotation.getPredicateOntologyVersion(), "jsPredicateOntologyVersion", "Predicate ontology version");
+				c.assertEqual(annotation.getPredicateAccessionId(), "jsPredicateAccessionId", "Predicate accession id");
+				c.assertEqual(annotation.getDescriptorOntologyId(), "jsDescriptorOntologyId", "Descriptor ontology id");
+				c.assertEqual(annotation.getDescriptorOntologyVersion(), "jsDescriptorOntologyVersion", "Descriptor ontology version");
+				c.assertEqual(annotation.getDescriptorAccessionId(), "jsDescriptorAccessionId", "Descriptor accession id");
+			}
+
+			testCreate(c, fCreate, c.findSemanticAnnotation, fCheck);
+		});
 
 	}
 
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
index 3f36e2b2598..5a5350b900a 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
@@ -366,6 +366,29 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 
 			testGet(c, fCreate, fGet, fGetEmptyFetchOptions, fechOptionsTestConfig);
 		});
+		
+		QUnit.test("getSemanticAnnotations()", function(assert) {
+			var c = new common(assert, openbis);
+			var fo = new c.SemanticAnnotationFetchOptions();
+			var fechOptionsTestConfig = getConfigForFetchOptions(fo);
+
+			var fCreate = function(facade) {
+				return $.when(c.createSemanticAnnotation(facade), c.createSemanticAnnotation(facade)).then(function(permId1, permId2) {
+					return [ permId1, permId2 ];
+				});
+			}
+
+			var fGet = function(facade, permIds) {
+				testFetchOptionsAssignation(c, fo, fechOptionsTestConfig);
+				return facade.getSemanticAnnotations(permIds, fo);
+			}
+
+			var fGetEmptyFetchOptions = function(facade, permIds) {
+				return facade.getSemanticAnnotations(permIds, new c.SemanticAnnotationFetchOptions());
+			}
+
+			testGet(c, fCreate, fGet, fGetEmptyFetchOptions, fechOptionsTestConfig);
+		});
 
 	}
 
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 ac5673ad9ad..c403ad54dfa 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
@@ -476,6 +476,21 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria
 				}
 			});
 		}
+		
+		this.createSemanticAnnotations = function(creations) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "createSemanticAnnotations",
+					"params" : [ thisFacade._private.sessionToken, creations ]
+				},
+				returnType : {
+					name : "List",
+					arguments : [ "SemanticAnnotationPermId" ]
+				}
+			});
+		}
 
 		this.updateSpaces = function(updates) {
 			var thisFacade = this;
@@ -706,6 +721,21 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria
 				}
 			});
 		}
+		
+		this.getSemanticAnnotations = function(ids, fetchOptions) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "getSemanticAnnotations",
+					"params" : [ thisFacade._private.sessionToken, ids, fetchOptions ]
+				},
+				returnType : {
+					name : "Map",
+					arguments : [ "ISemanticAnnotationId", "SemanticAnnotation" ]
+				}
+			});
+		}
 
 		this.getExternalDataManagementSystems = function(ids, fetchOptions) {
 			var thisFacade = this;
-- 
GitLab