Fix INF-371 inventoryChange notification of the resourceType, resourcePool, Dms
[pti/o2.git] / o2ims / service / auditor / resourcepool_handler.py
index 88cf182..366b77f 100644 (file)
@@ -20,11 +20,12 @@ from o2ims.domain.stx_object import StxGenericModel
 # from dataclasses import asdict
 # from typing import List, Dict, Callable, Type
 # TYPE_CHECKING
-from o2ims.domain import commands
+from o2ims.domain import commands, events
 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 ResourcePool
+from o2ims.domain.subscription_obj import NotificationEventEnum
 # if TYPE_CHECKING:
 #     from . import unit_of_work
 
@@ -74,15 +75,20 @@ def is_outdated(resourcepool: ResourcePool, stxobj: StxGenericModel):
 
 def create_by(stxobj: StxGenericModel, parentid: str) -> ResourcePool:
     content = json.loads(stxobj.content)
-    globalcloudId = stxobj.id  # to be updated
+    globalLocationId = ''  # to be updated
     description = "A Resource Pool"
+    location = content['location'] if content['location'] is not None else ''
     resourcepool = ResourcePool(stxobj.id, stxobj.name,
-                                content['location'],
-                                parentid, globalcloudId, description)
+                                location,
+                                parentid, globalLocationId, description)
     resourcepool.createtime = stxobj.createtime
     resourcepool.updatetime = stxobj.updatetime
     resourcepool.hash = stxobj.hash
-
+    resourcepool.events.append(events.ResourcePoolChanged(
+        id=stxobj.id,
+        notificationEventType=NotificationEventEnum.CREATE,
+        updatetime=stxobj.updatetime
+    ))
     return resourcepool
 
 
@@ -92,10 +98,15 @@ def update_by(target: ResourcePool, stxobj: StxGenericModel,
         raise MismatchedModel("Mismatched Id")
     content = json.loads(stxobj.content)
     target.name = stxobj.name
-    target.location = content['location']
+    target.location = content['location'] if content['location'] is not None \
+        else ''
     target.createtime = stxobj.createtime
     target.updatetime = stxobj.updatetime
     target.hash = stxobj.hash
     target.oCloudId = parentid
     target.version_number = target.version_number + 1
-    target.events = []
+    target.events.append(events.ResourcePoolChanged(
+        id=stxobj.id,
+        notificationEventType=NotificationEventEnum.MODIFY,
+        updatetime=stxobj.updatetime
+    ))