diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims-life-sciences/1/as/master-data/data-model.xls b/openbis_standard_technologies/dist/core-plugins/eln-lims-life-sciences/1/as/master-data/data-model.xls index 8b219a0b5747b886494c221c82bd3f3f1f470262..3ee993ae6e5fcd4df2a656c6551274769709d661 100644 Binary files a/openbis_standard_technologies/dist/core-plugins/eln-lims-life-sciences/1/as/master-data/data-model.xls and b/openbis_standard_technologies/dist/core-plugins/eln-lims-life-sciences/1/as/master-data/data-model.xls differ diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/master-data/data-model.xls b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/master-data/data-model.xls index 16332eb71f3a9ddbf34d818a04319e5fb81200c1..37c2bad5fbab86274c8b255a9d2fae259fbb991b 100644 Binary files a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/master-data/data-model.xls and b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/master-data/data-model.xls differ diff --git a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/entrypoint.py b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/entrypoint.py index 1f967741e87cee7d47323798c168d7866526cd8b..1f324a67b25e1605aa2cc5c1ec4fde6c329c2088 100644 --- a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/entrypoint.py +++ b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/entrypoint.py @@ -6,7 +6,7 @@ from ch.systemsx.cisd.openbis.generic.server import CommonServiceProvider from parsers import get_creations_from, get_definitions_from_xls, get_definitions_from_csv, get_creation_metadata_from, \ CreationOrUpdateToOperationParser, versionable_types from processors import OpenbisDuplicatesHandler, PropertiesLabelHandler, DuplicatesHandler, \ - unify_properties_representation_of + unify_properties_representation_of, validate_creations from search_engines import SearchEngine from utils import FileHandler from utils.openbis_utils import get_version_name_for, get_metadata_name_for @@ -77,6 +77,7 @@ def process(context, parameters): definitions = get_definitions_from_xls(xls_byte_arrays) definitions.extend(get_definitions_from_csv(csv_strings)) creations = get_creations_from(definitions, FileHandler(scripts)) + validate_creations(creations) creations_metadata = get_creation_metadata_from(definitions) creations = DuplicatesHandler.get_distinct_creations(creations) xls_version_filepath = get_property("xls-import.version-data-file", "../../../xls-import-version-info.json") diff --git a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/__init__.py b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/__init__.py index 4bf02ed2f60853c45dde046f96961ab7b0a0f090..7c32a00104eb924efb381e5a786c4149a3bf0c7a 100644 --- a/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/__init__.py +++ b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/__init__.py @@ -3,3 +3,4 @@ from .duplicates_handler import DuplicatesHandler from .properties_label_handler import PropertiesLabelHandler from .representation_unifier import unify_properties_representation_of from .version_handler import VersionHandler +from .creation_validator import validate_creations 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 new file mode 100644 index 0000000000000000000000000000000000000000..2cfd9572ee6f3fe8f6a92c3078db5be327694820 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/xls-import/1/as/services/xls-import-api/processors/creation_validator.py @@ -0,0 +1,43 @@ +from parsers import PropertyTypeDefinitionToCreationType +from ch.systemsx.cisd.common.exceptions import UserFailureException + + +def validate_creations(creations): + ''' + This validator checks for: + - whether property types with same code are all the same across xls + + It throws an exception if this is false. + ''' + if PropertyTypeDefinitionToCreationType not in creations: + return + property_type_creations = creations[PropertyTypeDefinitionToCreationType] + different_duplicates = set() + 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 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 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' + + raise UserFailureException(error_msg) diff --git a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/ImportPropertyTypesTest.java b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/ImportPropertyTypesTest.java index 3a1abfc3bdb230e54aefc0b1809e79bf917d533e..7db73a88f35d6717cc265e4b5ac14f73c75a1f3f 100644 --- a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/ImportPropertyTypesTest.java +++ b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/ImportPropertyTypesTest.java @@ -50,6 +50,10 @@ public class ImportPropertyTypesTest extends AbstractImportTest { private static final String PROPERTY_NON_VOCAB_TYPE_VOCABULARY_CODE = "property_types/vocabcode_when_not_vocabtype.xls"; + private static final String PROPERTY_DUPLICATES_DIFFERENT = "property_types/duplicates_different.xls"; + + private static final String PROPERTY_TYPES_DUPLICATES_SAME = "property_types/duplicates_same.xls"; + private static final String PROPERTY_VOCABULARY_ON_SERVER = "property_types/with_vocab_on_server.xls"; private static final String PROPERTY_VOCAB_TYPE = "property_types/with_vocab.xls"; @@ -98,6 +102,23 @@ public class ImportPropertyTypesTest extends AbstractImportTest { assertNull(notes.getVocabulary()); } + @Test + @DirtiesContext + public void testDuplicatesPropertiesAreAllowedIfTheyAreTheSame() throws IOException { + // GIVEN + TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_TYPES_DUPLICATES_SAME))); + // WHEN + PropertyType notes = TestUtils.getPropertyType(v3api, sessionToken, "NOTES"); + // THEN + assertEquals(notes.getCode(), "NOTES"); + assertEquals(notes.getLabel(), "Notes"); + assertEquals(notes.getDataType(), DataType.MULTILINE_VARCHAR); + assertEquals(notes.getDescription(), "Notes Descripton"); + assertFalse(notes.isInternalNameSpace()); + assertFalse(notes.isManagedInternally()); + assertNull(notes.getVocabulary()); + } + @Test(expectedExceptions = UserFailureException.class) public void testPropertyTypeNoCode() throws IOException { TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_NO_CODE))); @@ -108,6 +129,11 @@ public class ImportPropertyTypesTest extends AbstractImportTest { TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_NO_LABEL))); } + @Test(expectedExceptions = UserFailureException.class) + public void testPropertyTypesDuplicatesAreDifferent() throws IOException { + TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_DUPLICATES_DIFFERENT))); + } + @Test(expectedExceptions = UserFailureException.class) public void testPropertyTypeNoVocabularyCodeWhenVocabularyType() throws IOException { TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_VOCAB_TYPE_NO_VOCABULARY_CODE))); diff --git a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_different.xls b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_different.xls new file mode 100644 index 0000000000000000000000000000000000000000..81f20402fd34580406f2b52dc078df22f1e712bf Binary files /dev/null and b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_different.xls differ diff --git a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_same.xls b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_same.xls new file mode 100644 index 0000000000000000000000000000000000000000..35b3eb68daf6ab65fbe014d77afe51c26311a8db Binary files /dev/null and b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/duplicates_same.xls differ diff --git a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/normal_property_type.xls b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/normal_property_type.xls index b60b0d1af6c8bcc493e04f7ab025c2f30bcba1b4..eb22dc6e62a54f32184abf1b8c37691847f17000 100644 Binary files a/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/normal_property_type.xls and b/openbis_standard_technologies/sourceTest/java/ch/ethz/sis/openbis/systemtest/plugin/excelimport/test_files/property_types/normal_property_type.xls differ