def fetch_document(self, session, id): p = self.permissionHandlers.get('info:srw/operation/2/retrieve', None) if p: if not session.user: msg = ("Authenticated user required to retrieve an object " "from %s" % self.id) raise PermissionException(msg) okay = p.hasPermission(session, session.user) if not okay: msg = ("Permission required to retrieve an object from " "%s" % self.id) raise PermissionException(msg) data = self.fetch_data(session, id) if (data): doc = StringDocument(data) if (self.outPreParser is not None): doc = self.outPreParser.process_document(session, doc) elif (self.outWorkflow is not None): doc = self.outWorkflow.process(session, doc) doc.id = id doc.documentStore = self.id doc.parent = ('document', self.id, id) return doc elif (isinstance(data, DeletedObject)): raise ObjectDeletedException(data) else: raise ObjectDoesNotExistException(id)
def fetch_document(self, session, id): p = self.permissionHandlers.get('info:srw/operation/2/retrieve', None) if p: if not session.user: msg = ("Authenticated user required to retrieve an object " "from %s" % self.id) raise PermissionException(msg) okay = p.hasPermission(session, session.user) if not okay: msg = ("Permission required to retrieve an object from " "%s" % self.id) raise PermissionException(msg) data = self.fetch_data(session, id) if (data): doc = StringDocument(data) if (self.outPreParser is not None): doc = self.outPreParser.process_document(session, doc) elif (self.outWorkflow is not None): doc = self.outWorkflow.process(session, doc) doc.id = id doc.documentStore = self.id doc.parent = ('document', self.id, id) return doc elif (isinstance(data, DeletedObject)): raise ObjectDeletedException(data) else: raise ObjectDoesNotExistException(id)
def create_document(self, session, doc=None): p = self.permissionHandlers.get('info:srw/operation/1/create', None) if p: if not session.user: msg = ("Authenticated user required to create an object in " "%s" % self.id) raise PermissionException(msg) okay = p.hasPermission(session, session.user) if not okay: msg = "Permission required to create an object in %s" % self.id raise PermissionException(msg) id = self.generate_id(session) if (doc is None): # Create a placeholder doc = StringDocument("") else: doc.id = id doc.documentStore = self.id try: self.store_document(session, doc) except ObjectAlreadyExistsException: # Back out id change if type(id) == long: self.currentId -= 1 raise except: raise return doc
def create_document(self, session, doc=None): p = self.permissionHandlers.get('info:srw/operation/1/create', None) if p: if not session.user: msg = ("Authenticated user required to create an object in " "%s" % self.id) raise PermissionException(msg) okay = p.hasPermission(session, session.user) if not okay: msg = "Permission required to create an object in %s" % self.id raise PermissionException(msg) id = self.generate_id(session) if (doc is None): # Create a placeholder doc = StringDocument("") else: doc.id = id doc.documentStore = self.id try: self.store_document(session, doc) except ObjectAlreadyExistsException: # Back out id change if type(id) == long: self.currentId -= 1 raise except: raise return doc
def directoryDocumentStoreIter(store): session = Session() for id_, data in directoryStoreIter(store): doc = StringDocument(data) doc.id = id_ internalId = store._normalizeIdentifier(session, id_) doc.filename = store._getFilePath(session, internalId) doc.documentStore = store.id yield doc
def mercurialDocumentStoreIter(store): session = Session() for id_, data in directoryStoreIter(store): doc = StringDocument(data) doc.id = id_ internalId = store._normalizeIdentifier(session, id_) doc.filename = store._getFilePath(session, internalId) doc.documentStore = store.id # Assign byteCount and other useful metadata stat = os.stat(doc.filename) doc.byteCount = stat.st_size doc.metadata['lastModified'] = stat.st_mtime yield doc
def _process_data(self, session, id, data, preParser=None): # Split from fetch record for Iterators if (preParser is not None): doc = StringDocument(data) doc = preParser.process_document(session, doc) elif (self.outPreParser is not None): doc = StringDocument(data) doc = self.outPreParser.process_document(session, doc) elif (self.outWorkflow is not None): doc = StringDocument(data) doc = self.outWorkflow.process(session, doc) else: doc = StringDocument(data) # Ensure basic required info doc.id = id doc.documentStore = self.id return doc
def _process_data(self, session, id, data, preParser=None): # Split from fetch record for Iterators if (preParser is not None): doc = StringDocument(data) doc = preParser.process_document(session, doc) elif (self.outPreParser is not None): doc = StringDocument(data) doc = self.outPreParser.process_document(session, doc) elif (self.outWorkflow is not None): doc = StringDocument(data) doc = self.outWorkflow.process(session, doc) else: doc = StringDocument(data) # Ensure basic required info doc.id = id doc.documentStore = self.id return doc