Merge "Improve the ssl connection handle log message. Fix auth header exception handl...
[pti/o2.git] / o2ims / views / alarm_view.py
index a308429..b3a9e4a 100644 (file)
@@ -16,8 +16,9 @@ import uuid as uuid
 
 from o2common.service import unit_of_work
 from o2common.views.pagination_view import Pagination
+from o2common.views.view import gen_filter
 from o2ims.views.alarm_dto import SubscriptionDTO
-from o2ims.domain.alarm_obj import AlarmSubscription
+from o2ims.domain.alarm_obj import AlarmSubscription, AlarmEventRecord
 
 from o2common.helper import o2logging
 # from o2common.config import config
@@ -26,9 +27,11 @@ logger = o2logging.get_logger(__name__)
 
 def alarm_event_records(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
     pagination = Pagination(**kwargs)
-    filter_kwargs = pagination.get_filter()
+    query_kwargs = pagination.get_pagination()
+    args = gen_filter(AlarmEventRecord,
+                      kwargs['filter']) if 'filter' in kwargs else []
     with uow:
-        li = uow.alarm_event_records.list_with_count(**filter_kwargs)
+        li = uow.alarm_event_records.list_with_count(*args, **query_kwargs)
     return pagination.get_result(li)
 
 
@@ -41,9 +44,11 @@ def alarm_event_record_one(alarmEventRecordId: str,
 
 def subscriptions(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
     pagination = Pagination(**kwargs)
-    filter_kwargs = pagination.get_filter()
+    query_kwargs = pagination.get_pagination()
+    args = gen_filter(AlarmSubscription,
+                      kwargs['filter']) if 'filter' in kwargs else []
     with uow:
-        li = uow.alarm_subscriptions.list_with_count(**filter_kwargs)
+        li = uow.alarm_subscriptions.list_with_count(*args, **query_kwargs)
     return pagination.get_result(li)
 
 
@@ -54,7 +59,7 @@ def subscription_one(subscriptionId: str,
         return first.serialize() if first is not None else None
 
 
-def subscription_create(subscriptionDto: SubscriptionDTO.subscription,
+def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create,
                         uow: unit_of_work.AbstractUnitOfWork):
 
     sub_uuid = str(uuid.uuid4())
@@ -65,7 +70,8 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription,
     with uow:
         uow.alarm_subscriptions.add(subscription)
         uow.commit()
-    return {"alarmSubscriptionId": sub_uuid}
+        first = uow.alarm_subscriptions.get(sub_uuid)
+        return first.serialize()
 
 
 def subscription_delete(subscriptionId: str,