Skip to content

Commit fc09973

Browse files
author
Lloyd Watkin
committed
Tests all passing with new interface
1 parent e8f453d commit fc09973

20 files changed

Lines changed: 242 additions & 102 deletions

File tree

src/main/java/org/buddycloud/channelserver/channel/ChannelManagerImpl.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ public int countUserAffiliations(JID jid) throws NodeStoreException {
132132
}
133133

134134
@Override
135-
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId)
135+
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId, boolean isOwnerModerator)
136136
throws NodeStoreException {
137-
return nodeStore.getNodeAffiliations(nodeId);
137+
return nodeStore.getNodeAffiliations(nodeId, isOwnerModerator);
138138
}
139139

140140
@Override
141-
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId,
141+
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId, boolean isOwnerModerator,
142142
String afterItemId, int maxItemsToReturn) throws NodeStoreException {
143-
return nodeStore.getNodeAffiliations(nodeId, afterItemId,
143+
return nodeStore.getNodeAffiliations(nodeId, isOwnerModerator, afterItemId,
144144
maxItemsToReturn);
145145
}
146146

@@ -150,8 +150,8 @@ public ArrayList<JID> getNodeOwners(String node) throws NodeStoreException {
150150
}
151151

152152
@Override
153-
public int countNodeAffiliations(String nodeId) throws NodeStoreException {
154-
return nodeStore.countNodeAffiliations(nodeId);
153+
public int countNodeAffiliations(String nodeId, boolean isOwnerModerator) throws NodeStoreException {
154+
return nodeStore.countNodeAffiliations(nodeId, isOwnerModerator);
155155
}
156156

157157
@Override
@@ -185,21 +185,23 @@ public int countUserSubscriptions(JID user) throws NodeStoreException {
185185
}
186186

187187
@Override
188-
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId)
189-
throws NodeStoreException {
190-
return nodeStore.getNodeSubscriptions(nodeId);
188+
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId,
189+
boolean isOwnerModerator) throws NodeStoreException {
190+
return nodeStore.getNodeSubscriptions(nodeId, isOwnerModerator);
191191
}
192192

193193
@Override
194194
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId,
195-
JID afterItemId, int maxItemsToReturn) throws NodeStoreException {
196-
return nodeStore.getNodeSubscriptions(nodeId, afterItemId,
197-
maxItemsToReturn);
195+
boolean isOwnerModerator, JID afterItemId, int maxItemsToReturn)
196+
throws NodeStoreException {
197+
return nodeStore.getNodeSubscriptions(nodeId, isOwnerModerator,
198+
afterItemId, maxItemsToReturn);
198199
}
199200

200201
@Override
201-
public int countNodeSubscriptions(String nodeId) throws NodeStoreException {
202-
return nodeStore.countNodeSubscriptions(nodeId);
202+
public int countNodeSubscriptions(String nodeId, boolean isOwnerModerator)
203+
throws NodeStoreException {
204+
return nodeStore.countNodeSubscriptions(nodeId, isOwnerModerator);
203205
}
204206

205207
@Override
@@ -258,7 +260,7 @@ public boolean isCachedNode(String nodeId) throws NodeStoreException {
258260
@Override
259261
public boolean nodeHasSubscriptions(String nodeId)
260262
throws NodeStoreException {
261-
return (nodeStore.countNodeSubscriptions(nodeId) > 0);
263+
return (nodeStore.countNodeSubscriptions(nodeId, false) > 0);
262264
}
263265

264266
public boolean isCachedJID(JID jid) throws NodeStoreException {
@@ -366,7 +368,7 @@ public ResultSet<NodeSubscription> getNodeSubscriptionListeners(
366368
String nodeId) throws NodeStoreException {
367369
return nodeStore.getNodeSubscriptionListeners(nodeId);
368370
}
369-
371+
370372
@Override
371373
public ResultSet<NodeSubscription> getNodeSubscriptionListeners()
372374
throws NodeStoreException {
@@ -431,28 +433,31 @@ public int getFirehoseItemCount(boolean isAdmin) throws NodeStoreException {
431433
@Override
432434
public Affiliations getDefaultNodeAffiliation(String nodeId)
433435
throws NodeStoreException {
434-
String affiliationString = getNodeConfValue(nodeId, Conf.DEFAULT_AFFILIATION);
435-
436-
if(affiliationString != null) {
436+
String affiliationString = getNodeConfValue(nodeId,
437+
Conf.DEFAULT_AFFILIATION);
438+
439+
if (affiliationString != null) {
437440
try {
438441
return Affiliations.valueOf(affiliationString);
439-
}
440-
catch(IllegalArgumentException e) {
441-
logger.error("Invalid default affiliation stored for node " + nodeId + ": " + affiliationString, e);
442+
} catch (IllegalArgumentException e) {
443+
logger.error("Invalid default affiliation stored for node "
444+
+ nodeId + ": " + affiliationString, e);
442445
}
443446
}
444-
447+
445448
return Affiliations.member;
446449
}
447450

448451
@Override
449452
public CloseableIterator<NodeItem> performSearch(JID searcher,
450-
List content, JID author, int page, int rpp) throws NodeStoreException {
453+
List content, JID author, int page, int rpp)
454+
throws NodeStoreException {
451455
return nodeStore.performSearch(searcher, content, author, page, rpp);
452456
}
453457

454458
@Override
455-
public ResultSet<NodeItem> getUserItems(JID userJid) throws NodeStoreException {
459+
public ResultSet<NodeItem> getUserItems(JID userJid)
460+
throws NodeStoreException {
456461
return nodeStore.getUserItems(userJid);
457462
}
458463

@@ -481,5 +486,4 @@ public ResultSet<NodeThread> getNodeThreads(String node, String afterId,
481486
public int countNodeThreads(String node) throws NodeStoreException {
482487
return nodeStore.countNodeThreads(node);
483488
}
484-
485489
}

src/main/java/org/buddycloud/channelserver/db/NodeStore.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ ResultSet<NodeAffiliation> getAffiliationChanges(JID user, Date startDate, Date
219219
* the node id
220220
* @return
221221
*/
222-
ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId)
222+
ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId, boolean isOwnerModerator)
223223
throws NodeStoreException;
224224

225225
/**
@@ -229,8 +229,8 @@ ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId)
229229
* @param afterItemId
230230
* @return
231231
*/
232-
ResultSet<NodeAffiliation> getNodeAffiliations(String node
233-
, String afterItemId, int maxItemsToReturn) throws NodeStoreException;
232+
ResultSet<NodeAffiliation> getNodeAffiliations(String node, boolean isOwnerModerator,
233+
String afterItemId, int maxItemsToReturn) throws NodeStoreException;
234234

235235
/**
236236
* Get a list of node owners
@@ -246,7 +246,7 @@ ResultSet<NodeAffiliation> getNodeAffiliations(String node
246246
* @param nodeId
247247
* @return
248248
*/
249-
int countNodeAffiliations(String nodeId) throws NodeStoreException;
249+
int countNodeAffiliations(String nodeId, boolean isOwnerModerator) throws NodeStoreException;
250250

251251
/**
252252
* Gets the set of nodes to which the user is subscribed.
@@ -289,9 +289,10 @@ ResultSet<NodeSubscription> getSubscriptionChanges(JID user,
289289
*
290290
* @param nodeId
291291
* the node reference.
292+
* @param isOwnerModerator
292293
* @return
293294
*/
294-
ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId)
295+
ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId, boolean isOwnerModerator)
295296
throws NodeStoreException;
296297

297298

@@ -304,7 +305,7 @@ ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId)
304305
* after this JID
305306
* @return
306307
*/
307-
ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId, JID afterItemId,
308+
ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId, boolean isOwnerModerator, JID afterItemId,
308309
int maxItemsToReturn) throws NodeStoreException;
309310

310311
/**
@@ -467,10 +468,11 @@ CloseableIterator<NodeItem> getRecentItems(JID user, Date since,
467468
*
468469
* @param nodeId
469470
* the node id from which to retrieve the item count.
471+
* @param isOwnerModerator
470472
* @return the entries count.
471473
* @throws NodeStoreException
472474
*/
473-
int countNodeSubscriptions(String nodeId) throws NodeStoreException;
475+
int countNodeSubscriptions(String nodeId, boolean isOwnerModerator) throws NodeStoreException;
474476

475477
/**
476478
* Retrieves a single node item by the node item id.

src/main/java/org/buddycloud/channelserver/db/jdbc/JDBCNodeStore.java

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,17 @@ public ResultSet<NodeAffiliation> getUserAffiliations(JID user,
500500
}
501501

502502
@Override
503-
public int countNodeAffiliations(String nodeId) throws NodeStoreException {
503+
public int countNodeAffiliations(String nodeId, boolean isOwnerModerator) throws NodeStoreException {
504504
PreparedStatement selectStatement = null;
505505

506506
try {
507-
selectStatement = conn.prepareStatement(dialect
508-
.countNodeAffiliations());
507+
if (true == isOwnerModerator) {
508+
selectStatement = conn.prepareStatement(dialect
509+
.countNodeAffiliationsForOwner());
510+
} else {
511+
selectStatement = conn.prepareStatement(dialect
512+
.countNodeAffiliations());
513+
}
509514
selectStatement.setString(1, nodeId);
510515

511516
java.sql.ResultSet rs = selectStatement.executeQuery();
@@ -524,13 +529,17 @@ public int countNodeAffiliations(String nodeId) throws NodeStoreException {
524529
}
525530

526531
@Override
527-
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId)
532+
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId, boolean isOwnerModerator)
528533
throws NodeStoreException {
529534

530535
PreparedStatement stmt = null;
531536

532537
try {
533-
stmt = conn.prepareStatement(dialect.selectAffiliationsForNode());
538+
if (true == isOwnerModerator) {
539+
stmt = conn.prepareStatement(dialect.selectAffiliationsToNodeForOwner());
540+
} else {
541+
stmt = conn.prepareStatement(dialect.selectAffiliationsForNode());
542+
}
534543
stmt.setString(1, nodeId);
535544

536545
java.sql.ResultSet rs = stmt.executeQuery();
@@ -554,13 +563,18 @@ public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId)
554563
}
555564

556565
@Override
557-
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId,
566+
public ResultSet<NodeAffiliation> getNodeAffiliations(String nodeId, boolean isOwnerModerator,
558567
String afterItemId, int maxItemsToReturn) throws NodeStoreException {
559568
PreparedStatement stmt = null;
560569

561570
try {
562-
stmt = conn.prepareStatement(dialect
563-
.selectAffiliationsForNodeAfterJid());
571+
if (true == isOwnerModerator) {
572+
stmt = conn.prepareStatement(dialect
573+
.selectAffiliationsToNodeForOwnerAfterJid());
574+
} else {
575+
stmt = conn.prepareStatement(dialect
576+
.selectAffiliationsForNodeAfterJid());
577+
}
564578
stmt.setString(1, nodeId);
565579
stmt.setString(2, nodeId);
566580
stmt.setString(3, afterItemId);
@@ -767,13 +781,17 @@ public ResultSet<NodeSubscription> getSubscriptionChanges(JID user,
767781
}
768782

769783
@Override
770-
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId)
784+
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId, boolean isOwnerModerator)
771785
throws NodeStoreException {
772786

773787
PreparedStatement stmt = null;
774788

775789
try {
776-
stmt = conn.prepareStatement(dialect.selectSubscriptionsForNode());
790+
if (true == isOwnerModerator) {
791+
stmt = conn.prepareStatement(dialect.selectSubscriptionsToNodeForOwner());
792+
} else {
793+
stmt = conn.prepareStatement(dialect.selectSubscriptionsForNode());
794+
}
777795
stmt.setString(1, nodeId);
778796

779797
java.sql.ResultSet rs = stmt.executeQuery();
@@ -796,8 +814,12 @@ public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId)
796814
}
797815
}
798816

817+
818+
@Override
799819
public ResultSet<NodeSubscription> getNodeSubscriptions(String nodeId,
800-
JID afterItemId, int maxItemsToReturn) throws NodeStoreException {
820+
boolean isOwnerModerator, JID afterItemId, int maxItemsToReturn)
821+
throws NodeStoreException {
822+
801823
PreparedStatement stmt = null;
802824

803825
String maxItems;
@@ -1646,11 +1668,17 @@ public boolean isCachedJID(JID jid) throws NodeStoreException {
16461668
}
16471669

16481670
@Override
1649-
public int countNodeSubscriptions(String nodeId) throws NodeStoreException {
1671+
public int countNodeSubscriptions(String nodeId, boolean isOwnerModerator) throws NodeStoreException {
16501672
PreparedStatement selectStatement = null;
16511673
try {
1652-
selectStatement = conn.prepareStatement(dialect
1653-
.countSubscriptionsForNode());
1674+
if (true == isOwnerModerator) {
1675+
selectStatement = conn.prepareStatement(dialect
1676+
.countSubscriptionsToNodeForOwner());
1677+
} else {
1678+
selectStatement = conn.prepareStatement(dialect
1679+
.countSubscriptionsForNode());
1680+
}
1681+
16541682
selectStatement.setString(1, nodeId);
16551683

16561684
java.sql.ResultSet rs = selectStatement.executeQuery();
@@ -1671,7 +1699,7 @@ public int countNodeSubscriptions(String nodeId) throws NodeStoreException {
16711699
@Override
16721700
public boolean nodeHasSubscriptions(String nodeId)
16731701
throws NodeStoreException {
1674-
return (this.countNodeSubscriptions(nodeId) > 0);
1702+
return (this.countNodeSubscriptions(nodeId, false) > 0);
16751703
}
16761704

16771705
@Override
@@ -1936,11 +1964,15 @@ public interface NodeStoreSQLDialect {
19361964
String selectRecentItemParts();
19371965

19381966
String countNodeAffiliations();
1967+
1968+
String countNodeAffiliationsForOwner();
19391969

19401970
String countUserAffiliations();
19411971

19421972
String countSubscriptionsForNode();
19431973

1974+
String countSubscriptionsToNodeForOwner();
1975+
19441976
String deleteItems();
19451977

19461978
String selectNodeList();
@@ -1966,8 +1998,12 @@ public interface NodeStoreSQLDialect {
19661998
String selectAffiliationsForUserAfterNodeId();
19671999

19682000
String selectAffiliationsForNode();
2001+
2002+
String selectAffiliationsToNodeForOwner();
19692003

19702004
String selectAffiliationsForNodeAfterJid();
2005+
2006+
String selectAffiliationsToNodeForOwnerAfterJid();
19712007

19722008
String selectAffiliationChanges();
19732009

@@ -1985,6 +2021,8 @@ public interface NodeStoreSQLDialect {
19852021

19862022
String getSubscriptionChanges();
19872023

2024+
String selectSubscriptionsToNodeForOwner();
2025+
19882026
String selectSubscriptionsForNode();
19892027

19902028
String selectSubscriptionsForNodeAfterJid();

0 commit comments

Comments
 (0)