From fe3cf7b4ebdb54ea21ebd9e6db4f1a46ac0f7ae9 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 6 Apr 2016 13:07:10 +0000
Subject: [PATCH] SSDM-3401: Javascript: search*Types introduced, implemented
 and tested. Bugs in *TypeFetchOptions.js fixed.

SVN: 36093
---
 .../openbis-v3-api-test/html/index.html       |   2 +-
 .../openbis-v3-api-test/html/test/common.js   |   5 +
 .../html/test/test-search.js                  | 125 ++++++++++++++++++
 .../fetchoptions/DataSetTypeFetchOptions.js   |   2 +-
 .../ExperimentTypeFetchOptions.js             |   2 +-
 .../fetchoptions/MaterialTypeFetchOptions.js  |   2 +-
 .../fetchoptions/SampleTypeFetchOptions.js    |   2 +-
 .../public/resources/api/v3/openbis.js        |  40 +++++-
 8 files changed, 173 insertions(+), 7 deletions(-)

diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/index.html b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/index.html
index 96e47bafbe5..2f9cf3b638e 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/index.html
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/index.html
@@ -15,7 +15,7 @@
 	require.paths["test/qunit-report"] = testPath + "/lib/qunit/js/qunit-reporter-junit";
 	require.paths["test/naturalsort"] = testPath + "/lib/naturalsort/js/naturalSort";
 
-	require.urlArgs = 'now=' + Date.now();
+//	require.urlArgs = 'now=' + Date.now();
 
 	require.shim["test/qunit-report"] = {
 		deps : [ 'test/qunit' ]
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 e6b26804e14..90f1376ca86 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
@@ -40,6 +40,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, openbis,
 		this.MaterialDeletionOptions = dtos.MaterialDeletionOptions;
 		this.VocabularyTermDeletionOptions = dtos.VocabularyTermDeletionOptions;
 		this.EntityTypePermId = dtos.EntityTypePermId;
+		this.EntityTypeSearchCriteria = dtos.EntityTypeSearchCriteria;
 		this.SpacePermId = dtos.SpacePermId;
 		this.ProjectPermId = dtos.ProjectPermId;
 		this.ProjectIdentifier = dtos.ProjectIdentifier;
@@ -62,9 +63,13 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, openbis,
 		this.SpaceFetchOptions = dtos.SpaceFetchOptions;
 		this.ProjectFetchOptions = dtos.ProjectFetchOptions;
 		this.ExperimentFetchOptions = dtos.ExperimentFetchOptions;
+		this.ExperimentTypeFetchOptions = dtos.ExperimentTypeFetchOptions;
 		this.SampleFetchOptions = dtos.SampleFetchOptions;
+		this.SampleTypeFetchOptions = dtos.SampleTypeFetchOptions;
 		this.DataSetFetchOptions = dtos.DataSetFetchOptions;
+		this.DataSetTypeFetchOptions = dtos.DataSetTypeFetchOptions;
 		this.MaterialFetchOptions = dtos.MaterialFetchOptions;
+		this.MaterialTypeFetchOptions = dtos.MaterialTypeFetchOptions;
 		this.VocabularyTermFetchOptions = dtos.VocabularyTermFetchOptions;
 		this.DeletionFetchOptions = dtos.DeletionFetchOptions;
 		this.DeletionSearchCriteria = dtos.DeletionSearchCriteria;
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
index b883dc17fe8..f37d68890c5 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
@@ -211,6 +211,36 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'test/naturalsort' ],
 			}, fo);
 		});
 
+		QUnit.test("searchExperimentTypes()", function(assert) {
+			var c = new common(assert);
+
+			var fSearch = function(facade) {
+				var criteria = new c.EntityTypeSearchCriteria();
+				criteria.withCode().thatStartsWith("HT");
+				var fetchOptions = new c.ExperimentTypeFetchOptions();
+				fetchOptions.withPropertyAssignments();
+				return facade.searchExperimentTypes(criteria, fetchOptions);
+			}
+
+			var fCheck = function(facade, experimentTypes) {
+				c.assertEqual(experimentTypes.length, 1, "Number of experiment types");
+				var type = experimentTypes[0];
+				c.assertEqual(type.getCode(), "HT_SEQUENCING", "Experiment type code");
+				c.assertEqual(type.getFetchOptions().hasPropertyAssignments(), true);
+				var assignments = type.getPropertyAssignments();
+				c.assertEqual(assignments.length, 1, "Number of property assignments");
+				c.assertEqual(assignments[0].isMandatory(), false, "Mandatory property assignment?");
+				var propertyType = assignments[0].getPropertyType();
+				c.assertEqual(propertyType.getCode(), "EXPERIMENT_DESIGN", "Property type code");
+				c.assertEqual(propertyType.getLabel(), "Experiment Design", "Property type label");
+				c.assertEqual(propertyType.getDescription(), "", "Property type description");
+				c.assertEqual(propertyType.getDataTypeCode(), "CONTROLLEDVOCABULARY", "Property data type code");
+				c.assertEqual(propertyType.isInternalNameSpace(), false, "Property type internal name space?");
+			}
+
+			testSearch(c, fSearch, fCheck);
+		});
+
 		QUnit.test("searchSamples()", function(assert) {
 			var c = new common(assert);
 
@@ -329,6 +359,37 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'test/naturalsort' ],
 			testSearch(c, fSearch, fCheck);
 		});
 
+		QUnit.test("searchSampleTypes()", function(assert) {
+			var c = new common(assert);
+
+			var fSearch = function(facade) {
+				var criteria = new c.EntityTypeSearchCriteria();
+				criteria.withCode().thatStartsWith("MA");
+				var fetchOptions = new c.SampleTypeFetchOptions();
+				fetchOptions.withPropertyAssignments().sortBy().label().desc();
+				return facade.searchSampleTypes(criteria, fetchOptions);
+			}
+
+			var fCheck = function(facade, sampleTypes) {
+				c.assertEqual(sampleTypes.length, 1, "Number of sample types");
+				var type = sampleTypes[0];
+				c.assertEqual(type.getCode(), "MASTER_SAMPLE", "Sample type code");
+				c.assertEqual(type.getFetchOptions().hasPropertyAssignments(), true);
+				var assignments = type.getPropertyAssignments();
+				c.assertEqual(assignments.length, 8, "Number of property assignments");
+				c.assertEqual(assignments[0].isMandatory(), true, "Mandatory property assignment?");
+				var propertyType = assignments[0].getPropertyType();
+				c.assertEqual(propertyType.getCode(), "SAMPLE_KIND", "Property type code");
+				c.assertEqual(propertyType.getLabel(), "Sample Kind", "Property type label");
+				c.assertEqual(propertyType.getDescription(), "", "Property type description");
+				c.assertEqual(propertyType.getDataTypeCode(), "CONTROLLEDVOCABULARY", "Property data type code");
+				c.assertEqual(propertyType.isInternalNameSpace(), false, "Property type internal name space?");
+				c.assertEqual(assignments[1].getPropertyType().getCode(), "NCBI_ORGANISM_TAXONOMY", "Second property type code");
+			}
+
+			testSearch(c, fSearch, fCheck);
+		});
+		
 		QUnit.test("searchDataSets()", function(assert) {
 			var c = new common(assert);
 
@@ -461,6 +522,38 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'test/naturalsort' ],
 			testSearch(c, fSearch, fCheck);
 		});
 
+		QUnit.test("searchDataSetTypes()", function(assert) {
+			var c = new common(assert);
+
+			var fSearch = function(facade) {
+				var criteria = new c.EntityTypeSearchCriteria();
+				criteria.withCode().thatStartsWith("MA");
+				var fetchOptions = new c.DataSetTypeFetchOptions();
+				fetchOptions.withPropertyAssignments().sortBy().code().asc();
+				return facade.searchDataSetTypes(criteria, fetchOptions);
+			}
+
+			var fCheck = function(facade, dataSetTypes) {
+				c.assertEqual(dataSetTypes.length, 1, "Number of data set types");
+				var type = dataSetTypes[0];
+				c.assertEqual(type.getCode(), "MACS_OUTPUT", "Data set type code");
+				c.assertEqual(type.getFetchOptions().hasPropertyAssignments(), true);
+				var assignments = type.getPropertyAssignments();
+				c.assertEqual(assignments.length, 2, "Number of property assignments");
+				c.assertEqual(assignments[0].isMandatory(), false, "Mandatory property assignment?");
+				var propertyType = assignments[0].getPropertyType();
+				c.assertEqual(propertyType.getCode(), "MACS_VERSION", "Property type code");
+				c.assertEqual(propertyType.getLabel(), "MACS VERSION", "Property type label");
+				c.assertEqual(propertyType.getDescription(), "", "Property type description");
+				c.assertEqual(propertyType.getDataTypeCode(), "CONTROLLEDVOCABULARY", "Property data type code");
+				c.assertEqual(propertyType.isInternalNameSpace(), false, "Property type internal name space?");
+				c.assertEqual(assignments[1].getPropertyType().getCode(), "NOTES", "Second property type code");
+				c.assertEqual(assignments[1].getPropertyType().getDataTypeCode(), "MULTILINE_VARCHAR", "Second property data type code");
+			}
+
+			testSearch(c, fSearch, fCheck);
+		});
+
 		QUnit.test("searchMaterials()", function(assert) {
 			var c = new common(assert);
 
@@ -497,6 +590,38 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'test/naturalsort' ],
 			}, fo);
 		});
 
+		QUnit.test("searchMaterialTypes()", function(assert) {
+			var c = new common(assert);
+
+			var fSearch = function(facade) {
+				var criteria = new c.EntityTypeSearchCriteria();
+				criteria.withCode().thatStartsWith("G");
+				var fetchOptions = new c.MaterialTypeFetchOptions();
+				fetchOptions.withPropertyAssignments().sortBy().code().desc();
+				return facade.searchMaterialTypes(criteria, fetchOptions);
+			}
+
+			var fCheck = function(facade, materialTypes) {
+				c.assertEqual(materialTypes.length, 1, "Number of material types");
+				var type = materialTypes[0];
+				c.assertEqual(type.getCode(), "GENE", "Material type code");
+				c.assertEqual(type.getFetchOptions().hasPropertyAssignments(), true);
+				var assignments = type.getPropertyAssignments();
+				c.assertEqual(assignments.length, 2, "Number of property assignments");
+				c.assertEqual(assignments[0].isMandatory(), false, "Mandatory property assignment?");
+				var propertyType = assignments[0].getPropertyType();
+				c.assertEqual(propertyType.getCode(), "GENE_SYMBOLS", "Property type code");
+				c.assertEqual(propertyType.getLabel(), "Gene symbols", "Property type label");
+				c.assertEqual(propertyType.getDescription(), "", "Property type description");
+				c.assertEqual(propertyType.getDataTypeCode(), "VARCHAR", "Property data type code");
+				c.assertEqual(propertyType.isInternalNameSpace(), false, "Property type internal name space?");
+				c.assertEqual(assignments[1].getPropertyType().getCode(), "DESCRIPTION", "Second property type code");
+				c.assertEqual(assignments[1].getPropertyType().getDescription(), "A Description", "Second property type description");
+			}
+
+			testSearch(c, fSearch, fCheck);
+		});
+
 		QUnit.test("searchGlobally() withText thatContains", function(assert) {
 			var c = new common(assert);
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/dataset/fetchoptions/DataSetTypeFetchOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/dataset/fetchoptions/DataSetTypeFetchOptions.js
index b39179512bd..cd475e9d1ce 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/dataset/fetchoptions/DataSetTypeFetchOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/dataset/fetchoptions/DataSetTypeFetchOptions.js
@@ -13,7 +13,7 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions" ], function(stjs, Fet
 		prototype.withPropertyAssignments = function() {
 			if (this.propertyAssignments == null) {
 				var PropertyAssignmentFetchOptions = require("as/dto/property/fetchoptions/PropertyAssignmentFetchOptions");
-				this.type = new PropertyAssignmentFetchOptions();
+				this.propertyAssignments = new PropertyAssignmentFetchOptions();
 			}
 			return this.propertyAssignments;
 		};
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/experiment/fetchoptions/ExperimentTypeFetchOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/experiment/fetchoptions/ExperimentTypeFetchOptions.js
index 9a1acc7da10..7f9c9a386db 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/experiment/fetchoptions/ExperimentTypeFetchOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/experiment/fetchoptions/ExperimentTypeFetchOptions.js
@@ -13,7 +13,7 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions" ], function(stjs, Fet
 		prototype.withPropertyAssignments = function() {
 			if (this.propertyAssignments == null) {
 				var PropertyAssignmentFetchOptions = require("as/dto/property/fetchoptions/PropertyAssignmentFetchOptions");
-				this.type = new PropertyAssignmentFetchOptions();
+				this.propertyAssignments = new PropertyAssignmentFetchOptions();
 			}
 			return this.propertyAssignments;
 		};
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/material/fetchoptions/MaterialTypeFetchOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/material/fetchoptions/MaterialTypeFetchOptions.js
index 0b7071f9d63..97e110f7a6e 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/material/fetchoptions/MaterialTypeFetchOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/material/fetchoptions/MaterialTypeFetchOptions.js
@@ -13,7 +13,7 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions" ], function(stjs, Fet
 		prototype.withPropertyAssignments = function() {
 			if (this.propertyAssignments == null) {
 				var PropertyAssignmentFetchOptions = require("as/dto/property/fetchoptions/PropertyAssignmentFetchOptions");
-				this.type = new PropertyAssignmentFetchOptions();
+				this.propertyAssignments = new PropertyAssignmentFetchOptions();
 			}
 			return this.propertyAssignments;
 		};
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/sample/fetchoptions/SampleTypeFetchOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/sample/fetchoptions/SampleTypeFetchOptions.js
index c343e7f4141..1365f357cab 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/sample/fetchoptions/SampleTypeFetchOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/sample/fetchoptions/SampleTypeFetchOptions.js
@@ -13,7 +13,7 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions" ], function(stjs, Fet
 		prototype.withPropertyAssignments = function() {
 			if (this.propertyAssignments == null) {
 				var PropertyAssignmentFetchOptions = require("as/dto/property/fetchoptions/PropertyAssignmentFetchOptions");
-				this.type = new PropertyAssignmentFetchOptions();
+				this.propertyAssignments = new PropertyAssignmentFetchOptions();
 			}
 			return this.propertyAssignments;
 		};
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 6ddd105b645..736dd7d83a0 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
@@ -452,6 +452,18 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 			})
 		}
 
+		this.searchExperimentTypes = function(criteria, fetchOptions) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "searchExperimentTypes",
+					"params" : [ thisFacade._private.sessionToken, criteria, fetchOptions ]
+				},
+				returnType : "SearchResult"
+			})
+		}
+		
 		this.searchSamples = function(criteria, fetchOptions) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
@@ -464,6 +476,18 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 			});
 		}
 
+		this.searchSampleTypes = function(criteria, fetchOptions) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "searchSampleTypes",
+					"params" : [ thisFacade._private.sessionToken, criteria, fetchOptions ]
+				},
+				returnType : "SearchResult"
+			});
+		}
+		
 		this.searchDataSets = function(criteria, fetchOptions) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
@@ -476,12 +500,24 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 			});
 		}
 
-		this.searchMaterials = function(criteria, fetchOptions) {
+		this.searchDataSetTypes = function(criteria, fetchOptions) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "searchDataSetTypes",
+					"params" : [ thisFacade._private.sessionToken, criteria, fetchOptions ]
+				},
+				returnType : "SearchResult"
+			});
+		}
+		
+		this.searchMaterialTypes = function(criteria, fetchOptions) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
 				url : openbisUrl,
 				data : {
-					"method" : "searchMaterials",
+					"method" : "searchMaterialTypes",
 					"params" : [ thisFacade._private.sessionToken, criteria, fetchOptions ]
 				},
 				returnType : "SearchResult"
-- 
GitLab