Skip to content
Snippets Groups Projects
Commit 5280256f authored by Cezary Czernecki's avatar Cezary Czernecki
Browse files

SSDM-8714 duplicated properties errors will produce exception if are not the same

parent daa8c76e
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 1 deletion
No preview for this file type
...@@ -6,7 +6,7 @@ from ch.systemsx.cisd.openbis.generic.server import CommonServiceProvider ...@@ -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, \ from parsers import get_creations_from, get_definitions_from_xls, get_definitions_from_csv, get_creation_metadata_from, \
CreationOrUpdateToOperationParser, versionable_types CreationOrUpdateToOperationParser, versionable_types
from processors import OpenbisDuplicatesHandler, PropertiesLabelHandler, DuplicatesHandler, \ from processors import OpenbisDuplicatesHandler, PropertiesLabelHandler, DuplicatesHandler, \
unify_properties_representation_of unify_properties_representation_of, validate_creations
from search_engines import SearchEngine from search_engines import SearchEngine
from utils import FileHandler from utils import FileHandler
from utils.openbis_utils import get_version_name_for, get_metadata_name_for from utils.openbis_utils import get_version_name_for, get_metadata_name_for
...@@ -77,6 +77,7 @@ def process(context, parameters): ...@@ -77,6 +77,7 @@ def process(context, parameters):
definitions = get_definitions_from_xls(xls_byte_arrays) definitions = get_definitions_from_xls(xls_byte_arrays)
definitions.extend(get_definitions_from_csv(csv_strings)) definitions.extend(get_definitions_from_csv(csv_strings))
creations = get_creations_from(definitions, FileHandler(scripts)) creations = get_creations_from(definitions, FileHandler(scripts))
validate_creations(creations)
creations_metadata = get_creation_metadata_from(definitions) creations_metadata = get_creation_metadata_from(definitions)
creations = DuplicatesHandler.get_distinct_creations(creations) creations = DuplicatesHandler.get_distinct_creations(creations)
xls_version_filepath = get_property("xls-import.version-data-file", "../../../xls-import-version-info.json") xls_version_filepath = get_property("xls-import.version-data-file", "../../../xls-import-version-info.json")
......
...@@ -3,3 +3,4 @@ from .duplicates_handler import DuplicatesHandler ...@@ -3,3 +3,4 @@ from .duplicates_handler import DuplicatesHandler
from .properties_label_handler import PropertiesLabelHandler from .properties_label_handler import PropertiesLabelHandler
from .representation_unifier import unify_properties_representation_of from .representation_unifier import unify_properties_representation_of
from .version_handler import VersionHandler from .version_handler import VersionHandler
from .creation_validator import validate_creations
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)
...@@ -50,6 +50,10 @@ public class ImportPropertyTypesTest extends AbstractImportTest { ...@@ -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_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_VOCABULARY_ON_SERVER = "property_types/with_vocab_on_server.xls";
private static final String PROPERTY_VOCAB_TYPE = "property_types/with_vocab.xls"; private static final String PROPERTY_VOCAB_TYPE = "property_types/with_vocab.xls";
...@@ -98,6 +102,23 @@ public class ImportPropertyTypesTest extends AbstractImportTest { ...@@ -98,6 +102,23 @@ public class ImportPropertyTypesTest extends AbstractImportTest {
assertNull(notes.getVocabulary()); 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) @Test(expectedExceptions = UserFailureException.class)
public void testPropertyTypeNoCode() throws IOException { public void testPropertyTypeNoCode() throws IOException {
TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_NO_CODE))); TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_NO_CODE)));
...@@ -108,6 +129,11 @@ public class ImportPropertyTypesTest extends AbstractImportTest { ...@@ -108,6 +129,11 @@ public class ImportPropertyTypesTest extends AbstractImportTest {
TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_NO_LABEL))); 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) @Test(expectedExceptions = UserFailureException.class)
public void testPropertyTypeNoVocabularyCodeWhenVocabularyType() throws IOException { public void testPropertyTypeNoVocabularyCodeWhenVocabularyType() throws IOException {
TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_VOCAB_TYPE_NO_VOCABULARY_CODE))); TestUtils.createFrom(v3api, sessionToken, Paths.get(FilenameUtils.concat(FILES_DIR, PROPERTY_VOCAB_TYPE_NO_VOCABULARY_CODE)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment