From ee7c04dd2f7e3a2c26f1dd81b85d72aedc3bd7bf Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Mon, 10 Nov 2014 12:51:41 +0000
Subject: [PATCH] SSDM-983 : PAPER - Annotations on Batch Import

SVN: 32766
---
 .../newbrowser/1/as/initialize-master-data.py |   2 +
 .../newbrowser/1/compatibility/managed.py     | 117 ++++++++++++++++--
 2 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py b/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py
index 8655da1e465..40b43b8e41c 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py
+++ b/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py
@@ -52,6 +52,7 @@ def addTermWithLabel(vocabulary, termCode, termLabel):
 def createSampleTypeWithProperties(sampleTypeCode, description, properties):
 	newSampleType = tr.getOrCreateNewSampleType(sampleTypeCode);
 	newSampleType.setDescription(description);
+	newSampleType.setShowParents(True);
 	newSampleType.setAutoGeneratedCode(True);
 	newSampleType.setGeneratedCodePrefix(sampleTypeCode[:3]);
 	addProperties(newSampleType, properties);
@@ -89,6 +90,7 @@ def addProperty(entity, propertyCode, section, propertyLabel, dataType, vocabula
 	propertyAssignment.setSection(section);
 	if managedScript != None:
 		propertyAssignment.setManaged(True);
+		propertyAssignment.setShownEdit(True);
 		propertyAssignment.setScriptName(managedScript);
 
 def createProperty(propertyCode, dataType, propertyLabel, propertyDescription, vocabularyCode):
diff --git a/plasmid/source/core-plugins/newbrowser/1/compatibility/managed.py b/plasmid/source/core-plugins/newbrowser/1/compatibility/managed.py
index eb26c1d5b52..de68800ec1b 100644
--- a/plasmid/source/core-plugins/newbrowser/1/compatibility/managed.py
+++ b/plasmid/source/core-plugins/newbrowser/1/compatibility/managed.py
@@ -3,7 +3,80 @@ from ch.systemsx.cisd.openbis.generic.server import CommonServiceProvider
 # Configuration
 # This needs to be edited for each sample type to match the Profile.js ANNOTATION_PROPERTIES map.
 configuration = {}
-#configuration["CHEMICAL"] = { "QUANTITY" : False, "COMMENTS" : False }
+configuration["MEDIA"] = {
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "MEDIA" : {"QUANTITY" : False, "COMMENTS" : False }
+                         };
+
+configuration["SOLUTION_BUFFER"] = {
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "MEDIA" : {"QUANTITY" : False, "COMMENTS" : False }
+                         };
+
+configuration["GENERAL_PROTOCOL"] = {
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "MEDIA" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "ENZYME" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "GENERAL_PROTOCOL" : {"COMMENTS" : False }
+                         };
+
+configuration["PCR_PROTOCOL"] = {
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "ENZYME" : {"QUANTITY" : False, "COMMENTS" : False }
+                         };
+
+configuration["WESTERN_BLOTTING_PROTOCOL"] = {
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "ANTIBODY" : {"QUANTITY" : False, "COMMENTS" : False }
+                         };
+
+configuration["PLASMID"] = {
+                          "PLASMID" : {"COMMENTS" : False }
+                         };
+
+configuration["BACTERIA"] = {
+                          "BACTERIA" : {"COMMENTS" : False },
+                          "PLASMID" : {"PLASMID_RELATIONSHIP" : False, "PLASMID_ANNOTATION" : False, "COMMENTS" : False }
+                         };
+
+configuration["YEAST"] = {
+                          "YEAST" : {"COMMENTS" : False },
+                          "PLASMID" : {"PLASMID_RELATIONSHIP" : False, "PLASMID_ANNOTATION" : False, "COMMENTS" : False }
+                         };
+
+configuration["CELL_LINE"] = {
+                          "CELL_LINE" : {"COMMENTS" : False },
+                          "PLASMID" : {"PLASMID_RELATIONSHIP" : False, "PLASMID_ANNOTATION" : False, "COMMENTS" : False },
+                          "FLY" : {"COMMENTS" : False }
+                         };
+
+configuration["FLY"] = {
+                          "FLY" : {"COMMENTS" : False },
+                          "PLASMID" : {"PLASMID_RELATIONSHIP" : False, "PLASMID_ANNOTATION" : False, "COMMENTS" : False }
+                         };
+
+configuration["EXPERIMENTAL_STEP"] = {
+                          "ANTIBODY" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "BACTERIA" : {"COMMENTS" : False },
+                          "CELL_LINE" : {"COMMENTS" : False },
+                          "CHEMICAL" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "ENZYME" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "FLY" : {"COMMENTS" : False },
+                          "MEDIA" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "OLIGO" : {"COMMENTS" : False },
+                          "PLASMID" : {"COMMENTS" : False },
+                          "RNA" : {"COMMENTS" : False },
+                          "SOLUTION_BUFFER" : {"QUANTITY" : False, "COMMENTS" : False },
+                          "YEAST" : {"COMMENTS" : False },
+                          "GENERAL_PROTOCOL" : {"COMMENTS" : False },
+                          "PCR_PROTOCOL" : {"COMMENTS" : False },
+                          "WESTERN_BLOTTING_PROTOCOL" : {"COMMENTS" : False }
+                         };
 
 #Global Variables
 server = CommonServiceProvider.getCommonServer()
@@ -13,6 +86,20 @@ propertyTypes = server.listPropertyTypes(contextOrNull.getSessionToken(), False)
 ##
 ## Help Methods
 ##
+def getAllAnnotableSampleTypes():
+    allTypes = {};
+    for sampleTypeWithAnnotations in configuration:
+        for sampleTypeWithAnnotationsForType in configuration[sampleTypeWithAnnotations]:
+                allTypes[sampleTypeWithAnnotationsForType] = True;
+    return allTypes;
+
+def getPropertyTypesForSampleTypeIgnoringCurrentType(sampleTypeCodeToFind):
+    for sampleTypeWithAnnotations in configuration:
+        for sampleTypeWithAnnotationsForType in configuration[sampleTypeWithAnnotations]:
+                if sampleTypeWithAnnotationsForType == sampleTypeCodeToFind:
+                        return configuration[sampleTypeWithAnnotations][sampleTypeWithAnnotationsForType];
+    return None;
+    
 def getPropertyType(propertyTypeCode):
     print "Searching property type: " + propertyTypeCode
     for propertyType in propertyTypes:
@@ -28,15 +115,20 @@ def createAnnotationsFor(permId, annotations):
 
 def getWidgetForAdd(sampleTypeCode):
     widgets = []
-    widget = inputWidgetFactory().createTextInputField("permId")\
+    widgetPermId = inputWidgetFactory().createTextInputField("permId")\
+                            .setMandatory(True)\
+                            .setValue("")\
+                            .setDescription("")
+    widgets.append(widgetPermId)
+    widgetCode = inputWidgetFactory().createTextInputField("code")\
                             .setMandatory(True)\
                             .setValue("")\
                             .setDescription("")
-    widgets.append(widget)
-    for propertyTypeCode in configuration[sampleTypeCode].keys():
+    widgets.append(widgetCode)
+    for propertyTypeCode in getPropertyTypesForSampleTypeIgnoringCurrentType(sampleTypeCode):
         propertyType = getPropertyType(propertyTypeCode)
         widget = inputWidgetFactory().createTextInputField(propertyType.label)\
-                        .setMandatory(configuration[sampleTypeCode][propertyTypeCode])\
+                        .setMandatory(getPropertyTypesForSampleTypeIgnoringCurrentType(sampleTypeCode)[propertyTypeCode])\
                         .setValue("")\
                         .setDescription(propertyType.description)
         widgets.append(widget)
@@ -49,13 +141,16 @@ def isValid(dataType, value):
 ## Help Methods
 ##
 def configureUI():
-    print "All property types: " + str(propertyTypes)
     # Add Headers
     tableBuilder = createTableBuilder()
     tableBuilder.addHeader("permId")
-    for sampleTypeCode in configuration.keys():
-        for propertyTypeCode in configuration[sampleTypeCode].keys():
-            tableBuilder.addHeader(propertyTypeCode)
+    tableBuilder.addHeader("code")
+    usedTableHeaders = {"permId" : True, "code" : True}
+    for sampleTypeCode in getAllAnnotableSampleTypes():
+        for propertyTypeCode in getPropertyTypesForSampleTypeIgnoringCurrentType(sampleTypeCode):
+            if propertyTypeCode not in usedTableHeaders:
+                tableBuilder.addHeader(propertyTypeCode)
+                usedTableHeaders[propertyTypeCode] = True
 
     property.setOwnTab(True)
     uiDescription = property.getUiDescription()
@@ -69,7 +164,7 @@ def configureUI():
             row.setCell(annotation, sample.getAttribute(annotation))
             
     # Add Create buttons
-    for sampleTypeCode in configuration.keys():
+    for sampleTypeCode in getAllAnnotableSampleTypes():
         title = "Add " + sampleTypeCode;
         addAction = uiDescription.addTableAction(title).setDescription(title)
         widgets = getWidgetForAdd(sampleTypeCode)
@@ -88,7 +183,7 @@ def updateFromUI(action):
         sampleTypeCode = action.name[4:]
         permId = action.getInputValue("permId")
         annotations = {}
-        for propertyTypeCode in configuration[sampleTypeCode]:
+        for propertyTypeCode in getPropertyTypesForSampleTypeIgnoringCurrentType(sampleTypeCode):
             propertyType = getPropertyType(propertyTypeCode)
             propertyTypeValue = action.getInputValue(propertyType.label)
             if not isValid(propertyType.dataType, propertyTypeValue):
-- 
GitLab