From e5bf82ac5ba49716f5715b2ec2ce76ae23418404 Mon Sep 17 00:00:00 2001
From: Cezary Czernecki <ccezary@ethz.ch>
Date: Fri, 6 Sep 2019 15:36:55 +0200
Subject: [PATCH] fix for displaying duplicated values

---
 .../processors/creation_validator.py          | 32 +++++++++++--------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/creation_validator.py b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/creation_validator.py
index 2cfd9572ee6..ca81778bffb 100644
--- a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/creation_validator.py
+++ b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/creation_validator.py
@@ -6,38 +6,44 @@ def validate_creations(creations):
     '''
         This validator checks for:
          - whether property types with same code are all the same across xls
+         - If allowed entries align with creations about to be made
 
         It throws an exception if this is false.
     '''
     if PropertyTypeDefinitionToCreationType not in creations:
         return
     property_type_creations = creations[PropertyTypeDefinitionToCreationType]
-    different_duplicates = set()
+    different_duplicates = {}
     for property_type in property_type_creations:
         for second_property_type in property_type_creations:
             if property_type.code == second_property_type.code:
                 difference_info = {}
                 attributes_to_check = ['label', 'description', 'dataType', 'internalNameSpace', 'vocabularyId',
                                        'metaData']
-                not_equal_attributes_pairs = set()
                 for attribute in attributes_to_check:
                     attribute_of_property_type = getattr(property_type, attribute)
                     attribute_of_second_property_type = getattr(second_property_type, attribute)
                     if attribute_of_property_type != attribute_of_second_property_type:
-                        not_equal_attributes_pairs.add(
-                            frozenset([attribute_of_property_type, attribute_of_second_property_type]))
+                        if attribute not in difference_info:
+                            difference_info[attribute] = []
+                        attribute_pair = [str(attribute_of_property_type), str(attribute_of_second_property_type)]
+                        difference_info[attribute].extend(attribute_pair)
 
-                if not_equal_attributes_pairs:
-                    difference_info['Property Label'] = property_type.code
-                    difference_info['errors'] = not_equal_attributes_pairs
-                    different_duplicates.add((property_type.code, frozenset(not_equal_attributes_pairs)))
+                if difference_info:
+                    if property_type.code not in different_duplicates:
+                        different_duplicates[property_type.code] = {}
+                    for key in difference_info:
+                        if key not in different_duplicates[property_type.code]:
+                            different_duplicates[property_type.code][key] = set(difference_info[key])
+                        else:
+                            different_duplicates[property_type.code][key].update(difference_info[key])
 
     if different_duplicates:
         error_msg = "Following property types have ambiguous definition: \n" + \
-                    '\n'.join(
-                        ['Property Code: ' + str(diff_info[0]) + '\n' + '\n'.join(
-                            [' != '.join(['"' + attribute_value + '"' for attribute_value in duplicates_attributes])
-                             for duplicates_attributes in diff_info[1]])
-                         for diff_info in different_duplicates]) + '\n'
+                    '\n'.join(['Property Code: ' + str(code) + '\n' + '\n'.join(
+                        ["Attribute with difference: " + attr_name + ", has following values: " + '\n' + ', '.join(
+                            ['"' + str(attribute_value) + '"' for attribute_value in duplicates_attributes])
+                         for attr_name, duplicates_attributes in diff_info.items()]) for code, diff_info in
+                               different_duplicates.items()]) + '\n'
 
         raise UserFailureException(error_msg)
-- 
GitLab