Add get detail of a resource to API; remove the dependency of the domain in the view...
[pti/o2.git] / o2ims / service / auditor / ocloud_handler.py
index 9dd4f0e..c0d8eaf 100644 (file)
@@ -20,11 +20,11 @@ from o2ims.domain.stx_object import StxGenericModel
 # from typing import List, Dict, Callable, Type
 # TYPE_CHECKING
 from o2ims.domain import commands
-from o2ims.service.unit_of_work import AbstractUnitOfWork
+from o2common.service.unit_of_work import AbstractUnitOfWork
 from o2ims.domain.resource_type import InvalidOcloudState
 from o2ims.domain.resource_type import MismatchedModel
 from o2ims.domain.ocloud import Ocloud
-from o2ims import config
+from o2common.config import config
 # if TYPE_CHECKING:
 #     from . import unit_of_work
 
@@ -43,9 +43,9 @@ def update_ocloud(
     stxobj = cmd.data
     with uow:
         oclouds = uow.oclouds.list()
-        if oclouds and len(oclouds) > 1:
+        if oclouds and oclouds.count() > 1:
             raise InvalidOcloudState("More than 1 ocloud is found")
-        elif not oclouds or len(oclouds) == 0:
+        elif not oclouds or oclouds.count() == 0:
             logger.info("add ocloud:" + stxobj.name
                         + " update_at: " + str(stxobj.updatetime)
                         + " id: " + str(stxobj.id)
@@ -56,7 +56,7 @@ def update_ocloud(
             logger.info("Add the ocloud: " + stxobj.id
                         + ", name: " + stxobj.name)
         else:
-            localmodel = oclouds.pop()
+            localmodel = oclouds.first()
             if is_outdated(localmodel, stxobj):
                 logger.info("update ocloud:" + stxobj.name
                             + " update_at: " + str(stxobj.updatetime)
@@ -99,3 +99,4 @@ def update_by(ocloud: Ocloud, stxobj: StxGenericModel) -> None:
     # ocloud.content = stxobj.content
     ocloud.hash = stxobj.hash
     ocloud.version_number = ocloud.version_number + 1
+    ocloud.events = []