def get_subjects(self, obj): """Get datacite subjects.""" subjects = obj["metadata"].get("subjects", []) if not subjects: return missing serialized_subjects = [] ids = [] for subject in subjects: sub_text = subject.get("subject") if sub_text: serialized_subjects.append({"subject": sub_text}) else: ids.append(subject.get("id")) if ids: subjects_service = (current_service_registry.get("subjects")) subjects = subjects_service.read_many(system_identity, ids) validator = validate.URL() for subject in subjects: serialized_subj = { "subject": subject.get("subject"), "subjectScheme": subject.get("scheme"), } id_ = subject.get("id") try: validator(id_) serialized_subj["valueURI"] = id_ except ValidationError: pass serialized_subjects.append(serialized_subj) return serialized_subjects if serialized_subjects else missing
def service(self): """Service property. It is required to access the regitry lazily to avoid out of application context errors. """ if not self.service_name: return current_service return current_service_registry.get(self.service_name)
def cleanup_drafts(seconds=3600): """Hard delete of soft deleted drafts. :param int seconds: numbers of seconds that should pass since the last update of the draft in order to be hard deleted. """ timedelta_param = timedelta(seconds=seconds) service = current_service_registry.get("rdm-records") service.cleanup_drafts(timedelta_param)
def subject_v(app): """Subject vocabulary record.""" subjects_service = (current_service_registry.get("subjects")) vocab = subjects_service.create( system_identity, { "id": "http://id.nlm.nih.gov/mesh/A-D000007", "scheme": "MeSH", "subject": "Abdominal Injuries", }) Subject.index.refresh() return vocab
def test_load_affiliations(app, db, admin_role): dir_ = Path(__file__).parent affiliations = AffiliationsFixture([ dir_ / "app_data", dir_.parent.parent / "invenio_rdm_records/fixtures/data" ], "affiliations.yaml") affiliations.load() # app_data/users.yaml doesn't create an [email protected] user service = current_service_registry.get("rdm-affiliations") cern = service.read(identity=system_identity, id_="01ggx4157") assert cern["acronym"] == "CERN" pytest.raises(PIDDoesNotExistError, service.read, "cern", system_identity)
def get_affiliation(self, obj): """Get affiliation list.""" affiliations = obj.get("affiliations", []) if not affiliations: return missing serialized_affiliations = [] ids = [] for affiliation in affiliations: id_ = affiliation.get("id") if id_: ids.append(id_) else: # if no id, name is mandatory serialized_affiliations.append({"name": affiliation["name"]}) if ids: affiliations_service = ( current_service_registry.get("affiliations")) affiliations = affiliations_service.read_many(system_identity, ids) for affiliation in affiliations: aff = { "name": affiliation["name"], } identifiers = affiliation.get("identifiers") if identifiers: # PIDS-FIXME: DataCite accepts only one, how to decide identifier = identifiers[0] id_scheme = get_scheme_datacite( identifier["scheme"], "VOCABULARIES_AFFILIATION_SCHEMES", default=identifier["scheme"]) if id_scheme: aff["affiliationIdentifier"] = identifier["identifier"] aff["affiliationIdentifierScheme"] = id_scheme.upper() # upper() is fine since this field is free text. It # saves us from having to modify invenio-vocabularies # or do config overrides. serialized_affiliations.append(aff) return serialized_affiliations
def __init__(self, service_or_name, identity, *args, update=False, **kwargs): """Constructor. :param service_or_name: a service instance or a key of the service registry. :param identity: access identity. :param update: if True it will update records if they exist. """ if isinstance(service_or_name, str): service_or_name = current_service_registry.get(service_or_name) self._service = service_or_name self._identity = system_identity self._update = update super().__init__(*args, **kwargs)
def affiliations_v(app): """Affiliations vocabulary record.""" affiliations_service = (current_service_registry.get("rdm-affiliations")) aff = affiliations_service.create( system_identity, { "id": "cern", "name": "CERN", "acronym": "CERN", "identifiers": [{ "scheme": "ror", "identifier": "01ggx4157", }, { "scheme": "isni", "identifier": "000000012156142X", }] }) Affiliations.index.refresh() return aff
def affiliations_service(): return current_service_registry.get("affiliations")
def subjects_service(app): """Subjects service.""" return current_service_registry.get("subjects")
def get_service(self): """Return the record service.""" return current_service_registry.get(self._service_id)
def subjects_service(): return current_service_registry.get("subjects")
def create(self, entry): """Load a single user.""" service = current_service_registry.get("rdm-affiliations") service.create(identity=system_identity, data=entry)
def _read_affiliation(self, id_): """Retrieve affiliation record using service.""" affiliations_service = ( current_service_registry.get("rdm-affiliations") ) return affiliations_service.read(id_, system_identity)
def names_service(): return current_service_registry.get("names")
def get_service_for_vocabulary(vocabulary): """Calculates the configuration for a Data Stream.""" if vocabulary == "names": # FIXME: turn into a proper factory return current_service_registry.get("names")