Skip to content

Commit a2e1905

Browse files
author
Lloyd Watkin
committed
Merge branch 'master' of github.com:buddycloud/buddycloud-server-java into search
Conflicts: src/main/java/org/buddycloud/channelserver/channel/ChannelManagerImpl.java
2 parents 00323af + d9a549b commit a2e1905

90 files changed

Lines changed: 3162 additions & 569 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,39 @@ The java server purposefully uses the same database schema as the buddycloud nod
1414

1515
## Build and run
1616

17+
* install openjdk-6-jdk maven2
1718
* `git clone https://github.com/buddycloud/buddycloud-server-java`
1819
* `cd buddycloud-server-java`
1920
* `mvn package`
2021
* Edit configuration files as required
2122
* Install database
2223
* `java -jar target/channelserver-<VERSION>-jar-with-dependencies.jar
24+
25+
### Manually create the buddycloud server database
26+
27+
~~~~ {.bash}
28+
# switch to the postgres user
29+
sudo su - postgres
30+
~~~~
31+
32+
Create a database user and assign it a password (it will not work with a blank password);
33+
~~~~ {.bash}
34+
createuser buddycloud_server --pwprompt --no-superuser --no-createdb --no-createrole
35+
~~~~
36+
37+
Then just proceed as follows, entering the password you picked whenever asked.
38+
~~~~ {.bash}
39+
# create the database
40+
createdb --owner buddycloud_server --encoding UTF8 buddycloud_server
41+
42+
# install the schema file (and all upgrade files)
43+
psql -h 127.0.0.1 -U buddycloud_server -d buddycloud_server < postgres/install.sql
44+
psql -h 127.0.0.1 -U buddycloud_server -d buddycloud_server < postgres/upgrade-1.sql
45+
psql -h 127.0.0.1 -U buddycloud_server -d buddycloud_server < postgres/upgrade-2.sql
46+
~~~~
47+
48+
Now we're done, but we must test that we can connect to the database and that the schema was installed appropriately.
49+
~~~~ {.bash}
50+
psql -h 127.0.0.1 --username buddycloud_server -d buddycloud_server -c "select * from nodes;"
51+
~~~~
52+
If you got an output similar to (or exactly like) this, you're good to go.

contrib/init.d/buddycloud-server-java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DESC="buddycloud java server"
77
NAME="buddycloud-server-java"
88
RUNFROM=/usr/share/buddycloud-server-java
99
DAEMON=/usr/bin/java
10-
DAEMON_ARGS="-jar channelserver-*-jar-with-dependencies.jar"
10+
DAEMON_ARGS="-XX:-OmitStackTraceInFastThrow -jar channelserver-*-jar-with-dependencies.jar"
1111
PIDFILE=/var/run/$NAME.pid
1212
SCRIPTNAME=/etc/init.d/buddycloud-server-java
1313

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
<artifactId>log4jdbc-remix</artifactId>
124124
<version>0.2.3</version>
125125
</dependency>
126+
<dependency>
127+
<groupId>joda-time</groupId>
128+
<artifactId>joda-time</artifactId>
129+
<version>2.3</version>
130+
</dependency>
126131
</dependencies>
127132
<repositories>
128133
<repository>

postgres/upgrade-3.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BEGIN TRANSACTION;
2+
3+
-- Ensure there really are listeners
4+
5+
ALTER TABLE subscriptions ALTER COLUMN node set NOT NULL;
6+
ALTER TABLE subscriptions ALTER COLUMN "user" set NOT NULL;
7+
ALTER TABLE subscriptions ALTER COLUMN listener set NOT NULL;
8+
ALTER TABLE subscriptions ALTER COLUMN subscription set NOT NULL;
9+
ALTER TABLE subscriptions ALTER COLUMN updated set NOT NULL;
10+
11+
INSERT INTO schema_version (version, "when", description)
12+
VALUES (3, 'now', 'Added listeners constraint to subscriptions table');
13+
14+
COMMIT;

src/main/java/org/buddycloud/channelserver/ChannelsEngine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void processPacket(Packet p) {
110110
}
111111

112112
public void sendPacket(Packet p) throws ComponentException {
113+
LOGGER.debug("OUT -> " + p.toXML());
113114
manager.sendPacket(this, p);
114115
}
115116

src/main/java/org/buddycloud/channelserver/TopicsEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ public void processPacket(Packet p) {
6767
} catch (NullPointerException e) {
6868
// Catch and ignore
6969
e.printStackTrace();
70+
logger.error(e);
7071
} catch (ComponentException e) {
7172
// TODO Auto-generated catch block
7273
e.printStackTrace();
74+
logger.error(e);
7375
}
7476
logger.info("Topic component does not handle these packets: '" + p.toXML()
7577
+ "'.");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Properties;
44

5-
import org.buddycloud.channelserver.Configuration;
65
import org.buddycloud.channelserver.db.NodeStoreFactory;
76

87
public class ChannelManagerFactoryImpl implements ChannelManagerFactory {

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.buddycloud.channelserver.pubsub.model.NodeAffiliation;
1818
import org.buddycloud.channelserver.pubsub.model.NodeItem;
1919
import org.buddycloud.channelserver.pubsub.model.NodeSubscription;
20+
import org.buddycloud.channelserver.pubsub.model.NodeThread;
2021
import org.xmpp.packet.JID;
2122
import org.xmpp.resultsetmanagement.ResultSet;
2223

@@ -320,6 +321,7 @@ public void createPersonalChannel(JID owner) throws NodeStoreException {
320321
@Override
321322
public boolean isLocalNode(String nodeId) {
322323
if (false == nodeId.matches("/user/.+@.+/.+")) {
324+
logger.debug("Node " + nodeId + " has an invalid format");
323325
throw new IllegalArgumentException(INVALID_NODE);
324326
}
325327
return ((true == nodeId
@@ -359,11 +361,16 @@ public ResultSet<NodeSubscription> getNodeSubscriptionListeners(
359361
String nodeId) throws NodeStoreException {
360362
return nodeStore.getNodeSubscriptionListeners(nodeId);
361363
}
364+
365+
@Override
366+
public ResultSet<NodeSubscription> getNodeSubscriptionListeners()
367+
throws NodeStoreException {
368+
return nodeStore.getNodeSubscriptionListeners();
369+
}
362370

363371
@Override
364372
public void deleteNode(String nodeId) throws NodeStoreException {
365373
nodeStore.deleteNode(nodeId);
366-
367374
}
368375

369376
@Override
@@ -438,4 +445,36 @@ public CloseableIterator<NodeItem> performSearch(JID searcher,
438445
List content, JID author, int page, int rpp) throws NodeStoreException {
439446
return nodeStore.performSearch(searcher, content, author, page, rpp);
440447
}
448+
449+
@Override
450+
public ResultSet<NodeItem> getUserItems(JID userJid) throws NodeStoreException {
451+
return nodeStore.getUserItems(userJid);
452+
}
453+
454+
@Override
455+
public void deleteUserItems(JID userJid) throws NodeStoreException {
456+
nodeStore.deleteUserItems(userJid);
457+
}
458+
459+
@Override
460+
public void deleteUserAffiliations(JID userJid) throws NodeStoreException {
461+
nodeStore.deleteUserAffiliations(userJid);
462+
}
463+
464+
@Override
465+
public void deleteUserSubscriptions(JID userJid) throws NodeStoreException {
466+
nodeStore.deleteUserSubscriptions(userJid);
467+
}
468+
469+
@Override
470+
public ResultSet<NodeThread> getNodeThreads(String node, String afterId,
471+
int limit) throws NodeStoreException {
472+
return nodeStore.getNodeThreads(node, afterId, limit);
473+
}
474+
475+
@Override
476+
public int countNodeThreads(String node) throws NodeStoreException {
477+
return nodeStore.countNodeThreads(node);
478+
}
479+
441480
}

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

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.buddycloud.channelserver.channel;
22

3-
import java.text.SimpleDateFormat;
43
import java.util.Date;
54
import java.util.HashMap;
6-
import java.util.TimeZone;
7-
import org.buddycloud.channelserver.pubsub.affiliation.Affiliations;
8-
import org.buddycloud.channelserver.pubsub.publishmodel.PublishModels;
5+
96
import org.buddycloud.channelserver.pubsub.accessmodel.AccessModels;
7+
import org.buddycloud.channelserver.pubsub.affiliation.Affiliations;
8+
import org.joda.time.format.DateTimeFormatter;
9+
import org.joda.time.format.ISODateTimeFormat;
1010
import org.xmpp.packet.JID;
1111

1212
//TODO! Refactor this!
@@ -27,28 +27,57 @@ public class Conf {
2727

2828
private static final String PUBLISHERS = "publishers";
2929

30-
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S'Z'";
31-
32-
30+
public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat.dateTimeParser();
31+
public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat.dateTime();
32+
3333
// Most of these are copied from here
3434
// https://github.com/buddycloud/buddycloud-server/blob/master/src/local/operations.coffee#L14
3535

3636
public static String getPostChannelNodename(JID channelJID) {
3737
return "/user/" + channelJID.toBareJID() + "/posts";
3838
}
39+
40+
/**
41+
* Parses a ISO 8601 to a string
42+
*
43+
* @param iso8601Str
44+
* @return
45+
* @throws IllegalArgumentException if the provided string is not ISO 8601
46+
*/
47+
public static Date parseDate(String iso8601Str) throws IllegalArgumentException {
48+
return ISO_8601_PARSER.parseDateTime(iso8601Str).toDate();
49+
}
50+
51+
public static String formatDate(Date date) {
52+
return ISO_8601_FORMATTER.print(date.getTime());
53+
}
3954

40-
public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) {
41-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
42-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
55+
public static HashMap<String, String> getDefaultChannelConf(JID channelJID, JID ownerJID) {
56+
HashMap<String, String> conf = new HashMap<String, String>();
57+
58+
conf.put(TYPE, "http://www.w3.org/2005/Atom");
59+
conf.put(TITLE, channelJID.toBareJID() + "'s title");
60+
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s description");
61+
conf.put(PUBLISH_MODEL, PUBLISHERS);
62+
conf.put(ACCESS_MODEL, AccessModels.open.toString());
63+
conf.put(CREATION_DATE, formatDate(new Date()));
64+
conf.put(OWNER, ownerJID.toBareJID());
65+
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
66+
conf.put(NUM_SUBSCRIBERS, "1");
67+
conf.put(NOTIFY_CONFIG, "1");
4368

69+
return conf;
70+
}
71+
72+
public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) {
4473
HashMap<String, String> conf = new HashMap<String, String>();
4574

4675
conf.put(TYPE, "http://www.w3.org/2005/Atom");
4776
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud channel!");
4877
conf.put(DESCRIPTION, "This channel belongs to " + channelJID.toBareJID() + ". To nobody else!");
4978
conf.put(PUBLISH_MODEL, PUBLISHERS);
5079
conf.put(ACCESS_MODEL, AccessModels.open.toString());
51-
conf.put(CREATION_DATE, sdf.format(new Date()));
80+
conf.put(CREATION_DATE, formatDate(new Date()));
5281
conf.put(OWNER, channelJID.toBareJID());
5382
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
5483
conf.put(NUM_SUBSCRIBERS, "1");
@@ -63,17 +92,14 @@ public static String getStatusChannelNodename(JID channelJID) {
6392
}
6493

6594
public static HashMap<String, String> getDefaultStatusChannelConf(JID channelJID) {
66-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
67-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
68-
6995
HashMap<String, String> conf = new HashMap<String, String>();
7096

7197
conf.put(TYPE, "http://www.w3.org/2005/Atom");
7298
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud status!");
7399
conf.put(DESCRIPTION, "This is " + channelJID.toBareJID() + "'s mood a.k.a status -channel. Depends how geek you are.");
74100
conf.put(PUBLISH_MODEL, PUBLISHERS);
75101
conf.put(ACCESS_MODEL, AccessModels.open.toString());
76-
conf.put(CREATION_DATE, sdf.format(new Date()));
102+
conf.put(CREATION_DATE, formatDate(new Date()));
77103
conf.put(OWNER, channelJID.toBareJID());
78104
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
79105
conf.put(NUM_SUBSCRIBERS, "1");
@@ -87,17 +113,14 @@ public static String getGeoPreviousChannelNodename(JID channelJID) {
87113
}
88114

89115
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(JID channelJID) {
90-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
91-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
92-
93116
HashMap<String, String> conf = new HashMap<String, String>();
94117

95118
conf.put(TYPE, "http://www.w3.org/2005/Atom");
96119
conf.put(TITLE, channelJID.toBareJID() + "'s previous location.");
97120
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " has been before.");
98121
conf.put(PUBLISH_MODEL, PUBLISHERS);
99122
conf.put(ACCESS_MODEL, AccessModels.open.toString());
100-
conf.put(CREATION_DATE, sdf.format(new Date()));
123+
conf.put(CREATION_DATE, formatDate(new Date()));
101124
conf.put(OWNER, channelJID.toBareJID());
102125
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
103126
conf.put(NUM_SUBSCRIBERS, "1");
@@ -111,17 +134,14 @@ public static String getGeoCurrentChannelNodename(JID channelJID) {
111134
}
112135

113136
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(JID channelJID) {
114-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
115-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
116-
117137
HashMap<String, String> conf = new HashMap<String, String>();
118138

119139
conf.put(TYPE, "http://www.w3.org/2005/Atom");
120140
conf.put(TITLE, channelJID.toBareJID() + "'s current location.");
121141
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is now.");
122142
conf.put(PUBLISH_MODEL, PUBLISHERS);
123143
conf.put(ACCESS_MODEL, AccessModels.open.toString());
124-
conf.put(CREATION_DATE, sdf.format(new Date()));
144+
conf.put(CREATION_DATE, formatDate(new Date()));
125145
conf.put(OWNER, channelJID.toBareJID());
126146
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
127147
conf.put(NUM_SUBSCRIBERS, "1");
@@ -135,17 +155,14 @@ public static String getGeoNextChannelNodename(JID channelJID) {
135155
}
136156

137157
public static HashMap<String, String> getDefaultGeoNextChannelConf(JID channelJID) {
138-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
139-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
140-
141158
HashMap<String, String> conf = new HashMap<String, String>();
142159

143160
conf.put(TYPE, "http://www.w3.org/2005/Atom");
144161
conf.put(TITLE, channelJID.toBareJID() + "'s next location.");
145162
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is going to go.");
146163
conf.put(PUBLISH_MODEL, PUBLISHERS);
147164
conf.put(ACCESS_MODEL, AccessModels.open.toString());
148-
conf.put(CREATION_DATE, sdf.format(new Date()));
165+
conf.put(CREATION_DATE, formatDate(new Date()));
149166
conf.put(OWNER, channelJID.toBareJID());
150167
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
151168
conf.put(NUM_SUBSCRIBERS, "1");
@@ -159,17 +176,14 @@ public static String getSubscriptionsChannelNodename(JID channelJID) {
159176
}
160177

161178
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(JID channelJID) {
162-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
163-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
164-
165179
HashMap<String, String> conf = new HashMap<String, String>();
166180

167181
conf.put(TYPE, "http://www.w3.org/2005/Atom");
168182
conf.put(TITLE, channelJID.toBareJID() + "'s susbcriptions.");
169183
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s subscriptions. ");
170184
conf.put(PUBLISH_MODEL, PUBLISHERS);
171185
conf.put(ACCESS_MODEL, AccessModels.open.toString());
172-
conf.put(CREATION_DATE, sdf.format(new Date()));
186+
conf.put(CREATION_DATE, formatDate(new Date()));
173187
conf.put(OWNER, channelJID.toBareJID());
174188
conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString());
175189
conf.put(NUM_SUBSCRIBERS, "1");

0 commit comments

Comments
 (0)