ooici/coi-services — pull request #302 by swarbhanu (2012-10-12 18:12:59+00:00)
Title: UNS code changes

# UNS changes #

### Abstract ###

The notification workers were aligned with the new transform architecture. The publish_event method can now be used by the operator to just publish an event. The find_events() method now leverages couchdb views to make it more efficient. The old find_events() method that used elastic search has been moved to find_events_extended(). Right now the find_events_extended() method is still using the same parameters as the find_events() method but later on its search criteria for events and results output can be extended to leverage the capabilities of elastic search. Also when a create_notification() method is used, a hasNotification association is created between the user and the notification request object.

### Changes###

1. The interface for the publish_event() method has been changed. Now it only needs an event passed in as input.
```
event_obj = DeviceEvent(origin= "origin_1", origin_type='origin_type_1', sub_type= 'sub_type_1', ts_created = 2))
user_notification_service.publish_event(event = event_obj)
```

2. The find_events() method now leverages couchdb use. Its interface is unchanged. To use it:
```
event_publisher_1 = EventPublisher("ResourceLifecycleEvent")
event_publisher_2 = EventPublisher("ReloadUserInfoEvent")

for i in xrange(10):
event_publisher_1.publish_event(origin='Some_Resource_Agent_ID1', ts_created = i)
event_publisher_2.publish_event(origin='Some_Resource_Agent_ID2', ts_created = i)

# allow elastic search to populate the indexes. This gives enough time for the reload of user_info
events = self.unsc.find_events(origin='Some_Resource_Agent_ID1', type = 'ResourceLifecycleEvent', min_datetime= 4, max_datetime=7)
```
At present the min_datetime and max_datetime are seconds since epoch. They accept integers.
If you are using a date time object, you can convert it into seconds since epoch by using this static method in UNS:
```
from datetime import datetime
datetime_obj = datetime.utcnow()

user_notification_service = UserNotificationServiceClient()
min_datetime_in_seconds = user_notification_service.makeEpochTime(datetime_obj)
```

3. A find_events_extended() method has been added. It uses ElasticSearch. At present it takes in the same parameters as find_events().
I think no one should be using find_events_extended() method right now and everyone should instead use the find_events() method.

### Changes Not Yet Incorporated###

This pull request does not contain the implementation for the get_recent_events() and get_user_notifications() methods. A separate pull request by Monday afternoon will contain their implementation and an integration test that checks them for extended resources.