Ejemplo n.º 1
0
    def delete_data(self, row):
        '''Deletes records via the ArchivesSpace API.

           Parameters:
            row['uri']: The URI of the record to delete.
            dirpath: Path to the backup directory. Defined in as_tools_config.yml

           Returns:
            dict: The JSON response from the ArchivesSpace API.
        '''
        record_json = self.sesh.get(self.api_url + row['uri']).json()
        u.create_backups(self.dirpath, row['uri'], record_json)
        record_delete = self.sesh.delete(self.api_url + row['uri']).json()
        return record_delete
Ejemplo n.º 2
0
    def set_parent_reposition_archival_object(self, row):
        '''Updates the archival object parent and position of an archival object record.

           Parameters:
            row['child_uri']: The URI of the record to update.
            row['parent_uri']: The URI of the new parent.
            row['position']: The new position value.
            dirpath: Path to the backup directory. Defined in as_tools_config.yml

           Returns:
            dict: The JSON response from the ArchivesSpace API.
        '''
        record_json = self.sesh.get(self.api_url + row['child_uri']).json()
        u.create_backups(self.dirpath, row['child_uri'], record_json)
        record_post = self.sesh.post(self.api_url + row['child_uri'] + '/parent?parent=' + row['parent_uri'] + '&position=' + str(row['position'])).json()
        return record_post
Ejemplo n.º 3
0
    def update_data(self, row, json_func):
        '''Updates data via the ArchivesSpace API.

           Parameters:
            row['uri']: The URI of the record to update.
            dirpath: Path to the backup directory. Defined in as_tools_config.yml
            json_data: The json structure to use in the update.

           Returns:
            dict: The JSON response from the ArchivesSpace API.
        '''
        #gets the JSON to update
        record_json = self.sesh.get(self.api_url + row['uri']).json()
        #creates a backup of the original file
        u.create_backups(self.dirpath, row['uri'], record_json)
        #this modifies the JSON based on a particular JSON data structure defined by the user
        record_json = json_func(record_json, row)
        #this posts the JSON
        record_post = self.sesh.post(self.api_url + row['uri'], json=record_json).json()
        print(record_post)
        return record_post
Ejemplo n.º 4
0
    def merge_data(self, row, record_type):
        '''Merges two records.

           NOTE: need to add another sys.argv value for this so can specify record type outside of CSV

           Parameters:
            row['target_uri']: The URI of the record to keep.
            row['victim_uri']: The URI of the record to merge.
            record_type: The type of record to be merged.

           Returns:
            dict: The JSON response from the ArchivesSpace API.
        '''
        victim_backup = self.sesh.get(self.api_url + row['victim_uri']).json()
        u.create_backups(self.dirpath, row['victim_uri'], victim_backup)
        #I want to add a check here to make sure contact info, etc. is not present...check merge_records.py for ex
        merge_json = {'target': {'ref': row['target_uri']},
                      'victims': [{'ref': row['victim_uri']}],
                      'jsonmodel_type': 'merge_request'}
        merge_request = self.sesh.post(self.api_url + '/merge_requests/' + str(record_type), json=merge_json).json()
        return merge_request
Ejemplo n.º 5
0
    def migrate_enumerations(self, row):
        '''Merges controlled values.

           Parameters:
            row['enum_uri']: The URI of the parent enumeration
            row['enum_val_uri']: The URI of the enumeration value to merge
            row['from']: The name of the enumeration value to merge
            row['to']: The name of the enumeration value to merge into

        '''
        #print(row)
        #record_json = requests.get(api_url + '/config/enumeration_values/' + row['from'], headers=headers).json()
        #print(record_json)
        #u.create_backups(dirpath, row['from'], record_json)
        record_json = self.sesh.get(self.api_url + row['enum_val_uri']).json()
        u.create_backups(self.dirpath, row['enum_val_uri'], record_json)
        merge_json = {'enum_uri': row['enum_uri'], #the URI of the parent enumeration - i.e. /config/enumerations/14
                        'from': row['from'], #the actual NAME of the enumeration value - i.e. photographs
                        'to': row['to'], #the actual NAME of the enumertion value - i.e. photographs
                        'jsonmodel_type': 'enumeration_migration'}
        record_post = self.sesh.post(self.api_url + '/config/enumerations/migration', json=merge_json)
        print(record_post.status_code)
        return record_post.json()