def _construct_attribute_context_tree(
            self,
            proj_ctx: 'ProjectionContext',
            set_attr_ctx: Optional[bool] = False) -> None:
        """
        Takes all the stored attribute context parameters, creates attribute contexts from them, and then constructs the tree.
        :param proj_ctx: The projection context
        :param set_attr_ctx: Whether to set the created attribute context on the associated resolved attribute
        """

        # Iterate over all the search_for attribute context parameters
        for search_for_attr_ctx_param in self._search_for_to_search_for_attr_ctx_param.values(
        ):
            search_for_attr_ctx = None

            # Fetch all the found attribute context parameters associated with this search_for
            found_attr_ctx_params = self._search_for_attr_ctx_param_to_found_attr_ctx_param[
                search_for_attr_ctx_param]

            # Iterate over all the found attribute context parameters
            for found_attr_ctx_param in found_attr_ctx_params:
                # We should only create the search_for node when search_for and found have different names. Else collapse the nodes together.
                if not StringUtils.equals_with_case(
                        search_for_attr_ctx_param._name,
                        found_attr_ctx_param._name):
                    # Create the attribute context for searchFor if it hasn't been created already and set it as the parent of found
                    if search_for_attr_ctx is None:
                        search_for_attr_ctx = CdmAttributeContext._create_child_under(
                            proj_ctx._projection_directive._res_opt,
                            search_for_attr_ctx_param)
                    found_attr_ctx_param._under = search_for_attr_ctx

                # Fetch the action attribute context parameter associated with this found
                action_attr_ctx_param = self._found_attr_ctx_param_to_action_attr_ctx_param[
                    found_attr_ctx_param]

                # We should only create the found node when found and action have different names. Else collapse the nodes together.
                if not StringUtils.equals_with_case(
                        found_attr_ctx_param._name,
                        action_attr_ctx_param._name):
                    # Create the attribute context for found and set it as the parent of action
                    found_attr_ctx = CdmAttributeContext._create_child_under(
                        proj_ctx._projection_directive._res_opt,
                        found_attr_ctx_param)
                    action_attr_ctx_param._under = found_attr_ctx

                # Create the attribute context for action
                action_attr_ctx = CdmAttributeContext._create_child_under(
                    proj_ctx._projection_directive._res_opt,
                    action_attr_ctx_param)

                # Fetch the resolved attribute that should now point at this action attribute context
                res_attr_from_action = self._action_attr_ctx_param_to_res_attr[
                    action_attr_ctx_param]

                # TODO (jibyun): For now, only set the created attribute context on the resolved attribute when specified to,
                # as pointing the resolved attribute at this attribute context won't work currently for certain operations (Include/Exclude).
                # This will be changed to always run once we work on the attribute context fix.
                if set_attr_ctx:
                    res_attr_from_action.att_ctx = action_attr_ctx
Example #2
0
    def to_data(instance: CdmImport, res_opt: ResolveOptions,
                options: CopyOptions) -> Import:
        result = Import()
        if not StringUtils.is_blank_by_cdm_standard(instance.corpus_path):
            result.corpusPath = instance.corpus_path
        if not StringUtils.is_blank_by_cdm_standard(instance.moniker):
            result.moniker = instance.moniker

        return result
Example #3
0
    def create_adapter_with_shared_key(self, root_relative_path: str = None):
        hostname = os.environ.get("ADLS_HOSTNAME")
        root_path = os.environ.get("ADLS_ROOTPATH")
        shared_key = os.environ.get("ADLS_SHAREDKEY")

        self.assertFalse(StringUtils.is_null_or_white_space(hostname), "ADLS_HOSTNAME environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(root_path), "ADLS_ROOTPATH environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(shared_key), "ADLS_SHAREDKEY environment variable not set up")

        adapter = ADLSAdapter(hostname=hostname, root=self.combine_path(root_path, root_relative_path), shared_key=shared_key)

        return adapter
    def _get_new_attribute_name(self, attribute_state: 'ProjectionAttributeState', source_attribute_name: str):
        current_attribute_name = attribute_state._current_resolved_attribute._resolved_name
        ordinal = str(attribute_state._ordinal) if attribute_state._ordinal is not None else ''

        if not self.rename_format:
            logger.error(self._TAG, self.ctx, 'RenameFormat should be set for this operation to work.')
            return ''

        attribute_name = StringUtils._replace(self.rename_format, 'a', source_attribute_name)
        attribute_name = StringUtils._replace(attribute_name, 'o', ordinal)
        attribute_name = StringUtils._replace(attribute_name, 'm', current_attribute_name)

        return attribute_name
Example #5
0
    def create_adapter_with_client_id(self, root_relative_path: str = None):
        hostname = os.environ.get("ADLS_HOSTNAME")
        root_path = os.environ.get("ADLS_ROOTPATH")
        tenant = os.environ.get("ADLS_TENANT")
        client_id = os.environ.get("ADLS_CLIENTID")
        client_secret = os.environ.get("ADLS_CLIENTSECRET")

        self.assertFalse(StringUtils.is_null_or_white_space(hostname), "ADLS_HOSTNAME environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(root_path), "ADLS_ROOTPATH environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(tenant), "ADLS_TENANT environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(client_id), "ADLS_CLIENTID environment variable not set up")
        self.assertFalse(StringUtils.is_null_or_white_space(client_secret), "ADLS_CLIENTSECRET environment variable not set up")

        adapter = ADLSAdapter(hostname=hostname, root=self.combine_path(root_path, root_relative_path), tenant=tenant, client_id=client_id, secret=client_secret)

        return adapter
Example #6
0
    def from_data(
            ctx: 'CdmCorpusContext', data: 'OperationCombineAttributes'
    ) -> 'CdmOperationCombineAttributes':
        if not data:
            return None

        combine_attributes_op = ctx.corpus.make_object(
            CdmObjectType.OPERATION_COMBINE_ATTRIBUTES_DEF)

        if data.type and not StringUtils.equals_with_ignore_case(
                data.type,
                OperationTypeConvertor._operation_type_to_string(
                    CdmOperationType.COMBINE_ATTRIBUTES)):
            logger.error(
                _TAG, ctx,
                '$type {} is invalid for this operation.'.format(data.type))
        else:
            combine_attributes_op.type = CdmOperationType.COMBINE_ATTRIBUTES

        if data.explanation:
            combine_attributes_op.explanation = data.explanation

        combine_attributes_op.take = data.take
        combine_attributes_op.merge_into = utils.create_attribute(
            ctx, data.mergeInto)

        return combine_attributes_op
Example #7
0
    async def from_data(
        ctx: 'CdmCorpusContext', data: 'LocalEntity',
        extension_trait_def_list: List['CdmTraitDefinition'],
        local_extension_trait_def_list: List['CdmTraitDefinition']
    ) -> Optional['CdmEntityDefinition']:
        entity = ctx.corpus.make_object(CdmObjectType.ENTITY_DEF, data.name)

        if not StringUtils.is_blank_by_cdm_standard(data.get('description')):
            entity.description = data.description

        await utils.process_annotations_from_data(ctx, data,
                                                  entity.exhibits_traits)

        for element in (data.get('attributes') or []):
            type_attribute = await TypeAttributePersistence.from_data(
                ctx, element, extension_trait_def_list,
                local_extension_trait_def_list)
            if type_attribute is not None:
                entity.attributes.append(type_attribute)
            else:
                logger.error(
                    ctx, EntityPersistence.__name__,
                    EntityPersistence.from_data.__name__,
                    element.at_corpus_path, CdmLogCode.
                    ERR_PERSIST_MODELJSON_TO_ATTR_CONVERSION_FAILURE)
                return

        extension_helper.process_extension_from_json(
            ctx, data, entity.exhibits_traits, extension_trait_def_list,
            local_extension_trait_def_list)

        return entity
Example #8
0
    def update_config(self, config: str):
        configs_json = json.loads(config)

        if configs_json.get('root'):
            self.root = configs_json['root']
        else:
            raise ValueError('Root has to be set for ADLS adapter.')

        if configs_json.get('hostname'):
            self.hostname = configs_json['hostname']
        else:
            raise ValueError('Hostname has to be set for ADLS adapter.')

        self.update_network_config(config)

        if configs_json.get('tenant') and configs_json.get('clientId'):
            self._tenant = configs_json['tenant']
            self.client_id = configs_json['clientId']

            # To keep backwards compatibility with config files that were generated before the introduction of the `endpoint` property.
            if not hasattr(self, 'endpoint') or not self.endpoint:
                self.endpoint = AzureCloudEndpoint.AZURE_PUBLIC

        if configs_json.get('locationHint'):
            self.location_hint = configs_json['locationHint']

        if configs_json.get('endpoint'):
            endpoint_from_config = StringUtils.pascal_case_to_snake_case(
                configs_json['endpoint'])
            if endpoint_from_config in AzureCloudEndpoint.__members__.keys():
                self.endpoint = AzureCloudEndpoint[endpoint_from_config]
            else:
                raise ValueError(
                    'Endpoint value should be a string of an enumeration value from the class AzureCloudEndpoint in Pascal case.'
                )
Example #9
0
    def from_data(
            ctx: 'CdmCorpusContext',
            data: 'OperationArrayExpansion') -> 'CdmOperationArrayExpansion':
        if not data:
            return None

        array_expansion_op = ctx.corpus.make_object(
            CdmObjectType.OPERATION_ARRAY_EXPANSION_DEF)

        if data.type and not StringUtils.equals_with_ignore_case(
                data.type,
                OperationTypeConvertor._operation_type_to_string(
                    CdmOperationType.ARRAY_EXPANSION)):
            logger.error(
                _TAG, ctx,
                '$type {} is invalid for this operation.'.format(data.type))
        else:
            array_expansion_op.type = CdmOperationType.ARRAY_EXPANSION

        if data.explanation:
            array_expansion_op.explanation = data.explanation

        array_expansion_op.start_ordinal = data.startOrdinal
        array_expansion_op.end_ordinal = data.endOrdinal

        return array_expansion_op
    def _build_structure(curr: 'ProjectionAttributeState',
                         top: 'ProjectionAttributeState', attr_name: str,
                         st: 'SearchStructure', found_flag: bool,
                         found_depth: int) -> 'SearchStructure':
        """Build a structure using a stack"""
        if curr:
            st._add(curr)

            if StringUtils.equals_with_case(
                    curr._current_resolved_attribute.resolved_name, attr_name):
                found_flag = True
                st._result.found_flag = True
                st._result.found_depth = found_depth
                st._result.found = curr

            if found_flag and (curr and
                               (curr._previous_state_list is None or
                                (curr._previous_state_list is not None
                                 and len(curr._previous_state_list) == 0))):
                st._result.leaf.append(curr)

            if curr._previous_state_list and len(
                    curr._previous_state_list) > 0:
                for prev in curr._previous_state_list:
                    SearchStructure._build_structure(prev, top, attr_name, st,
                                                     found_flag,
                                                     found_depth + 1)

        return st
Example #11
0
    def from_data(ctx: 'CdmCorpusContext', object_type: 'CdmObjectType',
                  data: 'OperationBase'):
        if data is None:
            return None

        operation = ctx.corpus.make_object(
            object_type)  # type: CdmOperationBase
        operation_type = OperationTypeConvertor._from_object_type(
            object_type)  # type: CdmOperationType
        operation_name = OperationTypeConvertor._operation_type_to_string(
            CdmOperationType.COMBINE_ATTRIBUTES)
        if data.type and not StringUtils.equals_with_ignore_case(
                data.type, operation_name):
            logger.error(ctx, operation_name,
                         OperationBasePersistence.from_data.__name__, None,
                         CdmLogCode.ERR_PERSIST_PROJ_INVALID_OPS_TYPE,
                         data.type)
        else:
            operation.type = operation_type

        operation.condition = data.condition
        operation.explanation = data.explanation
        operation.source_input = data.sourceInput

        return operation
Example #12
0
File: adls.py Project: minettes/CDM
    def fetch_config(self) -> str:
        result_config = {'type': self._type}

        config_object = {
            'hostname': self.hostname,
            'root': self.root
        }

        # Check for clientId auth, we won't write shared key or secrets to JSON.
        if self.client_id and self.tenant:
            config_object['tenant'] = self.tenant
            config_object['clientId'] = self.client_id

        # Try constructing network configs.
        config_object.update(self.fetch_network_config())

        if self.location_hint:
            config_object['locationHint'] = self.location_hint

        if self.endpoint:
            config_object['endpoint'] = StringUtils.snake_case_to_pascal_case(self.endpoint.name)

        result_config['config'] = config_object

        return json.dumps(result_config)
Example #13
0
    def from_data(
        ctx: 'CdmCorpusContext', data: 'OperationAddSupportingAttribute'
    ) -> 'CdmOperationAddSupportingAttribute':
        if not data:
            return None

        add_supporting_attribute_op = ctx.corpus.make_object(
            CdmObjectType.OPERATION_ADD_SUPPORTING_ATTRIBUTE_DEF)

        if data.type and not StringUtils.equals_with_ignore_case(
                data.type,
                OperationTypeConvertor._operation_type_to_string(
                    CdmOperationType.ADD_SUPPORTING_ATTRIBUTE)):
            logger.error(
                _TAG, ctx,
                '$type {} is invalid for this operation.'.format(data.type))
        else:
            add_supporting_attribute_op.type = CdmOperationType.ADD_SUPPORTING_ATTRIBUTE

        if data.explanation:
            add_supporting_attribute_op.explanation = data.explanation

        if data.supportingAttribute:
            add_supporting_attribute_op.supporting_attribute = utils.create_attribute(
                ctx, data.supportingAttribute)

        return add_supporting_attribute_op
    def from_data(
            ctx: 'CdmCorpusContext', data: 'OperationIncludeAttributes'
    ) -> 'CdmOperationIncludeAttributes':
        if not data:
            return None

        include_attributes_op = ctx.corpus.make_object(
            CdmObjectType.OPERATION_INCLUDE_ATTRIBUTES_DEF)

        if data.type and not StringUtils.equals_with_ignore_case(
                data.type,
                OperationTypeConvertor._operation_type_to_string(
                    CdmOperationType.INCLUDE_ATTRIBUTES)):
            logger.error(
                _TAG, ctx,
                '$type {} is invalid for this operation.'.format(data.type))
        else:
            include_attributes_op.type = CdmOperationType.INCLUDE_ATTRIBUTES

        if data.explanation:
            include_attributes_op.explanation = data.explanation

        include_attributes_op.include_attributes = data.includeAttributes

        return include_attributes_op
Example #15
0
    async def test_model_json_data_partition_location_consistency(self):
        '''
            Testing whether DataPartition Location is consistently populated when:
             1. Manifest is read directly.
             2. Manifest is obtained by converting a model.json.
        '''
        test_name = 'test_model_json_data_partition_location_consistency'
        test_name_in_pascal_case = StringUtils.snake_case_to_pascal_case(test_name)
        cdm_corpus = TestHelper.get_local_corpus(self.tests_subpath, test_name)
        manifest_read = await cdm_corpus.fetch_object_async('default.manifest.cdm.json', cdm_corpus.storage.fetch_root_folder('local'))
        self.assertEqual('EpisodeOfCare/partition-data.csv', manifest_read.entities[0].data_partitions[0].location)

        converted_to_model_json = await ManifestPersistence.to_data(manifest_read, None, None)
        location = converted_to_model_json.entities[0]['partitions'][0]['location']  # type: str
        location_path = os.path.join('TestData', 'Persistence', 'ModelJson', 'DataPartition', test_name_in_pascal_case, 'Input', 'EpisodeOfCare', 'partition-data.csv')
        # Model Json uses absolute adapter path.
        self.assertTrue(location.find(location_path) != -1)

        cdm_corpus2 = TestHelper.get_local_corpus(self.tests_subpath, test_name)
        manifest_after_convertion = await ManifestPersistence.from_object(cdm_corpus2.ctx, converted_to_model_json, cdm_corpus2.storage.fetch_root_folder('local'))
        self.assertEqual('EpisodeOfCare/partition-data.csv', manifest_after_convertion.entities[0].data_partitions[0].location)

        # TODO: Need to change path in C#
        cdm_corpus3 = TestHelper.get_local_corpus(self.tests_subpath, test_name)
        read_file = TestHelper.get_input_file_content(self.tests_subpath, test_name, 'model.json')
        namespace_folder = cdm_corpus3.storage.fetch_root_folder('local')
        location_path3 = 'C:\\\\cdm\\\\testData\\\\Persistence\\\\ModelJson\\\\DataPartition\\\\TestModelJsonDataPartitionLocationConsistency\\\\Input\\\\EpisodeOfCare\\\\partition-data.csv'
        model_json_as_string = read_file.replace('\uFEFF', '').replace(location_path3, location.replace('\\', '\\\\'))

        manifest_read_from_model_json = await ManifestPersistence.from_object(cdm_corpus3.ctx, Model().decode(model_json_as_string), namespace_folder)
        self.assertEqual('EpisodeOfCare/partition-data.csv', manifest_read_from_model_json.entities[0].data_partitions[0].location)
Example #16
0
File: adls.py Project: minettes/CDM
    def hostname(self, value: str):
        if StringUtils.is_null_or_white_space(value):
            raise ValueError('Hostname cannot be null or whitespace.')

        self._hostname = value
        self._formatted_hostname = self._format_hostname(self.hostname)
        self._formatted_hostname_no_protocol = self._format_hostname(self._remove_protocol_from_hostname(self._hostname))
Example #17
0
    async def to_data(document_object_or_path: Union[CdmDocumentDefinition,
                                                     str],
                      manifest: 'CdmManifestDefinition',
                      res_opt: 'ResolveOptions', options: 'CopyOptions',
                      ctx: 'CdmCorpusContext') -> Optional['LocalEntity']:
        if isinstance(document_object_or_path, str):
            # Fetch the document from entity schema.
            cdm_entity = await ctx.corpus.fetch_object_async(
                document_object_or_path, manifest)

            if not isinstance(cdm_entity, CdmEntityDefinition):
                logger.error(ctx, DocumentPersistence.__name__,
                             DocumentPersistence.to_data.__name__,
                             manifest.at_corpus_path,
                             CdmLogCode.ERR_INVALID_CAST,
                             document_object_or_path, 'CdmEntityDefinition')
                return None
            if not cdm_entity:
                logger.error(ctx, DocumentPersistence.__name__,
                             DocumentPersistence.to_data.__name__,
                             manifest.at_corpus_path,
                             CdmLogCode.ERR_PERSIST_CDM_ENTITY_FETCH_ERROR)
                return None

            entity = await EntityPersistence.to_data(cdm_entity, res_opt,
                                                     options, ctx)
            if cdm_entity.owner and cdm_entity.owner.object_type == CdmObjectType.DOCUMENT_DEF:
                document = cdm_entity.owner  # type: CdmDocumentDefinition
                entity.imports = []
                for element in document.imports:
                    imp = CdmImportPersistence.to_data(element, res_opt,
                                                       options)
                    # the corpus path in the imports are relative to the document where it was defined.
                    # when saving in model.json the documents are flattened to the manifest level
                    # so it is necessary to recalculate the path to be relative to the manifest.
                    absolute_path = ctx.corpus.storage.create_absolute_corpus_path(
                        imp.corpusPath, document)

                    if not StringUtils.is_blank_by_cdm_standard(
                            document._namespace) and absolute_path.startswith(
                                document._namespace + ':'):
                        absolute_path = absolute_path[len(document._namespace
                                                          ) + 1:]

                    imp.corpusPath = ctx.corpus.storage.create_relative_corpus_path(
                        absolute_path, manifest)
                    entity.imports.append(imp)
            else:
                logger.warning(ctx, _TAG, DocumentPersistence.to_data.__name__,
                               manifest.at_corpus_path,
                               CdmLogCode.WARN_PERSIST_ENTITY_MISSING,
                               cdm_entity.get_name())
            return entity
        else:
            # TODO: Do something else when document_object_or_path is an object.
            pass
Example #18
0
    def _construct_attribute_context_tree(
            self, proj_ctx: 'ProjectionContext') -> None:
        """
        Takes all the stored attribute context parameters, creates attribute contexts from them, and then constructs the tree.
        :param proj_ctx: The projection context
        """

        # Iterate over all the search_for attribute context parameters
        for search_for_attr_ctx_param in self._search_for_to_search_for_attr_ctx_param.values(
        ):
            # Fetch all the found attribute context parameters associated with this search_for
            found_attr_ctx_params = self._search_for_attr_ctx_param_to_found_attr_ctx_param[
                search_for_attr_ctx_param]

            # Iterate over all the found attribute context parameters
            for found_attr_ctx_param in found_attr_ctx_params:
                # Fetch the action attribute context parameter associated with this found
                action_attr_ctx_param = self._found_attr_ctx_param_to_action_attr_ctx_param[
                    found_attr_ctx_param]

                # We should only create the found node when found and action have different names. Else collapse the nodes together.
                if not StringUtils.equals_with_case(
                        found_attr_ctx_param._name,
                        action_attr_ctx_param._name):
                    # Create the attribute context for found and set it as the parent of action
                    found_attr_ctx = CdmAttributeContext._create_child_under(
                        proj_ctx._projection_directive._res_opt,
                        found_attr_ctx_param)
                    action_attr_ctx_param._under = found_attr_ctx

                # Create the attribute context for action
                action_attr_ctx = CdmAttributeContext._create_child_under(
                    proj_ctx._projection_directive._res_opt,
                    action_attr_ctx_param)

                # Fetch the resolved attribute that should now point at this action attribute context
                res_attr_from_action = self._action_attr_ctx_param_to_res_attr.get(
                    action_attr_ctx_param, None)

                # make sure the lineage of the attribute stays linked up
                # there can be either (or both) a lineageOut and a lineageIn.
                # out lineage is where this attribute came from
                # in lineage should be pointing back at this context as a source
                lineage_out = self._action_attr_ctx_param_to_lineage_out.get(
                    action_attr_ctx_param, None)  # type: CdmAttributeContext
                if lineage_out:
                    if action_attr_ctx:
                        action_attr_ctx._add_lineage(lineage_out)
                    res_attr_from_action.att_ctx = action_attr_ctx  # probably the right context for this resAtt, unless ...

                lineage_in = self._action_attr_ctx_param_to_lineage_in.get(
                    action_attr_ctx_param, None)  # type: CdmAttributeContext
                if lineage_in:
                    if action_attr_ctx:
                        lineage_in._add_lineage(action_attr_ctx)
                    res_attr_from_action.att_ctx = lineage_in  # if there is a lineageIn. it points to us as lineage, so it is best
Example #19
0
    def get_test_folder_path(test_subpath: str, test_name: str, folder_name: str,
                             is_language_specific: Optional[bool] = False):
        test_name = StringUtils.snake_case_to_pascal_case(test_name)
        test_folder_path = os.path.join('..', 'TestData', test_subpath, test_name, folder_name, 'Python') \
            if is_language_specific else os.path.join('..', 'TestData', test_subpath, test_name,
                                                      folder_name)

        if folder_name == ACTUAL_OUTPUT_FOLDER_NAME and not os.path.isdir(test_folder_path):
            os.makedirs(test_folder_path, exist_ok=True)

        return test_folder_path
Example #20
0
    def from_data(ctx: CdmCorpusContext, obj: Import) -> CdmImport:
        imp = ctx.corpus.make_object(CdmObjectType.IMPORT)
        corpus_path = obj.get('corpusPath')

        if StringUtils.is_blank_by_cdm_standard(corpus_path):
            corpus_path = obj.uri

        imp.corpus_path = corpus_path
        imp.moniker = obj.get('moniker')

        return imp
Example #21
0
    def to_data(instance: 'CdmE2ERelationship', res_opt: ResolveOptions,
                options: CopyOptions) -> E2ERelationship:
        relationship = E2ERelationship()
        if not StringUtils.is_null_or_white_space(instance.relationship_name):
            relationship.name = instance.relationship_name
        relationship.fromEntity = instance.from_entity
        relationship.fromEntityAttribute = instance.from_entity_attribute
        relationship.toEntity = instance.to_entity
        relationship.toEntityAttribute = instance.to_entity_attribute

        return relationship
    def _get_new_attribute_name(self,
                                attribute_state: 'ProjectionAttributeState',
                                source_attribute_name: str):
        current_attribute_name = attribute_state._current_resolved_attribute._resolved_name
        ordinal = str(attribute_state._ordinal
                      ) if attribute_state._ordinal is not None else ''

        if not self.rename_format:
            logger.error(self.ctx, self._TAG,
                         self.getNewAttributeName.__name__,
                         self.at_corpus_path,
                         CdmLogCode.ERR_PROJ_RENAME_FORMAT_IS_NOT_SET)
            return ''

        attribute_name = StringUtils._replace(self.rename_format, 'a',
                                              source_attribute_name)
        attribute_name = StringUtils._replace(attribute_name, 'o', ordinal)
        attribute_name = StringUtils._replace(attribute_name, 'm',
                                              current_attribute_name)

        return attribute_name
Example #23
0
    def from_data(ctx: CdmCorpusContext,
                  data: E2ERelationship) -> CdmE2ERelationship:
        relationship = ctx.corpus.make_object(
            CdmObjectType.E2E_RELATIONSHIP_DEF)
        if not StringUtils.is_null_or_white_space(data.name):
            relationship.relationship_name = data.name
        relationship.from_entity = data.fromEntity
        relationship.from_entity_attribute = data.fromEntityAttribute
        relationship.to_entity = data.toEntity
        relationship.to_entity_attribute = data.toEntityAttribute

        return relationship
    def to_data(instance: 'CdmE2ERelationship', res_opt: ResolveOptions,
                options: CopyOptions) -> E2ERelationship:
        relationship = E2ERelationship()
        if not StringUtils.is_null_or_white_space(instance.name):
            relationship.name = instance.name
        relationship.fromEntity = instance.from_entity
        relationship.fromEntityAttribute = instance.from_entity_attribute
        relationship.toEntity = instance.to_entity
        relationship.toEntityAttribute = instance.to_entity_attribute
        relationship.exhibitsTraits = copy_data_utils._array_copy_data(
            res_opt, instance.exhibits_traits, options)

        return relationship
Example #25
0
    def _get_number(self, val: str, default_value: int) -> int:
        """Converts the string cardinality to number"""
        if StringUtils.equals_with_ignore_case(val, '*'):
            return CardinalitySettings._infinite_maximum

        try:
            number = int(val)
            return number
        except ValueError:
            logger.error(self._ctx, self._TAG, '_get_number',
                         self._owner.at_corpus_path,
                         CdmLogCode.ERR_PROJ_STRING_ERROR, val, default_value)
            # defaults to min:max DefaultMinimum:DefaultMaximum in the invalid values
            return default_value
    def from_data(ctx: 'CdmCorpusContext', data: 'OperationAddAttributeGroup') -> 'CdmOperationAddAttributeGroup':
        if not data:
            return None

        add_attribute_group_op = ctx.corpus.make_object(CdmObjectType.OPERATION_ADD_ATTRIBUTE_GROUP_DEF)  # type: CdmOperationAddAttributeGroup

        if data.type and not StringUtils.equals_with_ignore_case(data.type, OperationTypeConvertor._operation_type_to_string(CdmOperationType.ADD_ATTRIBUTE_GROUP)):
            logger.error(_TAG, ctx, '$type {} is invalid for this operation.'.format(data.type))
        else:
            add_attribute_group_op.type = CdmOperationType.ADD_ATTRIBUTE_GROUP

        add_attribute_group_op.attribute_group_name = data.attributeGroupName
        add_attribute_group_op.explanation = data.explanation

        return add_attribute_group_op
Example #27
0
    def _get_number(self, val: str, default_value: int) -> int:
        """Converts the string cardinality to number"""
        if StringUtils.equals_with_ignore_case(val, '*'):
            return CardinalitySettings._infinite_maximum

        try:
            number = int(val)
            return number
        except ValueError:
            logger.error(
                self._TAG, self._ctx,
                'Unable to get number for string \'{}\'. Falling to default value {}.'
                .format(val, default_value))
            # defaults to min:max DefaultMinimum:DefaultMaximum in the invalid values
            return default_value
Example #28
0
    def _replace_wildcard_characters(format: str, projection_owner_name: str,
                                     current_PAS: '******'):
        """
        Replace the wildcard character. {a/A} will be replaced with the current attribute name.
        {m/M} will be replaced with the entity attribute name. {o} will be replaced with the index of the attribute after an array expansion
        """
        if not format:
            return ''

        ordinal = str(
            current_PAS._ordinal) if current_PAS._ordinal is not None else ''
        original_member_attribute_name = current_PAS._current_resolved_attribute.target.name if isinstance(
            current_PAS._current_resolved_attribute.target,
            CdmAttribute) else '' or ''
        resolved_member_attribute_name = current_PAS._current_resolved_attribute._resolved_name

        value = StringUtils._replace(format, 'a', projection_owner_name)
        value = StringUtils._replace(value, 'o', ordinal)
        value = StringUtils._replace(value, 'mo',
                                     original_member_attribute_name)
        value = StringUtils._replace(value, 'm',
                                     resolved_member_attribute_name)

        return value
Example #29
0
    def from_data(ctx: CdmCorpusContext,
                  data: E2ERelationship) -> CdmE2ERelationship:
        relationship = ctx.corpus.make_object(
            CdmObjectType.E2E_RELATIONSHIP_DEF)
        if not StringUtils.is_null_or_white_space(data.name):
            relationship.relationship_name = data.name
        relationship.from_entity = data.fromEntity
        relationship.from_entity_attribute = data.fromEntityAttribute
        relationship.to_entity = data.toEntity
        relationship.to_entity_attribute = data.toEntityAttribute
        utils.add_list_to_cdm_collection(
            relationship.exhibits_traits,
            utils.create_trait_reference_array(ctx, data.exhibitsTraits))

        return relationship
Example #30
0
async def create_or_update_syms_entities(syms_manifest_content: 'SymsManifestContent', adapter: 'StorageAdapter'):
    failed_updated_tables = {}
    failed_updated_relationships = {}
    failed_removed_tables = {}
    failed_removed_relationships = {}
    error_mesg = ''

    if syms_manifest_content.intial_sync:
       await create_or_update_database(syms_manifest_content.database, adapter)
    if syms_manifest_content.removed_entities is not None:
        for remove_table in syms_manifest_content.removed_entities:
            try:
                await remove_table_entity(remove_table, syms_manifest_content.database.name, adapter)
            except Exception as e:
                failed_removed_tables[remove_table] = str(e)
            if len(failed_removed_tables) > 0:
                error_mesg += 'Failed removed tables : ' + str(failed_removed_tables)

    if syms_manifest_content.removed_relationships is not None:
        for remove_relationship in syms_manifest_content.removed_relationships:
            try:
                await remove_relationship_entity(remove_relationship, syms_manifest_content.database.name, adapter)
            except Exception as e:
                failed_removed_relationships[remove_relationship] = str(e)
        if len(failed_removed_relationships) > 0:
           error_mesg += 'Failed removed relationships :' + str(failed_removed_relationships)

    if syms_manifest_content.entities is not None:
        for table in syms_manifest_content.entities:
            try:
                await create_or_update_table_entity(table, adapter)
            except Exception as e:
                failed_updated_tables[table.name] = str(e)
        if len(failed_updated_tables) > 0:
            error_mesg += 'Failed updated tables : ' + str(failed_updated_tables)

    if syms_manifest_content.relationships is not None:
        for relationship in syms_manifest_content.relationships:
            try:
                await create_or_update_relationship_entity(relationship, adapter)
            except Exception as e:
                failed_updated_relationships[relationship.name] = str(e)
        if len(failed_updated_relationships) > 0:
            error_mesg += 'Failed updated relationships : ' + str(failed_updated_relationships)

    if not StringUtils.is_blank_by_cdm_standard(error_mesg):
        raise Exception (error_mesg)