From c51a52eda88edb0c3571c4de4c9524d2ae8ba744 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Thu, 24 Jul 2014 10:11:43 +0000
Subject: [PATCH] SSDM-623: Copy parents and children when duplicating
 subexperiments/samples (set default bench).

SVN: 32134
---
 .../newbrowser/html/js/views/SampleForm.js    | 27 +++++++++++++++++++
 .../reporting-plugins/newbrowserapi/script.py | 22 +++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
index 287007aa069..704159618d8 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
@@ -817,6 +817,33 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
 			}
 			if(!copyChildrenOnCopy) {
 				parameters["sampleChildren"] = [];
+			} else if(this.profile.storagesConfiguration["isEnabled"]) {
+				//1. All properties belonging to benches, to not to copy
+				parameters["notCopyProperties"] = [];
+				parameters["defaultBenchPropertyList"] = [];
+				for(var i = 0; i < this.profile.storagesConfiguration["STORAGE_PROPERTIES"].length; i++) {
+					var storagePropertyGroup = this.profile.storagesConfiguration["STORAGE_PROPERTIES"][i];
+					var listToUse = "notCopyProperties";
+					if(i === 0) {
+						listToUse = "defaultBenchPropertyList";
+					}
+					parameters[listToUse].push(storagePropertyGroup["NAME_PROPERTY"]);
+					parameters[listToUse].push(storagePropertyGroup["ROW_PROPERTY"]);
+					parameters[listToUse].push(storagePropertyGroup["COLUMN_PROPERTY"]);
+					parameters[listToUse].push(storagePropertyGroup["BOX_PROPERTY"]);
+					parameters[listToUse].push(storagePropertyGroup["USER_PROPERTY"]);
+				}
+				
+				//2. Default Bench properties
+				var defaultStoragePropertyGroup = this.profile.storagesConfiguration["STORAGE_PROPERTIES"][0];
+				parameters["defaultBenchProperties"] = {};
+				var $benchDropdown = FormUtil.getDefaultBenchDropDown();
+				var defaultBench = $benchDropdown.children()[1].value;
+				parameters["defaultBenchProperties"][defaultStoragePropertyGroup["NAME_PROPERTY"]] = defaultBench;
+				parameters["defaultBenchProperties"][defaultStoragePropertyGroup["ROW_PROPERTY"]] = 1;
+				parameters["defaultBenchProperties"][defaultStoragePropertyGroup["COLUMN_PROPERTY"]] = 1;
+				parameters["defaultBenchProperties"][defaultStoragePropertyGroup["BOX_PROPERTY"]] = $("#sampleSpaceProject").val().replace(/\//g,'\/') + "_" + isCopyWithNewCode + "_EXP_RESULTS";
+				parameters["defaultBenchProperties"][defaultStoragePropertyGroup["USER_PROPERTY"]] = this.serverFacade.openbisServer.getSession().split("-")[0];
 			}
 			parameters["sampleChildrenNew"] = [];
 			parameters["sampleChildrenRemoved"] = [];
diff --git a/plasmid/source/core-plugins/newbrowser/1/dss/reporting-plugins/newbrowserapi/script.py b/plasmid/source/core-plugins/newbrowser/1/dss/reporting-plugins/newbrowserapi/script.py
index a505e9cdca6..923bad1657a 100644
--- a/plasmid/source/core-plugins/newbrowser/1/dss/reporting-plugins/newbrowserapi/script.py
+++ b/plasmid/source/core-plugins/newbrowser/1/dss/reporting-plugins/newbrowserapi/script.py
@@ -167,7 +167,7 @@ def copySample(tr, parameters, tableBuilder):
 	if sampleChildren != None:
 		for sampleChildIdentifier in sampleChildren:
 			child = tr.getSample(sampleChildIdentifier); #Retrieve Sample child to copy
-			copyChildCode = parameters.get("sampleCode") + "_" + child.getCode();
+			copyChildCode = parameters.get("sampleCode") + child.getCode()[child.getCode().index('_'):];
 			copyChildIdentifier = "/" + parameters.get("sampleSpace") + "/" + copyChildCode;
 			
 			# Create new sample children
@@ -179,11 +179,29 @@ def copySample(tr, parameters, tableBuilder):
 			propertiesDefinitions = searchService.listPropertiesDefinitionsForSampleType(child.getSampleType());
 			for propertyDefinition in propertiesDefinitions:
 				propCode = propertyDefinition.getPropertyTypeCode();
-				propValue = child.getPropertyValue(propCode);
+				propValue = getCopySampleChildrenPropertyValue(
+					propCode,
+					child.getPropertyValue(propCode),
+					parameters.get("notCopyProperties"),
+					parameters.get("defaultBenchPropertyList"),
+					parameters.get("defaultBenchProperties")
+				);
 				if propValue != None:
 					childCopy.setPropertyValue(propCode, propValue);
 			
 	return True;
+
+#This method is used to return the properties, deleting the storage ones and setting the default storage
+def getCopySampleChildrenPropertyValue(propCode, propValue, notCopyProperties, defaultBenchPropertyList, defaultBenchProperties):
+	isPropertyToSkip = any(propCode == s for s in notCopyProperties);
+	isDefaultBenchProperty = any(propCode == s for s in defaultBenchPropertyList);
+	print propCode + " " + str(isPropertyToSkip) + " " + str(isDefaultBenchProperty);
+	if isPropertyToSkip:
+		return None;
+	elif isDefaultBenchProperty:
+		return str(defaultBenchProperties[propCode]);
+	else:
+		return propValue;
 	
 def insertUpdateSample(tr, parameters, tableBuilder):
 	
-- 
GitLab