def marc21_to_type_and_organisation(self, key, value): """Get document type and organisation from 980 field.""" # organisation if value.get('b'): organisation = value.get('b').lower() # Specific transformation for `unisi`, because the real acronym is # `usi`. if organisation == 'unisi': organisation = 'usi' if organisation not in overdo.registererd_organisations: overdo.create_organisation(organisation) overdo.registererd_organisations.append(organisation) self['organisation'] = [{ '$ref': OrganisationRecord.get_ref_link('organisations', organisation) }] # get doc type by mapping key = value.get('a', '') + '|' + value.get('f', '') if key not in TYPE_MAPPINGS: current_app.logger.warning( 'Document type not found in mapping for type "{type}"'.format( type=key)) return None # Store types to records self['documentType'] = TYPE_MAPPINGS[key] return None
def marc21_to_type_and_organisation(self, key, value): """Get document type and organisation from 980 field.""" subdivision_name = None # organisation if value.get('b'): organisation = value.get('b').lower() # Specific transformation for `unisi`, because the real acronym is # `usi`. if organisation == 'unisi': organisation = 'usi' # Specific transformation for `hep bejune`, in order to fill out # custom fields `Filière` (`customField1`) and `Titre obtenu` # (`customField2`) if organisation == 'hepbejune' and value.get('f'): document_subtype = value.get('f').lower() customField1 = '' customField2 = '' if document_subtype == 'diss_bachelor': customField1 = 'Enseignement primaire' customField2 = 'Bachelor of Arts in Pre-Primary and Primary Education' elif document_subtype == 'diss_master': customField1 = 'Enseignement secondaire' customField2 = 'Master of Arts or of Science in Secondary Education' if customField1: self['customField1'] = [customField1] if customField2: self['customField2'] = [customField2] # Specific transformation for `hepfr`, which should be imported as # a faculty AND a subdivision of FOLIA/unifr if organisation == 'hepfr': organisation = 'unifr' self['organisation'] = [{ '$ref': OrganisationRecord.get_ref_link('organisations', organisation) }] # `hepfr` is a faculty of FOLIA/unifr self['customField1'] = ['HEP|PH FR'] # `hepfr` is a subdivision of FOLIA/unifr subdivision_name = 'HEP Fribourg' # Store subdivision # TODO: avoid possible clashes between subdivision # names in different languages result = RecordSearch()\ .filter('term', organisation__pid=organisation)\ .filter('term', name__value__raw=subdivision_name)\ .source(includes='pid').scan() subdivision_pid = next(result).pid # If the subdivision exists, assign it to the record if subdivision_pid: self['subdivisions'] = [{ '$ref': SubdivisionRecord.get_ref_link('subdivisions', subdivision_pid) }] # Specific transformation for `bpuge` and `mhnge`, because the real # acronym is `vge`. subdivision_name = None if organisation in [ 'bpuge', 'mhnge', 'baage', 'bmuge', 'imvge', 'mhsge' ]: subdivision_name = 'bge' if organisation == 'bpuge' else organisation organisation = 'vge' if organisation not in overdo.registererd_organisations: overdo.create_organisation(organisation) overdo.registererd_organisations.append(organisation) self['organisation'] = [{ '$ref': OrganisationRecord.get_ref_link('organisations', organisation) }] if subdivision_name: # Store subdivision hash_key = hashlib.md5( (subdivision_name + organisation).encode()).hexdigest() subdivision_pid = SubdivisionRecord.get_pid_by_hash_key(hash_key) # No subdivision found if not subdivision_pid: subdivision = SubdivisionRecord.create({ 'name': [{ 'language': 'eng', 'value': subdivision_name }], 'organisation': { '$ref': OrganisationRecord.get_ref_link( 'organisations', organisation) }, 'hashKey': hash_key }) subdivision.commit() subdivision.reindex() db.session.commit() subdivision_pid = subdivision['pid'] self['subdivisions'] = [{ '$ref': SubdivisionRecord.get_ref_link('subdivisions', subdivision_pid) }] # get doc type by mapping key = value.get('a', '') + '|' + value.get('f', '') if key not in TYPE_MAPPINGS: current_app.logger.warning( 'Document type not found in mapping for type "{type}"'.format( type=key)) return None # Store types to records self['documentType'] = TYPE_MAPPINGS[key] return None