Ejemplo n.º 1
0
 def get_type(self, public_id: int):
     try:
         return CmdbType(**self.dbm.find_one(collection=CmdbType.COLLECTION,
                                             public_id=public_id))
     except RequiredInitKeyNotFoundError as err:
         raise ObjectManagerInitError(err=err.message)
     except Exception as err:
         raise ObjectManagerGetError(err=err)
Ejemplo n.º 2
0
 def get_all_types(self) -> List[TypeModel]:
     try:
         raw_types: List[dict] = self._get_many(collection=TypeModel.COLLECTION)
     except Exception as err:
         raise ObjectManagerGetError(err=err)
     try:
         return [TypeModel.from_data(type) for type in raw_types]
     except Exception as err:
         raise ObjectManagerInitError(err=err)
Ejemplo n.º 3
0
 def get_categories_by(self, sort='public_id', **requirements: dict) -> List[CategoryModel]:
     """Get a list of categories by special requirements"""
     try:
         raw_categories = self._get_many(collection=CategoryModel.COLLECTION, sort=sort, **requirements)
     except Exception as err:
         raise ObjectManagerGetError(err)
     try:
         return [CategoryModel.from_data(category) for category in raw_categories]
     except Exception as err:
         raise ObjectManagerInitError(err)
Ejemplo n.º 4
0
 def get_categories(self) -> List[CategoryModel]:
     """Get all categories as nested list"""
     try:
         raw_categories = self._get_many(collection=CategoryModel.COLLECTION, sort='public_id')
     except Exception as err:
         raise ObjectManagerGetError(err)
     try:
         return [CategoryModel.from_data(category) for category in raw_categories]
     except Exception as err:
         raise ObjectManagerInitError(err)
Ejemplo n.º 5
0
 def get_all_types(self) -> List[CmdbType]:
     try:
         raw_types: List[dict] = self._get_many(
             collection=CmdbType.COLLECTION)
     except Exception as err:
         raise ObjectManagerGetError(err=err)
     try:
         return [CmdbType(**type) for type in raw_types]
     except Exception as err:
         raise ObjectManagerInitError(err=err)
Ejemplo n.º 6
0
    def get_category_by(self, **requirements) -> CategoryModel:
        """Get a single category by requirements
        Notes:
            Even if multiple categories match the requirements only the first matched will be returned
        """
        try:
            raw_category = self._get_by(collection=CategoryModel.COLLECTION, **requirements)
        except Exception as err:
            raise ObjectManagerGetError(err)

        try:
            return CategoryModel.from_data(raw_category)
        except Exception as err:
            raise ObjectManagerInitError(err)
Ejemplo n.º 7
0
 def get_category(self, public_id: int) -> CmdbCategory:
     """Get a category from the database"""
     try:
         raw_category: dict = self._get(collection=CmdbCategory.COLLECTION,
                                        public_id=public_id)
     except Exception as err:
         raise ObjectManagerGetError(err=err)
     if not raw_category:
         raise ObjectManagerGetError(
             err=f'No category with the id: {public_id} was found')
     try:
         return CmdbCategory.from_data(raw_category)
     except Exception as err:
         raise ObjectManagerInitError(err=err)