|
2 | 2 |
|
3 | 3 | import java.util.Date; |
4 | 4 | import java.util.HashMap; |
| 5 | +import org.buddycloud.channelserver.Configuration; |
5 | 6 |
|
6 | 7 | import org.buddycloud.channelserver.pubsub.accessmodel.AccessModels; |
7 | 8 | import org.buddycloud.channelserver.pubsub.affiliation.Affiliations; |
8 | 9 | import org.joda.time.format.DateTimeFormatter; |
9 | 10 | import org.joda.time.format.ISODateTimeFormat; |
10 | 11 | import org.xmpp.packet.JID; |
11 | 12 |
|
12 | | -//TODO! Refactor this! |
13 | | -// Lot's of duplicate code plus other mayhem (like the SimpleDateFormat. |
| 13 | +/* |
| 14 | + * Most of these are copied from here |
| 15 | + * https://github.com/buddycloud/buddycloud-server/blob/master/src/local/operations.coffee#L14 |
| 16 | + */ |
14 | 17 | public class Conf { |
15 | 18 |
|
16 | | - public static final String TYPE = "pubsub#type"; |
17 | | - public static final String TITLE = "pubsub#title"; |
18 | | - public static final String DESCRIPTION = "pubsub#description"; |
19 | | - public static final String PUBLISH_MODEL = "pubsub#publish_model"; |
20 | | - public static final String ACCESS_MODEL = "pubsub#access_model"; |
21 | | - public static final String CREATION_DATE = "pubsub#creation_date"; |
22 | | - public static final String OWNER = "pubsub#owner"; |
23 | | - public static final String DEFAULT_AFFILIATION = "buddycloud#default_affiliation"; |
24 | | - public static final String NUM_SUBSCRIBERS = "pubsub#num_subscribers"; |
25 | | - public static final String NOTIFY_CONFIG = "pubsub#notify_config"; |
26 | | - public static final String CHANNEL_TYPE = "buddycloud#channel_type"; |
27 | | - |
| 19 | + public static final String TYPE = "pubsub#type"; |
| 20 | + public static final String TITLE = "pubsub#title"; |
| 21 | + public static final String DESCRIPTION = "pubsub#description"; |
| 22 | + public static final String PUBLISH_MODEL = "pubsub#publish_model"; |
| 23 | + public static final String ACCESS_MODEL = "pubsub#access_model"; |
| 24 | + public static final String CREATION_DATE = "pubsub#creation_date"; |
| 25 | + public static final String OWNER = "pubsub#owner"; |
| 26 | + public static final String DEFAULT_AFFILIATION = "buddycloud#default_affiliation"; |
| 27 | + public static final String NUM_SUBSCRIBERS = "pubsub#num_subscribers"; |
| 28 | + public static final String NOTIFY_CONFIG = "pubsub#notify_config"; |
| 29 | + public static final String CHANNEL_TYPE = "buddycloud#channel_type"; |
28 | 30 | private static final String PUBLISHERS = "publishers"; |
29 | | - |
30 | 31 | public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat.dateTimeParser(); |
31 | 32 | public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat.dateTime(); |
32 | | - |
33 | | - // Most of these are copied from here |
34 | | - // https://github.com/buddycloud/buddycloud-server/blob/master/src/local/operations.coffee#L14 |
35 | | - |
36 | | - public static String getPostChannelNodename(JID channelJID) { |
37 | | - return "/user/" + channelJID.toBareJID() + "/posts"; |
38 | | - } |
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 | | - } |
54 | | - |
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"); |
68 | | - |
69 | | - return conf; |
70 | | - } |
71 | | - |
72 | | - public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) { |
73 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
74 | | - |
75 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
76 | | - conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud channel!"); |
77 | | - conf.put(DESCRIPTION, "This channel belongs to " + channelJID.toBareJID() + ". To nobody else!"); |
78 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
79 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
80 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
81 | | - conf.put(OWNER, channelJID.toBareJID()); |
82 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
83 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
84 | | - conf.put(NOTIFY_CONFIG, "1"); |
85 | | - conf.put(CHANNEL_TYPE, "personal"); |
86 | | - |
87 | | - return conf; |
88 | | - } |
89 | | - |
90 | | - public static String getStatusChannelNodename(JID channelJID) { |
91 | | - return "/user/" + channelJID.toBareJID() + "/status"; |
92 | | - } |
93 | | - |
94 | | - public static HashMap<String, String> getDefaultStatusChannelConf(JID channelJID) { |
95 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
96 | | - |
97 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
98 | | - conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud status!"); |
99 | | - conf.put(DESCRIPTION, "This is " + channelJID.toBareJID() + "'s mood a.k.a status -channel. Depends how geek you are."); |
100 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
101 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
102 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
103 | | - conf.put(OWNER, channelJID.toBareJID()); |
104 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
105 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
106 | | - conf.put(NOTIFY_CONFIG, "1"); |
107 | | - |
108 | | - return conf; |
109 | | - } |
110 | | - |
111 | | - public static String getGeoPreviousChannelNodename(JID channelJID) { |
112 | | - return "/user/" + channelJID.toBareJID() + "/geo/previous"; |
113 | | - } |
114 | | - |
115 | | - public static HashMap<String, String> getDefaultGeoPreviousChannelConf(JID channelJID) { |
116 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
117 | | - |
118 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
119 | | - conf.put(TITLE, channelJID.toBareJID() + "'s previous location."); |
120 | | - conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " has been before."); |
121 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
122 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
123 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
124 | | - conf.put(OWNER, channelJID.toBareJID()); |
125 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
126 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
127 | | - conf.put(NOTIFY_CONFIG, "1"); |
128 | | - |
129 | | - return conf; |
130 | | - } |
131 | | - |
132 | | - public static String getGeoCurrentChannelNodename(JID channelJID) { |
133 | | - return "/user/" + channelJID.toBareJID() + "/geo/current"; |
134 | | - } |
135 | | - |
136 | | - public static HashMap<String, String> getDefaultGeoCurrentChannelConf(JID channelJID) { |
137 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
138 | | - |
139 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
140 | | - conf.put(TITLE, channelJID.toBareJID() + "'s current location."); |
141 | | - conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is now."); |
142 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
143 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
144 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
145 | | - conf.put(OWNER, channelJID.toBareJID()); |
146 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
147 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
148 | | - conf.put(NOTIFY_CONFIG, "1"); |
149 | | - |
150 | | - return conf; |
151 | | - } |
152 | | - |
153 | | - public static String getGeoNextChannelNodename(JID channelJID) { |
154 | | - return "/user/" + channelJID.toBareJID() + "/geo/next"; |
155 | | - } |
156 | | - |
157 | | - public static HashMap<String, String> getDefaultGeoNextChannelConf(JID channelJID) { |
158 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
159 | | - |
160 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
161 | | - conf.put(TITLE, channelJID.toBareJID() + "'s next location."); |
162 | | - conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is going to go."); |
163 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
164 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
165 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
166 | | - conf.put(OWNER, channelJID.toBareJID()); |
167 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
168 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
169 | | - conf.put(NOTIFY_CONFIG, "1"); |
170 | | - |
171 | | - return conf; |
172 | | - } |
173 | | - |
174 | | - public static String getSubscriptionsChannelNodename(JID channelJID) { |
175 | | - return "/user/" + channelJID.toBareJID() + "/subscriptions"; |
176 | | - } |
177 | | - |
178 | | - public static HashMap<String, String> getDefaultSubscriptionsChannelConf(JID channelJID) { |
179 | | - HashMap<String, String> conf = new HashMap<String, String>(); |
180 | | - |
181 | | - conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
182 | | - conf.put(TITLE, channelJID.toBareJID() + "'s susbcriptions."); |
183 | | - conf.put(DESCRIPTION, channelJID.toBareJID() + "'s subscriptions. "); |
184 | | - conf.put(PUBLISH_MODEL, PUBLISHERS); |
185 | | - conf.put(ACCESS_MODEL, AccessModels.open.toString()); |
186 | | - conf.put(CREATION_DATE, formatDate(new Date())); |
187 | | - conf.put(OWNER, channelJID.toBareJID()); |
188 | | - conf.put(DEFAULT_AFFILIATION, Affiliations.member.toString()); |
189 | | - conf.put(NUM_SUBSCRIBERS, "1"); |
190 | | - conf.put(NOTIFY_CONFIG, "1"); |
191 | | - |
192 | | - return conf; |
193 | | - } |
| 33 | + |
| 34 | + public static String getPostChannelNodename(JID channelJID) { |
| 35 | + return "/user/" + channelJID.toBareJID() + "/posts"; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Parses a ISO 8601 to a string |
| 40 | + * |
| 41 | + * @param iso8601Str |
| 42 | + * @return |
| 43 | + * @throws IllegalArgumentException if the provided string is not ISO 8601 |
| 44 | + */ |
| 45 | + public static Date parseDate(String iso8601Str) throws IllegalArgumentException { |
| 46 | + return ISO_8601_PARSER.parseDateTime(iso8601Str).toDate(); |
| 47 | + } |
| 48 | + |
| 49 | + public static String formatDate(Date date) { |
| 50 | + return ISO_8601_FORMATTER.print(date.getTime()); |
| 51 | + } |
| 52 | + |
| 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"); |
| 57 | + conf.put(OWNER, ownerJID.toBareJID()); |
| 58 | + return conf; |
| 59 | + } |
| 60 | + |
| 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!"); |
| 65 | + conf.put(CHANNEL_TYPE, "personal"); |
| 66 | + return conf; |
| 67 | + } |
| 68 | + |
| 69 | + public static String getStatusChannelNodename(JID channelJID) { |
| 70 | + return "/user/" + channelJID.toBareJID() + "/status"; |
| 71 | + } |
| 72 | + |
| 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."); |
| 77 | + return conf; |
| 78 | + } |
| 79 | + |
| 80 | + public static String getGeoPreviousChannelNodename(JID channelJID) { |
| 81 | + return "/user/" + channelJID.toBareJID() + "/geo/previous"; |
| 82 | + } |
| 83 | + |
| 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 | + return conf; |
| 89 | + } |
| 90 | + |
| 91 | + public static String getGeoCurrentChannelNodename(JID channelJID) { |
| 92 | + return "/user/" + channelJID.toBareJID() + "/geo/current"; |
| 93 | + } |
| 94 | + |
| 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 | + return conf; |
| 100 | + } |
| 101 | + |
| 102 | + public static String getGeoNextChannelNodename(JID channelJID) { |
| 103 | + return "/user/" + channelJID.toBareJID() + "/geo/next"; |
| 104 | + } |
| 105 | + |
| 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."); |
| 110 | + return conf; |
| 111 | + } |
| 112 | + |
| 113 | + public static String getSubscriptionsChannelNodename(JID channelJID) { |
| 114 | + return "/user/" + channelJID.toBareJID() + "/subscriptions"; |
| 115 | + } |
| 116 | + |
| 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. "); |
| 121 | + return conf; |
| 122 | + } |
| 123 | + |
| 124 | + private static HashMap<String, String> getDefaultConf(JID channelJID) { |
| 125 | + HashMap<String, String> conf = new HashMap<String, String>(); |
| 126 | + Configuration projectConf = Configuration.getInstance(); |
| 127 | + conf.put(TYPE, "http://www.w3.org/2005/Atom"); |
| 128 | + conf.put(PUBLISH_MODEL, PUBLISHERS); |
| 129 | + conf.put(CREATION_DATE, formatDate(new Date())); |
| 130 | + 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()); |
| 136 | + conf.put(NUM_SUBSCRIBERS, "1"); |
| 137 | + conf.put(NOTIFY_CONFIG, "1"); |
| 138 | + return conf; |
| 139 | + } |
194 | 140 | } |
0 commit comments