예제 #1
0
    def _count_records_per_owner(self, count_records_per_owner):

        self.report.add('Owner  Records')

        for key in count_records_per_owner:
            records = add_spaces(count_records_per_owner[key])
            key = add_spaces(key)
            self.report.add(f'{key}    {records}')
예제 #2
0
    def _report_columns_spaces(self, report: str):
        """ Sets the spacing between columns in a report line """
        count = 0
        result = ''

        # Split report
        report = report.split('@')

        columns_length = {
            1: 23,
            2: 18,
            3: 21,
            4: 38,
        }
        for column in report:
            count += 1

            if count < 5:
                column_length = columns_length[count]
                # Increaes column space in case of new line
                if '\n' in column:
                    column_length += 1
                # Add spaces
                result += add_spaces(column, column_length) + '-'
                continue
            result += column

        # Removes the dash from the last column
        if len(report) < 5:
            result = result[:-1]
        return result
예제 #3
0
    def _update_records(self, json_response: dict):
        """ Iterates over the Pure response and process all records that need to be created/updated """

        for item in json_response['items']:

            if 'changeType' not in item or 'uuid' not in item:
                self.local_counters['incomplete'] += 1
                continue
            elif item['familySystemName'] != 'ResearchOutput':
                self.local_counters['not_ResearchOutput'] += 1
                continue
            elif item['changeType'] == 'DELETE':
                continue

            uuid = item['uuid']
            if uuid in self.duplicated_uuid:
                self.local_counters['duplicated'] += 1
                continue

            record_number = add_spaces(self.global_counters['total'] + 1)
            report = f"\n{record_number} - Change type           - {item['changeType']}"
            self.report.add(report)

            if item['changeType'] == 'ADD' or item['changeType'] == 'CREATE':
                self.local_counters['create'] += 1

            if item['changeType'] == 'UPDATE':
                self.local_counters['update'] += 1

            # Checks if this uuid has already been created / updated / deleted
            self.duplicated_uuid.append(uuid)

            # Adds record to RDM
            self.add_record.push_record_by_uuid(self.global_counters, uuid)
예제 #4
0
    def _report_summary(self):

        # Global counters
        self.report.summary_global_counters(self.report_files,
                                            self.global_counters)

        arguments = []
        for i in self.local_counters:
            arguments.append(add_spaces(self.local_counters[i]))
        self.report.add_template(self.report_files, ['changes', 'summary'],
                                 arguments)
        return
예제 #5
0
    def get_uuid_version(self, uuid):
        """ Gives the version to use for a new record and old versions of the same uuid """

        # Request
        response = self.rdm_requests.get_metadata_by_query(uuid)

        resp_json = json.loads(response.content)

        message = f'\tRDM metadata version  - {response} - '

        total_recids = resp_json['hits']['total']
        all_metadata_versions = []

        if total_recids == 0:
            # If there are no records with the same uuid means it is the first one (version 1)
            new_version = 1
            self.report.add(
                f'{message}Record NOT found    - Metadata version: 1')
            return [new_version, all_metadata_versions]

        new_version = None

        # Iterates over all records in response
        for item in resp_json['hits']['hits']:
            rdm_metadata = item['metadata']

            # If a record has a differnt uuid than it will be ignored
            if uuid != rdm_metadata['uuid']:
                self.report.add(
                    f" VERSIONING - Different uuid {rdm_metadata['uuid']}")
                continue

            # Get the latest version
            if 'metadataVersion' in rdm_metadata and not new_version:
                new_version = rdm_metadata['metadataVersion'] + 1

            # Add data to listed versions (old versions)
            recid = item['id']
            creation_date = item['created'].split('T')[0]
            version = str(rdm_metadata['metadataVersion'])
            all_metadata_versions.append([recid, version, creation_date])

        # In case the record has no metadataVersion
        if not new_version:
            message += f'Vers. not specified - New metadata version: 1'
            new_version = 1
        else:
            count_old_versions = add_spaces(len(all_metadata_versions))
            message += f'Older versions{count_old_versions} - New version: {new_version}'

        self.report.add(message)

        return [new_version, all_metadata_versions]
예제 #6
0
    def get_userid_from_list_by_externalid(self, external_id: str,
                                           file_data: list):
        """  """
        for line in file_data:
            line = line.split('\n')[0]
            line = line.split(' ')

            # Checks if at least one of the ids match
            if external_id == line[2]:
                user_id = line[0]
                user_id_spaces = add_spaces(user_id)

                report = f'\tRDM owner list @@ User id:     {user_id_spaces} @ externalId: {external_id}'
                self.reports.add(report)

                return user_id
예제 #7
0
    def summary_global_counters(self, report_files, global_counters):
        arguments = []
        arguments.append(add_spaces(global_counters['metadata']['success']))
        arguments.append(add_spaces(global_counters['file']['success']))
        arguments.append(add_spaces(global_counters['delete']['success']))
        arguments.append(add_spaces(global_counters['metadata']['error']))
        arguments.append(add_spaces(global_counters['file']['error']))
        arguments.append(add_spaces(global_counters['delete']['error']))
        self.add_template(report_files, ['general', 'summary'], arguments)

        if global_counters['http_responses']:
            http_response_str = self.metadata_http_responses(global_counters)
            self.add(http_response_str, report_files)
예제 #8
0
    def pages_single_line(self, global_counters, pag, pag_size):
        """ Adds to pages report log a summary of the page submission to RDM """
        current_time = datetime.now().strftime("%H:%M:%S")
        arguments = []
        arguments.append(add_spaces(current_time))
        arguments.append(add_spaces(pag))
        arguments.append(add_spaces(pag_size))
        arguments.append(add_spaces(global_counters['metadata']['success']))
        arguments.append(add_spaces(global_counters['metadata']['error']))
        arguments.append(add_spaces(global_counters['file']['success']))
        arguments.append(add_spaces(global_counters['file']['error']))
        if global_counters['http_responses']:
            arguments.append(self.metadata_http_responses(global_counters))

        self.add_template(['pages'], ['pages', 'summary_single_line'],
                          arguments)
        return