From cc51347d9854c52f70d71fcee0f75b5af0811f24 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Wed, 23 Jul 2014 09:24:53 +0000
Subject: [PATCH] SSDM-623: Copy parents and children when duplicating
 subexperiments/samples (ongoing work).

SVN: 32127
---
 .../reporting-plugins/newbrowserapi/script.py    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

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 8358b8c0eee..a505e9cdca6 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
@@ -166,15 +166,23 @@ def copySample(tr, parameters, tableBuilder):
 	#Copy children and attach to Sample
 	if sampleChildren != None:
 		for sampleChildIdentifier in sampleChildren:
-			child = tr.getSampleForUpdate(sampleChildIdentifier); #Retrieve Sample child to copy
+			child = tr.getSample(sampleChildIdentifier); #Retrieve Sample child to copy
 			copyChildCode = parameters.get("sampleCode") + "_" + child.getCode();
 			copyChildIdentifier = "/" + parameters.get("sampleSpace") + "/" + copyChildCode;
 			
 			# Create new sample children
-			child = tr.createNewSample(copyChildIdentifier, child.getSampleType()); #Create Sample given his id
-			childParents = child.getParentSampleIdentifiers();
+			childCopy = tr.createNewSample(copyChildIdentifier, child.getSampleType()); #Create Sample given his id
+			childParents = childCopy.getParentSampleIdentifiers();
 			childParents.add(sampleIdentifier);
-			child.setParentSampleIdentifiers(childParents);
+			childCopy.setParentSampleIdentifiers(childParents);
+			searchService = tr.getSearchService();
+			propertiesDefinitions = searchService.listPropertiesDefinitionsForSampleType(child.getSampleType());
+			for propertyDefinition in propertiesDefinitions:
+				propCode = propertyDefinition.getPropertyTypeCode();
+				propValue = child.getPropertyValue(propCode);
+				if propValue != None:
+					childCopy.setPropertyValue(propCode, propValue);
+			
 	return True;
 	
 def insertUpdateSample(tr, parameters, tableBuilder):
-- 
GitLab