Skip to content

Commit bcabf86

Browse files
committed
Merge pull request #118 from surevine/conf-updates
Node configuration setting and overrides
2 parents bfef4a7 + 19d445c commit bcabf86

File tree

6 files changed

+298
-157
lines changed

6 files changed

+298
-157
lines changed

configuration.properties.example

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
2727
# NOTE: This will only work on local private channels
2828
channels.autosubscribe.autoapprove=false
2929

30-
# Default channels configuration related to access and permissions
31-
channels.default.accessmodel=open
32-
channels.default.role=follower+post
30+
# Channel configuration related to access model and affiliation
31+
32+
channel.configuration.default.accessmodel=open
33+
channel.configuration.default.affiliation=member
34+
35+
# Overrides for default configuration
36+
channel.configuration.posts.affiliation=publisher
37+
38+
channel.configuration.geo.next.accessmodel=authorize
39+
channel.configuration.geo.current.accessmodel=authorize
40+
channel.configuration.geo.previous.accessmodel=authorize
41+
42+
channel.configuration.status.description=%jid%'s status
43+
channel.configuration.status.description=The current status of %jid%

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public class Configuration extends Properties {
2828

2929
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE = "channels.autosubscribe";
3030
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE_AUTOAPPROVE = "channels.autosubscribe.autoapprove";
31-
public static final String CONFIGURATION_CHANNELS_DEFAULT_ROLE = "channels.default.role";
32-
public static final String CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL = "channels.default.accessmodel";
31+
public static final String CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION = "channel.configuration.default.affiliation";
32+
public static final String CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL = "channel.configuration.default.accessmodel";
33+
public static final String CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION = "channel.configuration.default.description";
34+
public static final String CONFIGURATION_CHANNELS_DEFAULT_TITLE = "channel.configuration.default.title";
3335

3436
private static final String CONFIGURATION_FILE = "configuration.properties";
37+
3538
private static Configuration instance = null;
3639

3740
private Collection<JID> adminUsers = new ArrayList<JID>();
@@ -42,14 +45,16 @@ public class Configuration extends Properties {
4245
private Configuration() {
4346
try {
4447
conf = new Properties();
45-
InputStream confFile = this.getClass().getClassLoader().getResourceAsStream(CONFIGURATION_FILE);
46-
if(confFile != null) {
48+
InputStream confFile = this.getClass().getClassLoader()
49+
.getResourceAsStream(CONFIGURATION_FILE);
50+
if (confFile != null) {
4751
load(confFile);
4852
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from classpath.");
4953
} else {
5054
File f = new File(CONFIGURATION_FILE);
5155
load(new FileInputStream(f));
52-
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from working directory.");
56+
LOGGER.info("Loaded " + CONFIGURATION_FILE
57+
+ " from working directory.");
5358
}
5459
} catch (Exception e) {
5560
LOGGER.error("Could not load " + CONFIGURATION_FILE + "!");
@@ -125,20 +130,21 @@ public String getServerTopicsDomain() {
125130
return getProperty(CONFIGURATION_SERVER_TOPICS_DOMAIN);
126131
}
127132

128-
public boolean getBooleanProperty(
129-
final String key, final boolean defaultValue) {
133+
public boolean getBooleanProperty(final String key,
134+
final boolean defaultValue) {
130135
String value = getProperty(key);
131-
132-
if(value != null) {
133-
if(value.equalsIgnoreCase("true")) {
136+
137+
if (value != null) {
138+
if (value.equalsIgnoreCase("true")) {
134139
return true;
135140
}
136-
if(value.equalsIgnoreCase("false")) {
141+
if (value.equalsIgnoreCase("false")) {
137142
return false;
138143
}
139-
LOGGER.warn("Invalid boolean property value for " + key + ": " + value);
144+
LOGGER.warn("Invalid boolean property value for " + key + ": "
145+
+ value);
140146
}
141-
147+
142148
return defaultValue;
143149
}
144150
}

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

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,45 @@ public class Conf {
2828
public static final String NOTIFY_CONFIG = "pubsub#notify_config";
2929
public static final String CHANNEL_TYPE = "buddycloud#channel_type";
3030
private static final String PUBLISHERS = "publishers";
31-
public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat.dateTimeParser();
32-
public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat.dateTime();
31+
public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat
32+
.dateTimeParser();
33+
public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat
34+
.dateTime();
35+
36+
private static Configuration projectConf;
37+
private static HashMap<String, String> conf;
3338

3439
public static String getPostChannelNodename(JID channelJID) {
3540
return "/user/" + channelJID.toBareJID() + "/posts";
3641
}
3742

3843
/**
3944
* Parses a ISO 8601 to a string
40-
*
45+
*
4146
* @param iso8601Str
4247
* @return
43-
* @throws IllegalArgumentException if the provided string is not ISO 8601
48+
* @throws IllegalArgumentException
49+
* if the provided string is not ISO 8601
4450
*/
45-
public static Date parseDate(String iso8601Str) throws IllegalArgumentException {
51+
public static Date parseDate(String iso8601Str)
52+
throws IllegalArgumentException {
4653
return ISO_8601_PARSER.parseDateTime(iso8601Str).toDate();
4754
}
4855

4956
public static String formatDate(Date date) {
5057
return ISO_8601_FORMATTER.print(date.getTime());
5158
}
5259

53-
public static HashMap<String, String> getDefaultChannelConf(JID channelJID, JID ownerJID) {
54-
HashMap<String, String> conf = getDefaultConf(channelJID);
55-
conf.put(TITLE, channelJID.toBareJID() + "'s title");
56-
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s description");
60+
public static HashMap<String, String> getDefaultChannelConf(JID channelJID,
61+
JID ownerJID) {
62+
HashMap<String, String> conf = getDefaultConf(channelJID, null);
5763
conf.put(OWNER, ownerJID.toBareJID());
5864
return conf;
5965
}
6066

61-
public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) {
62-
HashMap<String, String> conf = getDefaultConf(channelJID);
63-
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud channel!");
64-
conf.put(DESCRIPTION, "This channel belongs to " + channelJID.toBareJID() + ". To nobody else!");
67+
public static HashMap<String, String> getDefaultPostChannelConf(
68+
JID channelJID) {
69+
HashMap<String, String> conf = getDefaultConf(channelJID, "posts");
6570
conf.put(CHANNEL_TYPE, "personal");
6671
return conf;
6772
}
@@ -70,71 +75,141 @@ public static String getStatusChannelNodename(JID channelJID) {
7075
return "/user/" + channelJID.toBareJID() + "/status";
7176
}
7277

73-
public static HashMap<String, String> getDefaultStatusChannelConf(JID channelJID) {
74-
HashMap<String, String> conf = getDefaultConf(channelJID);
75-
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud status!");
76-
conf.put(DESCRIPTION, "This is " + channelJID.toBareJID() + "'s mood a.k.a status -channel. Depends how geek you are.");
78+
public static HashMap<String, String> getDefaultStatusChannelConf(
79+
JID channelJID) {
80+
HashMap<String, String> conf = getDefaultConf(channelJID, "status");
7781
return conf;
7882
}
7983

8084
public static String getGeoPreviousChannelNodename(JID channelJID) {
8185
return "/user/" + channelJID.toBareJID() + "/geo/previous";
8286
}
8387

84-
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(JID channelJID) {
85-
HashMap<String, String> conf = getDefaultConf(channelJID);
86-
conf.put(TITLE, channelJID.toBareJID() + "'s previous location.");
87-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " has been before.");
88+
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(
89+
JID channelJID) {
90+
HashMap<String, String> conf = getDefaultConf(channelJID,
91+
"geo/previous");
8892
return conf;
8993
}
9094

9195
public static String getGeoCurrentChannelNodename(JID channelJID) {
9296
return "/user/" + channelJID.toBareJID() + "/geo/current";
9397
}
9498

95-
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(JID channelJID) {
96-
HashMap<String, String> conf = getDefaultConf(channelJID);
97-
conf.put(TITLE, channelJID.toBareJID() + "'s current location.");
98-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is now.");
99+
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(
100+
JID channelJID) {
101+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/current");
99102
return conf;
100103
}
101104

102105
public static String getGeoNextChannelNodename(JID channelJID) {
103106
return "/user/" + channelJID.toBareJID() + "/geo/next";
104107
}
105108

106-
public static HashMap<String, String> getDefaultGeoNextChannelConf(JID channelJID) {
107-
HashMap<String, String> conf = getDefaultConf(channelJID);
108-
conf.put(TITLE, channelJID.toBareJID() + "'s next location.");
109-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is going to go.");
109+
public static HashMap<String, String> getDefaultGeoNextChannelConf(
110+
JID channelJID) {
111+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/next");
110112
return conf;
111113
}
112114

113115
public static String getSubscriptionsChannelNodename(JID channelJID) {
114116
return "/user/" + channelJID.toBareJID() + "/subscriptions";
115117
}
116118

117-
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(JID channelJID) {
118-
HashMap<String, String> conf = getDefaultConf(channelJID);
119-
conf.put(TITLE, channelJID.toBareJID() + "'s susbcriptions.");
120-
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s subscriptions. ");
119+
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(
120+
JID channelJID) {
121+
HashMap<String, String> conf = getDefaultConf(channelJID,
122+
"subscriptions");
121123
return conf;
122124
}
123125

124-
private static HashMap<String, String> getDefaultConf(JID channelJID) {
125-
HashMap<String, String> conf = new HashMap<String, String>();
126-
Configuration projectConf = Configuration.getInstance();
126+
private static HashMap<String, String> getDefaultConf(JID channelJID,
127+
String node) {
128+
129+
conf = new HashMap<String, String>();
130+
projectConf = Configuration.getInstance();
131+
conf.put(
132+
TITLE,
133+
projectConf.getProperty(
134+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_TITLE,
135+
"%jid%'s very own buddycloud channel").replace("%jid%",
136+
channelJID.toBareJID()));
137+
138+
conf.put(
139+
DESCRIPTION,
140+
projectConf
141+
.getProperty(
142+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION,
143+
"%jid%'s very own buddycloud channel").replace(
144+
"%jid%", channelJID.toBareJID()));
145+
127146
conf.put(TYPE, "http://www.w3.org/2005/Atom");
128147
conf.put(PUBLISH_MODEL, PUBLISHERS);
129148
conf.put(CREATION_DATE, formatDate(new Date()));
130149
conf.put(OWNER, channelJID.toBareJID());
131-
conf.put(ACCESS_MODEL, AccessModels.createFromString(projectConf.getProperty(
132-
Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL)).toString());
133-
conf.put(DEFAULT_AFFILIATION, Affiliations.createFromBuddycloudString(
134-
projectConf.getProperty(Configuration.CONFIGURATION_CHANNELS_DEFAULT_ROLE))
135-
.toString());
150+
151+
conf.put(
152+
ACCESS_MODEL,
153+
AccessModels
154+
.createFromString(
155+
projectConf
156+
.getProperty(
157+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL,
158+
AccessModels.open.toString()))
159+
.toString());
160+
conf.put(
161+
DEFAULT_AFFILIATION,
162+
Affiliations
163+
.createFromString(
164+
projectConf
165+
.getProperty(
166+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION,
167+
Affiliations.member.toString()))
168+
.toString());
136169
conf.put(NUM_SUBSCRIBERS, "1");
137170
conf.put(NOTIFY_CONFIG, "1");
171+
172+
getConfigurationOverrides(channelJID, node);
138173
return conf;
139174
}
175+
176+
private static void getConfigurationOverrides(JID channelJID, String node) {
177+
178+
if (null == node)
179+
return;
180+
181+
String accessModelKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL
182+
.replace("default", node.replace("/", "."));
183+
if (null != projectConf.getProperty(accessModelKey)) {
184+
conf.put(
185+
ACCESS_MODEL,
186+
AccessModels.createFromString(
187+
projectConf.getProperty(accessModelKey)).toString());
188+
}
189+
190+
String affiliationKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION
191+
.replace("default", node.replace("/", "."));
192+
if (null != projectConf.getProperty(affiliationKey)) {
193+
conf.put(
194+
DEFAULT_AFFILIATION,
195+
Affiliations.createFromString(
196+
projectConf.getProperty(affiliationKey)).toString());
197+
}
198+
String titleKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_TITLE
199+
.replace("default", node.replace("/", "."));
200+
201+
if (null != projectConf.getProperty(titleKey)) {
202+
String title = projectConf.getProperty(titleKey).replace("%jid%",
203+
channelJID.toBareJID());
204+
conf.put(TITLE, title);
205+
}
206+
String descriptionKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION
207+
.replace("default", node.replace("/", "."));
208+
if (null != projectConf.getProperty(descriptionKey)) {
209+
String description = projectConf.getProperty(descriptionKey)
210+
.replace("%jid%", channelJID.toBareJID());
211+
conf.put(DESCRIPTION, description);
212+
}
213+
214+
}
140215
}

src/main/java/org/buddycloud/channelserver/pubsub/affiliation/Affiliations.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ public static Affiliations createFromString(String asString) {
2121
}
2222
return none;
2323
}
24-
25-
public static Affiliations createFromBuddycloudString(String bcString) {
26-
27-
if ("producer".equals(bcString)) {
28-
return owner;
29-
} else if ("follower+post".equals(bcString)) {
30-
return publisher;
31-
} else if ("moderator".equals(bcString)) {
32-
return moderator;
33-
} else if ("follower".equals(bcString)) {
34-
return member;
35-
} else if ("none".equals(bcString)) {
36-
return none;
37-
} else if ("banned".equals(bcString)) {
38-
return outcast;
39-
}
40-
return none;
41-
}
4224

4325
public boolean in(Affiliations... affiliations) {
4426
for (Affiliations a : affiliations) {

0 commit comments

Comments
 (0)