From d2b5c58e38018c32d83f614c962655b057a45dae Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Fri, 18 Sep 2015 11:20:49 +0000
Subject: [PATCH] SSDM-2495 : Refactoring, removing/merging/categorizing sample
 search calls

SVN: 34671
---
 .../eln-lims/html/js/server/ServerFacade.js   | 85 ++++++++++---------
 1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
index 5a166432d79..df1668af2c2 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
@@ -523,19 +523,33 @@ function ServerFacade(openbisServer) {
 		this.openbisServer.searchForDataSets(dataSetCriteria, callbackFunction)
 	}
 	
+	// Used for blast search datasets
+	this.getSamplesForDataSets = function(dataSetCodes, callback) {
+		this.openbisServer.getDataSetMetaDataWithFetchOptions(dataSetCodes, [ 'SAMPLE' ], callback);
+	}
+	
 	//
 	// Search Samples
 	//
 	this.searchSamples = function(fechOptions, callbackFunction)
 	{	
+		//Attributes
 		var samplePermId = fechOptions["samplePermId"];
 		var sampleIdentifier = fechOptions["sampleIdentifier"];
 		var sampleCode = fechOptions["sampleCode"];
 		var sampleTypeCode = fechOptions["sampleTypeCode"];
+		
+		//Properties
 		var properyKeyValueList = fechOptions["properyKeyValueList"];
+		
+		//Sub Queries
 		var sampleExperimentIdentifier = fechOptions["sampleExperimentIdentifier"];
+		var sampleContainer = fechOptions["sampleContainer"];
+		
+		//Hierarchy Options
 		var withProperties = fechOptions["withProperties"];
 		var withParents = fechOptions["withParents"];
+		var withChildren = fechOptions["withChildren"];
 		var withAncestors = fechOptions["withAncestors"];
 		var withDescendants = fechOptions["withDescendants"];
 			
@@ -630,6 +644,22 @@ function ServerFacade(openbisServer) {
 			});
 		}
 		
+		if(sampleContainer) {
+			subCriterias.push({
+				"@type" : "SearchSubCriteria",
+				"targetEntityKind" : "SAMPLE_CONTAINER",
+				"criteria" : {
+					matchClauses : [{
+							"@type":"AttributeMatchClause",
+							fieldType : "ATTRIBUTE",			
+							attribute : "PERM_ID",
+							desiredValue : sampleContainer
+						}],
+					operator : "MATCH_ALL_CLAUSES"
+				}
+			});
+		}
+		
 		var sampleCriteria = {
 			matchClauses : matchClauses,
 			subCriterias : subCriterias,
@@ -654,6 +684,10 @@ function ServerFacade(openbisServer) {
 			options.push("PARENTS");
 		}
 		
+		if(withChildren) {
+			options.push("CHILDREN");
+		}
+		
 		var localReference = this;
 		this.openbisServer.searchForSamplesWithFetchOptions(sampleCriteria, options, function(data) {
 			callbackFunction(localReference.getInitializedSamples(data.result));
@@ -742,6 +776,15 @@ function ServerFacade(openbisServer) {
 		searchNext();
 	}
 	
+	this.searchContained = function(permId, callbackFunction) {
+		this.searchSamples({
+			"sampleContainer" : permId,
+			"withProperties" : true,
+			"withParents" : true,
+			"withChildren" : true
+		}, callbackFunction);
+	}
+	
 	this.getInitializedSamples = function(result) {
 		
 		//
@@ -830,47 +873,7 @@ function ServerFacade(openbisServer) {
 	}
 	
 	//
-	// Sample Search Very Specific cases
-	//
-	
-	// Used for Plates
-	this.searchContained = function(permId, callbackFunction) {
-		var matchClauses = [];
-		
-		var subCriteria = {
-				"@type" : "SearchSubCriteria",
-				"targetEntityKind" : "SAMPLE_CONTAINER",
-				"criteria" : {
-					matchClauses : [{
-							"@type":"AttributeMatchClause",
-							fieldType : "ATTRIBUTE",			
-							attribute : "PERM_ID",
-							desiredValue : permId
-						}],
-					operator : "MATCH_ALL_CLAUSES"
-			}
-		}
-		
-		var sampleCriteria = 
-		{
-			matchClauses : matchClauses,
-			subCriterias : [ subCriteria ],
-			operator : "MATCH_ALL_CLAUSES"
-		};
-		
-		var localReference = this;
-		this.openbisServer.searchForSamplesWithFetchOptions(sampleCriteria, ["PROPERTIES", "PARENTS", "CHILDREN"], function(data) {
-			callbackFunction(localReference.getInitializedSamples(data.result));
-		});
-	}
-	
-	// Used for blast search datasets
-	this.getSamplesForDataSets = function(dataSetCodes, callback) {
-		this.openbisServer.getDataSetMetaDataWithFetchOptions(dataSetCodes, [ 'SAMPLE' ], callback);
-	}
-	
-	//
-	// Free Search
+	// Free Text Search
 	//
 	this.searchWithText = function(freeText, callbackFunction)
 	{
-- 
GitLab