def get_next_pid(self, namespace=None, count=None): """ Request next available pid or pids from Fedora, optionally in a specified namespace. Calls :meth:`ApiFacade.getNextPID`. .. deprecated :: 0.14 Mint pids for new objects with :func:`eulcore.fedora.models.DigitalObject.get_default_pid` instead, or call :meth:`ApiFacade.getNextPID` directly. :param namespace: (optional) get the next pid in the specified pid namespace; otherwise, Fedora will return the next pid in the configured default namespace. :param count: (optional) get the specified number of pids; by default, returns 1 pid :rtype: string or list of strings """ # this method should no longer be needed - default pid logic moved to DigitalObject warnings.warn( """get_next_pid() method is deprecated; you should mint new pids via DigitalObject or ApiFacade.getNextPID() instead.""", DeprecationWarning, ) kwargs = {} if namespace: kwargs["namespace"] = namespace if count: kwargs["numPIDs"] = count data, url = self.api.getNextPID(**kwargs) nextpids = parse_xml_object(NewPids, data, url) if count is None: return nextpids.pids[0] else: return nextpids.pids
def find_objects(self, terms=None, type=None, chunksize=None, **kwargs): """ Find objects in Fedora. Find query should be generated via keyword args, based on the fields in Fedora documentation. By default, the query uses a contains (~) search for all search terms. Calls :meth:`ApiFacade.findObjects`. Results seem to return consistently in ascending PID order. Example usage - search for all objects where the owner contains 'jdoe':: repository.find_objects(ownerId='jdoe') Supports all search operators provided by Fedora findObjects query (exact, gt, gte, lt, lte, and contains). To specify the type of query for a particular search term, call find_objects like this:: repository.find_objects(ownerId__exact='lskywalker') repository.find_objects(date__gt='20010302') :param type: type of objects to return; defaults to :class:`DigitalObject` :param chunksize: number of objects to return at a time :rtype: generator for list of objects """ type = type or self.default_object_type find_opts = {"chunksize": chunksize} search_operators = {"exact": "=", "gt": ">", "gte": ">=", "lt": "<", "lte": "<=", "contains": "~"} if terms is not None: find_opts["terms"] = terms else: conditions = [] for field, value in kwargs.iteritems(): if "__" in field: field, filter = field.split("__") if filter not in search_operators: raise Exception("Unsupported search filter '%s'" % filter) op = search_operators[filter] else: op = search_operators["contains"] # default search mode if field in self.search_fields_aliases: field = self.search_fields_aliases[field] if field not in self.search_fields: raise Exception("Error generating Fedora findObjects query: unknown search field '%s'" % field) if " " in value: # if value contains whitespace, it must be delimited with single quotes value = "'%s'" % value conditions.append("%s%s%s" % (field, op, value)) query = " ".join(conditions) find_opts["query"] = query data, url = self.api.findObjects(**find_opts) chunk = parse_xml_object(SearchResults, data, url) while True: for result in chunk.results: yield type(self.api, result.pid) if chunk.session_token: data, url = self.api.findObjects(session_token=chunk.session_token, **find_opts) chunk = parse_xml_object(SearchResults, data, url) else: break