Mercurial > libervia-pubsub
annotate idavoll/backend.py @ 89:ccf699adae5e
Merge from RELENG_0: Fix bug in handling uncaught exceptions.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Tue, 16 Nov 2004 12:16:04 +0000 |
parents | ec557449d1aa |
children | 59378610b16e |
rev | line source |
---|---|
49
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
1 from twisted.protocols.jabber import jid |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
2 from twisted.python import components |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
3 from twisted.application import service |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
4 from twisted.xish import utility |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
5 from twisted.internet import defer |
84 | 6 import sha |
7 import time | |
2 | 8 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
9 class Error(Exception): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
10 msg = '' |
1 | 11 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
12 def __str__(self): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
13 return self.msg |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
14 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
15 class NodeNotFound(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
16 msg = 'Node not found' |
1 | 17 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
18 class NotAuthorized(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
19 pass |
20
eddea65d1032
Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents:
18
diff
changeset
|
20 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
21 class PayloadExpected(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
22 msg = 'Payload expected' |
15 | 23 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
24 class NoPayloadAllowed(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
25 msg = 'No payload allowed' |
2 | 26 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
27 class NoInstantNodes(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
28 pass |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
20
diff
changeset
|
29 |
24
4f3bbefc6fad
Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
30 class NodeExists(Error): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
31 pass |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
32 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
33 class NotImplemented(Error): |
34 | 34 pass |
35 | |
36 class NotSubscribed(Error): | |
37 pass | |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
38 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
39 class IBackendService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
40 """ Interface to a backend service of a pubsub service. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
41 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
42 def get_supported_affiliations(self): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
43 """ Reports the list of supported affiliation types. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
44 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
45 @return: a list of supported affiliation types. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
46 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
47 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
48 class INodeCreationService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
49 """ A service for creating nodes """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
50 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
51 def create_node(self, node_id, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
52 """ Create a node. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
53 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
54 @return: a deferred that fires when the node has been created. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
55 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
56 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
57 class IPublishService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
58 """ A service for publishing items to a node. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
59 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
60 def publish(self, node_id, items, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
61 """ Publish items to a pubsub node. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
62 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
63 @return: a deferred that fires when the items have been published. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
64 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
65 class INotificationService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
66 """ A service for notification of published items. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
67 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
68 def register_notifier(self, observerfn, *args, **kwargs): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
69 """ Register callback which is called for notification. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
70 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
71 def get_notification_list(self, node_id, items): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
72 pass |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
73 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
74 class ISubscriptionService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
75 """ A service for managing subscriptions. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
76 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
77 def subscribe(self, node_id, subscriber, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
78 """ Request the subscription of an entity to a pubsub node. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
79 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
80 Depending on the node's configuration and possible business rules, the |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
81 C{subscriber} is added to the list of subscriptions of the node with id |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
82 C{node_id}. The C{subscriber} might be different from the C{requestor}, |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
83 and if the C{requestor} is not allowed to subscribe this entity an |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
84 exception should be raised. |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
85 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
86 @return: a deferred that returns the subscription state |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
87 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
88 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
89 def unsubscribe(self, node_id, subscriber, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
90 """ Cancel the subscription of an entity to a pubsub node. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
91 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
92 The subscription of C{subscriber} is removed from the list of |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
93 subscriptions of the node with id C{node_id}. If the C{requestor} |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
94 is not allowed to unsubscribe C{subscriber}, an an exception should |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
95 be raised. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
96 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
97 @return: a deferred that fires when unsubscription is complete. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
98 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
99 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
100 class IAffiliationsService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
101 """ A service for retrieving the affiliations with this pubsub service. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
102 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
103 def get_affiliations(self, entity): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
104 """ Report the list of current affiliations with this pubsub service. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
105 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
106 Report the list of the current affiliations with all nodes within this |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
107 pubsub service, along with subscriptions to such nodes, for the |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
108 C{entity}. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
109 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
110 @return: a deferred that returns the list of all current affiliations |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
111 and subscriptions. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
112 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
113 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
114 class IRetractionService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
115 """ A service for retracting published items """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
116 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
117 def retract_item(self, node_id, item_id, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
118 """ Removes item in node from persistent storage """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
119 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
120 def purge_node(self, node_id, requestor): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
121 """ Removes all items in node from persistent storage """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
122 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
123 class IItemRetrievalService(components.Interface): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
124 """ A service for retrieving previously published items. """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
125 |
80
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
126 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
127 """ Retrieve items from persistent storage |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
128 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
129 If C{max_items} is given, return the C{max_items} last published |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
130 items, else if C{item_ids} is not empty, return the items requested. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
131 If neither is given, return all items. |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
132 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
133 @return: a deferred that returns the requested items |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
134 """ |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
135 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
136 class BackendService(service.MultiService, utility.EventDispatcher): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
137 |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
138 __implements__ = IBackendService, |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
139 |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
140 def __init__(self, storage): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
141 service.MultiService.__init__(self) |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
142 utility.EventDispatcher.__init__(self) |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
143 self.storage = storage |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
144 |
53
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
145 def supports_publisher_affiliation(self): |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
146 return True |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
147 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
148 def supports_outcast_affiliation(self): |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
149 return True |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
150 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
151 def supports_persistent_items(self): |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
152 return True |
39
788114f9b5bc
Added get_supported_affiliations() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
34
diff
changeset
|
153 |
65
d617f8d19263
Add get_node_type() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
61
diff
changeset
|
154 def get_node_type(self, node_id): |
72
a914cad421c5
Added get_nodes() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
65
diff
changeset
|
155 return self.storage.get_node_type(node_id) |
a914cad421c5
Added get_nodes() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
65
diff
changeset
|
156 |
a914cad421c5
Added get_nodes() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
65
diff
changeset
|
157 def get_nodes(self): |
a914cad421c5
Added get_nodes() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
65
diff
changeset
|
158 return self.storage.get_nodes() |
65
d617f8d19263
Add get_node_type() to BackendService.
Ralph Meijer <ralphm@ik.nu>
parents:
61
diff
changeset
|
159 |
44
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
160 class PublishService(service.Service): |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
161 |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
162 __implements__ = IPublishService, |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
163 |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
164 def publish(self, node_id, items, requestor): |
44
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
165 d1 = self.parent.storage.get_node_configuration(node_id) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
166 d2 = self.parent.storage.get_affiliation(node_id, requestor) |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
167 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
168 d.addErrback(lambda x: x.value[0]) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
169 d.addCallback(self._do_publish, node_id, items, requestor) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
170 return d |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
171 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
172 def _do_publish(self, result, node_id, items, requestor): |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
173 configuration = result[0][1] |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
174 persist_items = configuration["persist_items"] |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
175 deliver_payloads = configuration["deliver_payloads"] |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
176 affiliation = result[1][1] |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
177 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
178 if affiliation not in ['owner', 'publisher']: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
179 raise NotAuthorized |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
180 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
181 if items and not persist_items and not deliver_payloads: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
182 raise NoPayloadAllowed |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
183 elif not items and (persist_items or deliver_payloads): |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
184 raise PayloadExpected |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
185 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
186 print "publish by %s to %s" % (requestor.full(), node_id) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
187 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
188 if persist_items or deliver_payloads: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
189 for item in items: |
84 | 190 if not item.getAttribute("id"): |
191 item["id"] = sha.new(str(time.time()) + | |
192 requestor.full()).hexdigest() | |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
193 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
194 if persist_items: |
44
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
195 d = self.parent.storage.store_items(node_id, items, |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
196 requestor) |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
197 else: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
198 d = defer.succeed(None) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
199 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
200 d.addCallback(self._do_notify, node_id, items, deliver_payloads) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
201 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
202 def _do_notify(self, result, node_id, items, deliver_payloads): |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
203 if items and not deliver_payloads: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
204 for item in items: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
205 item.children = [] |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
206 |
44
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
207 self.parent.dispatch({ 'items': items, 'node_id': node_id }, |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
208 '//event/pubsub/notify') |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
209 |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
210 class NotificationService(service.Service): |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
211 |
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
212 __implements__ = INotificationService, |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
213 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
214 def get_notification_list(self, node_id, items): |
44
bc7438476a67
Removed IPersistenceService, this is a feature of the storage facility.
Ralph Meijer <ralphm@ik.nu>
parents:
43
diff
changeset
|
215 d = self.parent.storage.get_subscribers(node_id) |
43
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
216 d.addCallback(self._magic_filter, node_id, items) |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
217 return d |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
218 |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
219 def _magic_filter(self, subscribers, node_id, items): |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
220 list = {} |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
221 for subscriber in subscribers: |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
222 list[subscriber] = items |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
223 return list |
9685b7e291ef
Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents:
39
diff
changeset
|
224 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
225 def register_notifier(self, observerfn, *args, **kwargs): |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
226 self.parent.addObserver('//event/pubsub/notify', observerfn, |
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
227 *args, **kwargs) |
49
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
228 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
229 class SubscriptionService(service.Service): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
230 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
231 __implements__ = ISubscriptionService, |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
232 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
233 def subscribe(self, node_id, subscriber, requestor): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
234 if subscriber.userhostJID() != requestor: |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
235 raise NotAuthorized |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
236 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
237 d1 = self.parent.storage.get_node_configuration(node_id) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
238 d2 = self.parent.storage.get_affiliation(node_id, subscriber) |
49
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
239 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
240 d.addErrback(lambda x: x.value[0]) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
241 d.addCallback(self._do_subscribe, node_id, subscriber) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
242 return d |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
243 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
244 def _do_subscribe(self, result, node_id, subscriber): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
245 configuration = result[0][1] |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
246 affiliation = result[1][1] |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
247 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
248 if affiliation == 'outcast': |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
249 raise NotAuthorized |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
250 |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
251 d = self.parent.storage.add_subscription(node_id, subscriber, |
49
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
252 'subscribed') |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
253 d.addCallback(self._return_subscription, affiliation) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
254 return d |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
255 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
256 def _return_subscription(self, result, affiliation): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
257 result['affiliation'] = affiliation |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
258 return result |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
259 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
260 def unsubscribe(self, node_id, subscriber, requestor): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
261 if subscriber.userhostJID() != requestor: |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
262 raise NotAuthorized |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
263 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
264 d = self.parent.storage.get_node_configuration(node_id) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
265 d.addCallback(self._do_unsubscribe, node_id, subscriber) |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
266 return d |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
267 |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
268 def _do_unsubscribe(self, result, node_id, subscriber): |
94e4ede2a357
Implement SubscriptionService with separate storage.
Ralph Meijer <ralphm@ik.nu>
parents:
44
diff
changeset
|
269 return self.parent.storage.remove_subscription(node_id, |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
270 subscriber) |
53
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
271 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
272 class NodeCreationService(service.Service): |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
273 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
274 __implements__ = INodeCreationService, |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
275 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
276 def supports_instant_nodes(self): |
84 | 277 return True |
53
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
278 |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
279 def create_node(self, node_id, requestor): |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
280 if not node_id: |
84 | 281 node_id = 'generic/%s' % sha.new(str(time.time()) + |
282 requestor.full()).hexdigest() | |
53
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
283 |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
284 d = self.parent.storage.create_node(node_id, requestor) |
53
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
285 d.addCallback(lambda _: node_id) |
e602ddda2d6e
Implement NodeCreationService, using the create_node() method of Storage.
Ralph Meijer <ralphm@ik.nu>
parents:
49
diff
changeset
|
286 return d |
61 | 287 |
288 class AffiliationsService(service.Service): | |
289 | |
290 __implements__ = IAffiliationsService, | |
291 | |
292 def get_affiliations(self, entity): | |
293 d1 = self.parent.storage.get_affiliations(entity) | |
294 d2 = self.parent.storage.get_subscriptions(entity) | |
295 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) | |
296 d.addErrback(lambda x: x.value[0]) | |
297 d.addCallback(self._affiliations_result, entity) | |
298 return d | |
299 | |
300 def _affiliations_result(self, result, entity): | |
301 affiliations = result[0][1] | |
302 subscriptions = result[1][1] | |
303 | |
304 new_affiliations = {} | |
305 | |
306 for node, affiliation in affiliations: | |
307 new_affiliations[(node, entity.full())] = {'node': node, | |
308 'jid': entity, | |
309 'affiliation': affiliation, | |
310 'subscription': None | |
311 } | |
312 | |
313 for node, subscriber, subscription in subscriptions: | |
314 key = node, subscriber.full() | |
315 if new_affiliations.has_key(key): | |
316 new_affiliations[key]['subscription'] = subscription | |
317 else: | |
318 new_affiliations[key] = {'node': node, | |
319 'jid': subscriber, | |
320 'affiliation': None, | |
321 'subscription': subscription} | |
322 | |
323 return new_affiliations.values() | |
80
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
324 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
325 class ItemRetrievalService(service.Service): |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
326 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
327 __implements__ = IItemRetrievalService |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
328 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
329 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
330 d = self.parent.storage.is_subscribed(node_id, requestor) |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
331 d.addCallback(self._do_get_items, node_id, max_items, item_ids) |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
332 return d |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
333 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
334 def _do_get_items(self, result, node_id, max_items, item_ids): |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
335 def q(r): |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
336 print r |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
337 return r |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
338 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
339 if not result: |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
340 raise NotAuthorized |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
341 |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
342 if item_ids: |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
343 d = self.parent.storage.get_items_by_ids(node_id, item_ids) |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
344 d.addCallback(q) |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
345 d.addErrback(q) |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
346 return d |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
347 else: |
ec354aab3949
Implemented ItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
72
diff
changeset
|
348 return self.parent.storage.get_items(node_id, max_items) |
85
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
349 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
350 class RetractionService(service.Service): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
351 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
352 __implements__ = IRetractionService, |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
353 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
354 def retract_item(self, node_id, item_ids, requestor): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
355 d1 = self.parent.storage.get_node_configuration(node_id) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
356 d2 = self.parent.storage.get_affiliation(node_id, requestor) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
357 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
358 d.addErrback(lambda x: x.value[0]) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
359 d.addCallback(self._do_retract, node_id, item_ids) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
360 return d |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
361 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
362 def _do_retract(self, result, node_id, item_ids): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
363 configuration = result[0][1] |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
364 persist_items = configuration["persist_items"] |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
365 affiliation = result[1][1] |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
366 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
367 if affiliation not in ['owner', 'publisher']: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
368 raise NotAuthorized |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
369 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
370 if not persist_items: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
371 raise NodeNotPersistent |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
372 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
373 d = self.parent.storage.remove_items(node_id, item_ids) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
374 d.addCallback(self._do_notify_retraction, node_id) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
375 return d |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
376 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
377 def _do_notify_retraction(self, result, node_id): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
378 self.parent.dispatch({ 'item_ids': result, 'node_id': node_id }, |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
379 '//event/pubsub/retract') |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
380 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
381 def purge_node(self, node_id, requestor): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
84
diff
changeset
|
382 pass |