def add_manifest(self, manifest: Manifest) -> tuple: if self.ESM_DB.manifests.count({'id': manifest.id}) == 0: LOG.debug("replacing newlines - mongodb strips these!") manifest.manifest_content = manifest.manifest_content.replace('\n', '</br>') result = self.ESM_DB.manifests.insert_one(manifest.to_dict()) if not result.acknowledged: return 'there was an issue saving the supplied manifest to the DB', 500 else: print('client side error - 4XX') return 'the manifest already exists in the catalog', 409 return 'ok', 200
def get_manifest(manifest_id: str = None, plan_id: str = None) -> List[Manifest]: if manifest_id and plan_id: raise Exception('Query Manifests only by manifest_id OR plan_id') if plan_id: manifests = ManifestSQL.where( 'plan_id_name', '=', '{}'.format(plan_id)).get().serialize() if len(manifests) > 1: raise Exception( 'Too many manifests {mani_len} returned for the Plan: {plan_id}' .format(mani_len=len(manifests), plan_id=plan_id)) return [Manifest.from_dict(manifests[0])] if manifest_id: if ManifestAdapter.exists_in_db(manifest_id): model_sql = ManifestAdapter.find_by_id_name(manifest_id) model = ManifestAdapter.model_sql_to_model(model_sql) model.manifest_content = model.manifest_content.replace( '</br>', '\n') return [model] else: return [] else: manifests = ManifestAdapter.get_all() for manifest in manifests: manifest.manifest_content = manifest.manifest_content.replace( '</br>', '\n') return manifests
def add_manifest(self, manifest: Manifest) -> tuple: if manifest not in self.ESM_DB.manifests: self.ESM_DB.manifests.append(manifest) return 'ok', 200 else: LOG.warn('A duplicate manifest was attempted to be registered. ' 'Ignoring the request. ' 'Content supplied:\n{content}'.format(content=manifest.to_str())) return 'duplicate', 400
def get_manifest(self, manifest_id: str = None, plan_id: str = None) -> List[Manifest]: if manifest_id and plan_id: raise Exception('Query manifests only by manifest_id OR plan_id') if plan_id: if self.ESM_DB.manifests.count({'plan_id': plan_id}) == 1: m = self.ESM_DB.manifests.find_one({'plan_id': plan_id}) m = Manifest.from_dict(m) LOG.debug("replacing <br/> with newlines") m.manifest_content = m.manifest_content.replace('</br>', '\n') return [m] else: LOG.warning( 'Requested manifest by plan ID not found: {id}'.format( id=plan_id)) return [] elif manifest_id: if self.ESM_DB.manifests.count({'id': manifest_id}) == 1: m = self.ESM_DB.manifests.find_one({'id': manifest_id}) m = Manifest.from_dict(m) LOG.debug("replacing <br/> with newlines") m.manifest_content = m.manifest_content.replace('</br>', '\n') return [m] else: LOG.warning('Requested manifest not found: {id}'.format( id=manifest_id)) return [] else: manifests = [] for manifest in self.ESM_DB.manifests.find(): LOG.debug("replacing <br/> with newlines") manifest['manifest_content'] = manifest[ 'manifest_content'].replace('</br>', '\n') manifests.append(Manifest().from_dict(manifest)) return manifests
def add_manifest(self, manifest: Manifest) -> tuple: m = [m for m in self.ESM_DB.manifests if m.id == manifest.id] if len(m) == 0: LOG.info('Manifest to be added with:\n{content}'.format( content=manifest.to_str())) if not self.valid_manifest_type(manifest.manifest_content, manifest.manifest_type): LOG.error("Incompatible manifest type and content.") return 'the manifest has an incompatible type {}'.format( manifest.manifest_type), 400 # self.ESM_DB.manifests.remove(m[0]) self.ESM_DB.manifests.append(manifest) return 'ok', 200 else: print('client side error - 4XX') error_msg = "The Manifest already exists in the catalog." LOG.warning(error_msg) return error_msg, 409