4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
P2Processor.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Martin Petr
4  * File: P2Processor.java
5  * Description: Class which process XML with messages in 4A protocol v 2.0
6  */
7 
8 /**
9  * @file P2Processor.java
10  *
11  * @brief Class which process XML with messages in 4A protocol v 2.0
12  */
13 
14 /**
15  * @package cz.vutbr.fit.knot.annotations.comet.protocolV2_0
16  *
17  * @brief Classes which process XML with messages in 4A protocol v 2.0
18  */
19 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0;
20 
21 import cz.vutbr.fit.knot.annotations.app.*;
26 import cz.vutbr.fit.knot.annotations.entity.*;
28 import java.security.MessageDigest;
29 import java.security.NoSuchAlgorithmException;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.logging.Level;
34 import java.util.logging.Logger;
35 import org.w3c.dom.Element;
36 import org.w3c.dom.Node;
37 import org.w3c.dom.NodeList;
38 
39 /**
40  * Class which parses and process XML with messages for protocol version 2
41  *
42  * @brief Class which parses and process XML with messages for protocol version 2
43  * @author Martin Petr (xpetrm05)
44  */
45 public class P2Processor {
47 
48  /**
49  * Constructor
50  */
51  public P2Processor() {
52  }
53 
54  /**
55  * Method parses and process XML with messages from client.
56  *
57  * @param mainElement element with messages from client
58  * @param requestInfo informations about client request
59  */
60  public void processXMLDocument(Element mainElement,RequestInfo requestInfo){
61  this.requestInfo = requestInfo;
62  EditorSession session = requestInfo.getSession();
63  P2AnnotTypeProcessor annotTypeProcessor = new P2AnnotTypeProcessor();
64  P2AnnotationProcessor annotationProcessor = new P2AnnotationProcessor();
65  P2SuggestionProcessor suggestionsProcessor = new P2SuggestionProcessor();
66 
67  // ********** Comet **********
68  NodeList cometMsg = mainElement.getElementsByTagName("comet");
69  Element cometEl = (Element) cometMsg.item(0);
70  if(cometEl != null && cometEl.getParentNode().isSameNode(mainElement)){
71  requestInfo.setSessionOnly(true);
72  requestInfo.setCanNotify(false); // nothing to notify
73  return;
74  }
75 
76  // ********** login **********
77  User user = null;
78  NodeList loginMsg = mainElement.getElementsByTagName("login");
79  Element loginEl = (Element) loginMsg.item(0);
80  if(loginEl != null && loginEl.getParentNode().isSameNode(mainElement)) {
81  // process message and returns user or null
82  user = processLogin(loginEl, requestInfo);
83  requestInfo.setLoggedIn(user);
84  session.setUser(user);
85  session.actualizeAllCachedSettings();
86 
87  if(user != null) {
88  // ifsuccessfully logged in, prepare logged message
89  AppBean.getSessionsCleaner().setSessionConfirm(session.getSessionId());
90  requestInfo.appendToReply(P2MessagesCreator.getXMLLoggedUser(user));
91  }
92 
93  if(user == null) {
94  // ifuser not logged in, disconnect message still can be processed
95  NodeList disconnMsg = mainElement.getElementsByTagName("disconnect");
96  Element disconnEl = (Element) disconnMsg.item(0);
97  if(disconnEl != null) {
98  // ifdisconnect message was sent
99  if(session.getSyncDocument() != null){
100  AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
101  }
102  AppBean.removeSession(session);
103  // delete session
104  requestInfo.setDisconnect(true);
105  }
106  return;
107  }
108 
109  // Subscribe to own annotations
110  requestInfo.getSession().addSource(new SubscribedSource("*", user.getURIV2(), null));
111 
112  // Subscribe annotations from groups where is user presented
113  Iterator<UserGroup> groupsIt = user.getGroupsAL().iterator();
114  while(groupsIt.hasNext()){
115  requestInfo.getSession().addSource(new SubscribedSource("*", null, groupsIt.next().getUri()));
116  }
117  }
118 
119  if(user == null) { // ifuser not set, get him from session
120  user = session.getUser();
121  }
122 
123  if(user == null) { // ifuser is not set
124  // disconnect message can be processed
125  NodeList disconnMsg = mainElement.getElementsByTagName("disconnect");
126  Element disconnEl = (Element) disconnMsg.item(0);
127  int lod = session.getProtocolLOD();
128  requestInfo.addWarning(lod, session.getLanguageNum(), Localisation.WARNING_5_NOT_LOGGED_IN);
130  String msg = "User is not logged in.";
131  Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
132  }
133  if(disconnEl != null) {
134  //ifsession have sync. document , it must be decrement in document usage list
135  if(session.getSyncDocument() != null){
136  AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
137  }
138 
139  AppBean.removeSession(session); // remove session from list of active sessions
140  requestInfo.setDisconnect(true);
141  // Session remains in requestInfo and in flier and after request
142  // is fully processed, it's discarded.
143  }
144 
145  // no other messages can be processed without logged in user
146  return;
147  } // ifuser is not set
148 
149  // ********** logout **********
150  NodeList logoutMsg = mainElement.getElementsByTagName("logout");
151  Element logoutEl = (Element) logoutMsg.item(0);
152  if(logoutEl != null) {
153  if(session.getSyncDocument() != null){
154  AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
155  }
156 
157  // logout user from session
158  session.setUser(null);
159  requestInfo.setLogout(true);
160  }
161 
162  // ********** users **********
163  NodeList usersQueryMsg = mainElement.getElementsByTagName("getUsers");
164  Element usersQueryEl = (Element) usersQueryMsg.item(0);
165  if(usersQueryEl != null) {
166  ArrayList<String> searchPattern = processUsersQuerry(usersQueryEl);
167 
168  // check ifthere any restriction includeOnly restriction
169  boolean restrictions[];
170  NodeList includeOnlyNodes = usersQueryEl.getElementsByTagName("includeOnly");
171  Element includeOnlyEl = (Element) includeOnlyNodes.item(0);
172  if(includeOnlyEl != null){
173  // user set some restrictions
174  restrictions = processIncludeOnly(includeOnlyEl);
175  }else{
176  // user want all informations
177  restrictions = new boolean[]{true,true,true,true,true,true};
178  }
179 
180  // set user query to requestInfo
181  requestInfo.setUsersQueryV2(searchPattern);
182  requestInfo.setUsersRestrictionsV2(restrictions);
183  }
184 
185  // ********** group - join **********
186  NodeList groupJoinMsgs = mainElement.getElementsByTagName("joinUserGroup");
187  Element joinEl = (Element) groupJoinMsgs.item(0);
188  if(joinEl != null){
189  processJoin(joinEl,requestInfo);
190  }
191 
192  // ********** group - leave **********
193  NodeList groupLeaveMsgs = mainElement.getElementsByTagName("leaveUserGroup");
194  Element leaveEl = (Element) groupLeaveMsgs.item(0);
195  if(leaveEl != null){
196  processLeave(leaveEl,requestInfo);
197  }
198 
199  // ********** group - query **********
200  NodeList groupsQueryMsgs = mainElement.getElementsByTagName("getUserGroups");
201  Element groupsQueryEl = (Element) groupsQueryMsgs.item(0);
202  if(groupsQueryEl != null){
203  ArrayList<String> searchPattern = processGroupsQuery(groupsQueryEl,requestInfo);
204 
205  if(searchPattern.get(P2Constants.GROUPS_Q_W_USERS).equals("true")){
206  boolean restrictions[];
207  NodeList includeOnlyNodes = groupsQueryEl.getElementsByTagName("includeOnly");
208  Element includeOnlyEl = (Element) includeOnlyNodes.item(0);
209  if(includeOnlyEl != null){
210  // user set some restrictions
211  restrictions = processIncludeOnly(includeOnlyEl);
212  }else{
213  // user want all informations
214  restrictions = new boolean[]{true,true,true,true,true,true};
215  }
216 
217  // set restrictions to requestInfo
218  requestInfo.setUsersGroupRestrictionsV2(restrictions);
219  }
220 
221  // set user query to requestInfo
222  requestInfo.setGroupsQueryV2(searchPattern);
223  }
224 
225  // ********** synchronization **********
226  NodeList documentSyncMsg = mainElement.getElementsByTagName("synchronize");
227  Element documentSyncEl = (Element) documentSyncMsg.item(0);
228  if(documentSyncEl != null) {
229  processSynchronize(documentSyncEl,requestInfo);
230  }
231 
232  // ********** resynchronization **********
233  NodeList documentResyncMsg = mainElement.getElementsByTagName("resynchronize");
234  Element documentResyncEl = (Element) documentResyncMsg.item(0);
235  if(documentResyncEl != null){
236  processResynchronize(documentResyncEl, requestInfo);
237  }
238 
239  // ********** subscriptions - add **********
240  NodeList subscriptAddMsg = mainElement.getElementsByTagName("createSubscription");
241  Element subscriptAddEl = (Element) subscriptAddMsg.item(0);
242  if(subscriptAddEl != null) {
243  // process add subscriptions package
244  procesAddSubscription(subscriptAddEl,requestInfo);
245  }
246 
247  // ********** subscriptions - delete **********
248  NodeList subscriptRemoveMsg = mainElement.getElementsByTagName("removeSubscription");
249  Element subscriptRemoveEl = (Element) subscriptRemoveMsg.item(0);
250  if(subscriptRemoveEl != null) {
251  // process delete subscriptions package
252  procesRemoveSubscription(subscriptRemoveEl,requestInfo);
253  }
254 
255  // ********** subscriptions - change **********
256  NodeList subscriptChangeMsg = mainElement.getElementsByTagName("modifySubscription");
257  Element subscriptChangeEl = (Element) subscriptChangeMsg.item(0);
258  if(subscriptChangeEl != null) {
259  // process change subscriptions package
260  procesChangeSubscription(subscriptChangeEl,requestInfo);
261  }
262 
263  // ********** subscriptions - subscribe **********
264  NodeList subscribeMsg = mainElement.getElementsByTagName("subscribe");
265  Element subscribeEl = (Element) subscribeMsg.item(0);
266  if(subscribeEl != null) {
267  // process subscriptions
268  processSubscribe(subscribeEl,requestInfo);
269  }
270 
271  // ********** subscriptions - unsubscribe **********
272  NodeList unsubscribeMsg = mainElement.getElementsByTagName("unsubscribe");
273  Element unsubscribeEl = (Element) unsubscribeMsg.item(0);
274  if(unsubscribeEl != null) {
275  // process subscriptions
276  processUnsubscribe(unsubscribeEl,requestInfo);
277  }
278 
279  // ********** subscriptions - query **********
280  NodeList subscrQueryMsg = mainElement.getElementsByTagName("getSubscriptions");
281  Element subscrQueryEl = (Element) subscrQueryMsg.item(0);
282  if(subscrQueryEl != null) {
283  // process subscriptions query
284  processSubscriptionsQuery(subscrQueryEl,requestInfo);
285  }
286 
287  // ********** attributes from ontology **********
288  NodeList queryAttrFromOntoMsg = mainElement.getElementsByTagName("getOntologyAttributes");
289  Element queryAttrFromOntoEl = (Element) queryAttrFromOntoMsg.item(0);
290  if (queryAttrFromOntoEl != null) {
291  String attrGr = queryAttrFromOntoEl.getAttribute("groupUri");
292  if (attrGr == null || attrGr.isEmpty()) {
293  attrGr = "*";
294  }
295  requestInfo.setQueryTypeAttOnto(attrGr);
296  }
297 
298  // ********** document modification*********
299  NodeList modificationMsg = mainElement.getElementsByTagName("modification");
300  Element modificationEl = (Element) modificationMsg.item(0);
301  if(modificationEl != null){
302  processDocumentModification(modificationEl, requestInfo);
303  }
304 
305  // ********** types - add **********
306  NodeList addTypesMsg = mainElement.getElementsByTagName("addTypes");
307  Element addTypesEl = (Element) addTypesMsg.item(0);
308  if(addTypesEl != null) {
309  annotTypeProcessor.procesTypesAdd(addTypesEl, requestInfo);
310  }
311 
312  // ********** types - modify **********
313  NodeList modifyTypesMsg = mainElement.getElementsByTagName("modifyTypes");
314  Element modifyTypesEl = (Element) modifyTypesMsg.item(0);
315  if(modifyTypesEl != null) {
316  annotTypeProcessor.procesTypesChange(modifyTypesEl, requestInfo);
317  }
318 
319  // ********** types - remove **********
320  NodeList removeTypesMsg = mainElement.getElementsByTagName("removeTypes");
321  Element removeTypesEl = (Element) removeTypesMsg.item(0);
322  if(removeTypesEl != null) {
323  annotTypeProcessor.procesTypesRemove(removeTypesEl,requestInfo);
324  }
325 
326  // ********** types - query **********
327  NodeList queryTypesMsg = mainElement.getElementsByTagName("getTypes");
328  Element queryTypesEl = (Element) queryTypesMsg.item(0);
329  if(queryTypesEl != null) {
330  annotTypeProcessor.procesTypeQuery(queryTypesEl,requestInfo);
331  }
332 
333  // ********** annotation - add **********
334  NodeList addAnnotationsMsg = mainElement.getElementsByTagName("createAnnotations");
335  Element addAnnotationsEl = (Element) addAnnotationsMsg.item(0);
336  if(addAnnotationsEl != null) {
337  // process annntoations to add
338  annotationProcessor.processAddAnnotations(addAnnotationsEl,requestInfo);
339  }
340 
341  // ********** annotation - change **********
342  NodeList changeAnnotationsMsg = mainElement.getElementsByTagName("modifyAnnotations");
343  Element changeAnnotationsEl = (Element) changeAnnotationsMsg.item(0);
344  if(changeAnnotationsEl != null) {
345  // process annntoations to change
346  annotationProcessor.processChangeAnnotations(changeAnnotationsEl,requestInfo);
347  }
348 
349  // ********** annotation - delete **********
350  NodeList removeAnnotationsMsg = mainElement.getElementsByTagName("removeAnnotations");
351  Element removeAnnotationsEl = (Element) removeAnnotationsMsg.item(0);
352  if(removeAnnotationsEl != null) {
353  // process annntoations to delete
354  annotationProcessor.processDeleteAnnotations(removeAnnotationsEl, requestInfo);
355  }
356 
357 
358  // ********** annotation - reload **********
359  NodeList reloadAnnotationMsg = mainElement.getElementsByTagName("reloadAnnotation");
360  Element reloadAnnotationEl = (Element) reloadAnnotationMsg.item(0);
361  if(reloadAnnotationEl != null){
362  processReloadAnnotation(reloadAnnotationEl, requestInfo);
363  }
364 
365 
366  // ********** entity - get types **********
367  NodeList getEntityTypesMsg = mainElement.getElementsByTagName("getEntityTypes");
368  Element getEntityTypesEl = (Element) getEntityTypesMsg.item(0);
369  if (getEntityTypesEl != null) { // if message was sent
370  // set to yes in RequestInfo
371  requestInfo.setGetEntityTypes(true);
372  }
373 
374  // ********** suggestions - query **********
375  NodeList suggQueryMsg = mainElement.getElementsByTagName("suggestAnnotations");
376  Element suggQueryEl = (Element) suggQueryMsg.item(0);
377  if (suggQueryEl != null) {
378  suggestionsProcessor.processSuggestionQuery(suggQueryEl, requestInfo);
379  }
380 
381  // ********** suggestions - confirm **********
382  NodeList suggConfirmMsg = mainElement.getElementsByTagName("confirmSuggestions");
383  Element suggConfirmEl = (Element) suggConfirmMsg.item(0);
384  if (suggConfirmEl != null) {
385  suggestionsProcessor.processSuggestionConfirm(suggConfirmEl, requestInfo);
386  }
387 
388  // ********** suggestions - refuse **********
389  NodeList suggRefuseMsg = mainElement.getElementsByTagName("refuseSuggestions");
390  Element suggRefuseEl = (Element) suggRefuseMsg.item(0);
391  if (suggRefuseEl != null) {
392  suggestionsProcessor.processSuggestionRefuse(suggRefuseEl, requestInfo);
393  }
394 
395  // ********** suggestions - getAlternativesFor **********
396  NodeList getAlternativesForMsg = mainElement.getElementsByTagName("getAlternativesFor");
397  Element getAlternativesForEl = (Element) getAlternativesForMsg.item(0);
398  if (getAlternativesForEl != null) {
399  suggestionsProcessor.processGetAlternatives(getAlternativesForEl, requestInfo);
400  }
401 
402  // ********** entity - query **********
403  NodeList entityQueryMsg = mainElement.getElementsByTagName("getEntities");
404  Element entityQueryEl = (Element) entityQueryMsg.item(0);
405  if (entityQueryEl != null) { // if message was sent
406  // set request to request info
407  processEntityQuery(entityQueryEl,requestInfo);
408  }
409 
410  // ********** settings **********
411  NodeList settingsMsg = mainElement.getElementsByTagName("updateParameters");
412  Element settingsEl = (Element) settingsMsg.item(0);
413  if (settingsEl != null) { // if message was sent
414  processSettings(settingsEl, requestInfo);
415  }
416 
417  // ********** disconnect **********
418  NodeList disconnMsg = mainElement.getElementsByTagName("disconnect");
419  Element disconnEl = (Element) disconnMsg.item(0);
420  if(disconnEl != null) {
421  if(session.getSyncDocument() != null){
422  AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
423  }
424  AppBean.removeSession(session); // remove session from list of active sessions
425  requestInfo.setDisconnect(true);
426  // Session remains in requestInfo and in flier and after request
427  // is fully processed, it's discarded.
428  }
429  } // processXMLDocument()
430 
431  /**
432  * Method handle user login message.
433  *
434  * @param loginEl element with user credentials
435  * @param requestInfo Informations about client request
436  * @return logged user
437  */
438  private User processLogin(Element loginEl, RequestInfo requestInfo){
439  User user = null;
440  PersistM persistMan = AppBean.getPersistenceManager();
441 
442  // parse user login attribute
443  String userAtt = loginEl.getAttribute("login");
444  if(userAtt == null){
445  // null is a same as not set
446  userAtt = "";
447  }
448 
449  // parse user password attribute
450  String passAtt = loginEl.getAttribute("password");
451  if(passAtt == null){
452  // null is a same as not set
453  passAtt = "";
454  }
455 
456  // parse user token attribute generated by system
457  String tokenAtt = loginEl.getAttribute("token");
458  if(tokenAtt == null){
459  // null is a same as not set
460  tokenAtt = "";
461  }
462 
463  // parse system URI attribute (system that generated token)
464  String systemAtt = loginEl.getAttribute("system");
465  if(systemAtt == null){
466  // null is a same as not set
467  systemAtt = "";
468  }
469 
470  // check required parameters for external authentication
471  if(!userAtt.isEmpty() && (!tokenAtt.isEmpty() && !systemAtt.isEmpty())) {
472  // external authentication
473  String storedToken = AppBean.getExtAuthData(systemAtt, userAtt);
474 
475  // check token
476  if(storedToken == null) {
477  // token was not found
478  int langNum = requestInfo.getSession().getLanguageNum();
479  int lod = requestInfo.getSession().getProtocolLOD();
480  requestInfo.addError(lod, langNum, Localisation.ERROR_1_BAD_CREDENTIALS);
482  String msg = "Unknown authentication token received.";
483  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
484  }
485  return null;
486  }
487 
488  // check iftoken is valid
489  if(!tokenAtt.equals(storedToken)) {
490  // bad token
491  int langNum = requestInfo.getSession().getLanguageNum();
492  int lod = requestInfo.getSession().getProtocolLOD();
493  requestInfo.addError(lod, langNum, Localisation.ERROR_1_BAD_CREDENTIALS);
495  String msg = "Bad authentication token received.";
496  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
497  }
498  return null;
499  }
500 
501  // get user by token
502  Object[] params = new Object[4];
503  params[0] = "login";
504  params[1] = userAtt;
505  params[2] = "comeFrom";
506  params[3] = systemAtt;
507  List uList = persistMan.queryDB("User.findByLoginAndSystem", params);
508  if(uList != null && !uList.isEmpty()) { // ifuser was found
509  user = (User) uList.get(0);
510  }
511  if(user != null) {
512  return user;
513  }
514  } // external authentication
515 
516  if(userAtt.isEmpty() || passAtt.isEmpty()) {
517  // iflogin (email) or password is not set
518  int langNum = requestInfo.getSession().getLanguageNum();
519  int lod = requestInfo.getSession().getProtocolLOD();
520  requestInfo.addError(lod, langNum, Localisation.ERROR_1_BAD_CREDENTIALS);
522  String msg = "Login or password is missing.";
523  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
524  }
525  return null;
526  } else { // ifcredentials are set
527 
528  // compute MD5 of password
529  MessageDigest md5;
530  String hash = "";
531  try {
532  md5 = MessageDigest.getInstance("MD5");
533  md5.update(passAtt.getBytes());
534  hash = MessageProcessor.getHexString(md5.digest());
535  } catch (NoSuchAlgorithmException ex) {
536  int langNum = requestInfo.getSession().getLanguageNum();
537  int lod = requestInfo.getSession().getProtocolLOD();
538  requestInfo.addError(lod, langNum, Localisation.ERROR_100_UNKNOWN_ERROR, "", "Internal server error.");
540  String msg = "NoSuchAlgorithmException for MD5 algorithm.";
541  Logger.getLogger(P2Processor.class.getName()).log(Level.SEVERE, msg, ex);
542  }
543  }
544 
545  // query database for user (find by login and password)
546  Object[] params = new Object[4];
547  params[0] = "login";
548  params[1] = userAtt;
549  params[2] = "password";
550  params[3] = hash; // use MD5 of sent password
551  List uList = persistMan.queryDB("User.findByCredentials", params);
552  if(uList != null && !uList.isEmpty()) { // ifuser was found
553  user = (User) uList.get(0);
554  }
555 
556  if(user == null) { // user wasn't found, possible secure login
557  // query database for user (find by login and password)
558  params[3] = passAtt;
559  uList = persistMan.queryDB("User.findByCredentials", params);
560  if(uList != null && !uList.isEmpty()) { // ifuser was found
561  user = (User) uList.get(0);
562  }
563  }
564 
565  if(user == null) { // user wasn't found, possible login with e-mail
566  params[0] = "email";
567  params[1] = userAtt;
568  params[3] = hash; // use MD5 of sent password
569  uList = persistMan.queryDB("User.findByEmailAndPassword", params);
570  if(uList != null && !uList.isEmpty()) { // ifuser was found
571  user = (User) uList.get(0);
572  }
573  }
574 
575  if(user == null) { // user wasn't found, possible secure login with e-mail
576  params[3] = passAtt;
577  uList = persistMan.queryDB("User.findByEmailAndPassword", params);
578  if(uList != null && !uList.isEmpty()) { // ifuser was found
579  user = (User) uList.get(0);
580  }
581  }
582 
583  if(user == null) { // user wasn't found - bad credentials
584  int langNum = requestInfo.getSession().getLanguageNum();
585  int lod = requestInfo.getSession().getProtocolLOD();
586  requestInfo.addError(lod, langNum, Localisation.ERROR_1_BAD_CREDENTIALS);
588  String msg = "Authentication by login and password failed (bad login or password).";
589  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
590  }
591  }
592  } // ifcredentials are set
593  return user;
594  } // processLogin()
595 
596  /**
597  * Method processes the element with a request for the users.
598  *
599  * @param userQueryEl element with request
600  * @return array of query parameters
601  */
602  private ArrayList<String> processUsersQuerry(Element userQueryEl){
603  ArrayList<String> result = new ArrayList<String>(P2Constants.USERS_Q_ATTR_COUNT);
604 
605  // search for user URI
606  String idAttr = userQueryEl.getAttribute("uri");
607  if(idAttr == null){
608  // null is a same as not set
609  idAttr = "";
610  }
611  String userPrefix = AppBean.getBaseUserUriV2();
612  idAttr = idAttr.replace(userPrefix, "");
613  result.add(P2Constants.USERS_Q_URI_ATTR, idAttr);
614 
615  // search for user e-mail
616  String emailAttr = userQueryEl.getAttribute("email");
617  if(emailAttr == null){
618  // null is a same as not set
619  emailAttr = "";
620  }
621  result.add(P2Constants.USERS_Q_EMAIL_ATTR, emailAttr);
622 
623  // search for user name
624  String nameAttr = userQueryEl.getAttribute("name");
625  if(nameAttr == null){
626  // null is a same as not set
627  nameAttr = "";
628  }
629  result.add(P2Constants.USERS_Q_NAME_ATTR, nameAttr);
630 
631  // search for user group uri
632  String groupUriAttr = userQueryEl.getAttribute("groupUri");
633  if(groupUriAttr == null){
634  // null is a same as not set
635  groupUriAttr = "";
636  }
637  String groupPrefix = AppBean.getBaseGroupUri();
638  groupUriAttr = groupUriAttr.replace(groupPrefix, "");
639  result.add(P2Constants.USERS_Q_GROUP_ATTR, groupUriAttr);
640 
641  return result;
642  }
643 
644  /**
645  * Method analyzes the element with restrictions on printing of pramethers of
646  * user and make array of booleans with results.
647  *
648  * @param includeOnlyEl element with restrictions
649  * @return array of booleans with results
650  */
651  private boolean[] processIncludeOnly(Element includeOnlyEl){
652  boolean result[] = new boolean[P2Constants.USER_ATTR_COUNT];
653  result[P2Constants.USER_URI_ATTR] = true;
654 
655  // find login element
656  NodeList restrictionNodes = includeOnlyEl.getElementsByTagName("login");
657  Element includeLoginEl = (Element) restrictionNodes.item(0);
658  if(includeLoginEl != null){
659  result[P2Constants.USER_LOGIN_ATTR] = true;
660  }
661 
662  // find name element
663  restrictionNodes = includeOnlyEl.getElementsByTagName("name");
664  Element includeNameEl = (Element) restrictionNodes.item(0);
665  if(includeNameEl != null){
666  result[P2Constants.USER_NAME_ATTR] = true;
667  }
668 
669  // find email element
670  restrictionNodes = includeOnlyEl.getElementsByTagName("email");
671  Element includeEmailEl = (Element) restrictionNodes.item(0);
672  if(includeEmailEl != null){
673  result[P2Constants.USER_EMAIL_ATTR] = true;
674  }
675 
676  // find image element
677  restrictionNodes = includeOnlyEl.getElementsByTagName("image");
678  Element includeImageEl = (Element) restrictionNodes.item(0);
679  if(includeImageEl != null){
680  result[P2Constants.USER_IMAGE_ATTR] = true;
681  }
682 
683  // find groups element
684  restrictionNodes = includeOnlyEl.getElementsByTagName("groups");
685  Element includeGroupsEl = (Element) restrictionNodes.item(0);
686  if(includeGroupsEl != null){
687  result[P2Constants.USER_GROUPS_ATTR] = true;
688  }
689 
690  return result;
691  }
692 
693  /**
694  * Method analyzes the element with joining user group element and adds user
695  * to group.
696  *
697  * @param joinEl element with informations about joining group
698  * @param requestInfo Informations about client request
699  */
700  private void processJoin(Element joinEl,RequestInfo requestInfo){
701  String groupUriAttr = joinEl.getAttribute("uri");
702  Integer groupId = getGroupIdFromUri(groupUriAttr);
703 
704  if(groupId == null){
705  int langNum = requestInfo.getSession().getLanguageNum();
706  int lod = requestInfo.getSession().getProtocolLOD();
707  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
709  String msg = "Join to group without group id.";
710  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
711  }
712  return;
713  }
714 
715  // add user to group
716  joinToGroup(groupId,requestInfo);
717  }
718 
719  /**
720  * Method analyzes the element with leaving user group element and removes user
721  * from group.
722  *
723  * @param leaveEl element with informations about leaving group
724  * @param requestInfo Informations about client reque
725  */
726  private void processLeave(Element leaveEl,RequestInfo requestInfo){
727  String groupUriAttr = leaveEl.getAttribute("uri");
728  Integer groupId = getGroupIdFromUri(groupUriAttr);
729 
730  if(groupId == null){
731  int langNum = requestInfo.getSession().getLanguageNum();
732  int lod = requestInfo.getSession().getProtocolLOD();
733  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
735  String msg = "Leave to group without group id.";
736  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
737  }
738  return;
739  }
740 
741  // remove user from group
742  leaveGroup(groupId,requestInfo);
743  }
744 
745  /**
746  * Method process the element with query and creates a list of query parameters.
747  *
748  * @param groupsQueryEl element with query for user group
749  * @param requestInfo Informations about client request
750  * @return list with parameters of query
751  */
752  private ArrayList<String> processGroupsQuery(Element groupsQueryEl, RequestInfo requestInfo){
753  ArrayList<String> attrs = new ArrayList<String>(P2Constants.GROUPS_Q_ATTR_COUNT);
754  String nameAttr = groupsQueryEl.getAttribute("name");
755  if(nameAttr == null){
756  // null is a same as not set
757  nameAttr = "";
758  }
759  attrs.add(P2Constants.GROUPS_Q_NAME, nameAttr);
760 
761  String uriAttr = groupsQueryEl.getAttribute("uri");
762  if(uriAttr == null){
763  // null is a same as not set
764  uriAttr = "";
765  }
766  String groupPrefix = AppBean.getBaseGroupUri();
767  uriAttr = uriAttr.replace(groupPrefix, "");
768  attrs.add(P2Constants.GROUPS_Q_ID, uriAttr);
769 
770  String withUsersAttr = groupsQueryEl.getAttribute("withUsers");
771  if(withUsersAttr == null && withUsersAttr.isEmpty()){
772  // default is false
773  withUsersAttr = "false";
774  }
775  attrs.add(P2Constants.GROUPS_Q_W_USERS, withUsersAttr);
776 
777  return attrs;
778  }
779 
780  /**
781  * Method process the element with subscriptions for add.
782  *
783  * @param addSubscriptionEl element with subscriptions for add
784  * @param requestInfo Informations about client request
785  */
786  private void procesAddSubscription(Element addSubscriptionEl, RequestInfo requestInfo){
787  Subscription subsPackage = new Subscription();
788  String tmpId = addSubscriptionEl.getAttribute("tmpId");
789  Integer tmpIdValue = null;
790  if(tmpId == null || tmpId.isEmpty()){
791  // error - tmpId of subscription not found
792  int langNum = requestInfo.getSession().getLanguageNum();
793  int lod = requestInfo.getSession().getProtocolLOD();
794  String info = "<subscription tmpId=\"\" invalidProperty=\"tmpId\"/>";
795  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
797  String msg = "Subscription's temporary id was not found.";
798  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
799  }
800  return;
801  }
802 
803  try{
804  tmpIdValue = Integer.decode(tmpId);
805  } catch(NumberFormatException ex){
806  // error - bad subscription tmpId
807  int langNum = requestInfo.getSession().getLanguageNum();
808  int lod = requestInfo.getSession().getProtocolLOD();
809  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
811  String msg = "Trying to decode wrong subscription's temporary id: " + tmpId;
812  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
813  }
814  return;
815  }
816 
817  String name = addSubscriptionEl.getAttribute("name");
818  if(name == null || name.isEmpty()){
819  // error - name of subscription not found
820  int langNum = requestInfo.getSession().getLanguageNum();
821  int lod = requestInfo.getSession().getProtocolLOD();
822  String info = "<subscription tmpId=\"" + tmpId + "\" invalidProperty=\"name\"/>";
823  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
825  String msg = "Subscription's name was not found.";
826  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
827  }
828  return;
829  }
830 
831  // check name and user dupliciy
832  PersistM persistMan = AppBean.getPersistenceManager();
833  Subscription currentPackage = null;
834 
835  Object[] params = new Object[4];
836  params[0] = "name";
837  params[1] = name;
838  params[2] = "userId";
839  params[3] = requestInfo.getSession().getUser().getId();
840  @SuppressWarnings("unchecked")
841  List<Subscription> pakckageList = persistMan.queryDB("Subscription.findByIdAndUserId", params);
842  if(pakckageList != null && !pakckageList.isEmpty()) { // subscription was found
843  // error - subscription already exist
844  int langNum = requestInfo.getSession().getLanguageNum();
845  int lod = requestInfo.getSession().getProtocolLOD();
846  String info = "<subscription tmpId=\"" + tmpId + "\"/>";
847  requestInfo.addError(lod, langNum, Localisation.ERROR_106_DUPLICIT_SUBSCRIPTION, info);
849  String msg = "Subscription with this name already exists.";
850  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
851  }
852  return;
853  }
854 
855 
856  subsPackage.setName(name);
857  subsPackage.setUser(requestInfo.getSession().getUser());
858  subsPackage.setTmpId(tmpIdValue);
859 
860  if(subsPackage.getUser().getGroups() != null && !subsPackage.getUser().getGroups().isEmpty()){
861  subsPackage.setGroup(subsPackage.getUser().getGroups().get(0));
862  }else{
863  int langNum = requestInfo.getSession().getLanguageNum();
864  int lod = requestInfo.getSession().getProtocolLOD();
865  requestInfo.addError(lod, langNum, Localisation.ERROR_97_NOT_IN_GROUP);
867  String msg = "User does not have a group.";
868  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
869  }
870  return;
871  }
872 
873  // find sources elements
874  NodeList sourceNodes = addSubscriptionEl.getElementsByTagName("source");
875  if (sourceNodes != null && sourceNodes.getLength() > 0) {
876  for (int index = 0; index < sourceNodes.getLength(); index++) {
877  Element sourceEl = (Element) sourceNodes.item(index);
878  if (sourceEl != null) {
879  Source actualSubscription = processSource(sourceEl, requestInfo, subsPackage);
880  if (actualSubscription != null) {
881  subsPackage.addSubscription(actualSubscription);
882  } else {
883  int langNum = requestInfo.getSession().getLanguageNum();
884  int lod = requestInfo.getSession().getProtocolLOD();
885  String info = "<subscription tmpId=\"" + tmpId + "\" invalidProperty=\"source\"/>";
886  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
887  }
888  }
889  }
890  }
891 
892  requestInfo.addNewSubscriptions(subsPackage);
893  } // procesAddSubscription()
894 
895  /**
896  * Method process the element with subscriptions for change.
897  *
898  * @param changeSubscriptionEl element with subscriptions for change
899  * @param requestInfo Informations about client request
900  */
901  private void procesChangeSubscription(Element changeSubscriptionEl, RequestInfo requestInfo){
902  Subscription subsPackage = new Subscription();
903  String uri = changeSubscriptionEl.getAttribute("uri");
904  Integer id = null;
905  if(uri == null || uri.isEmpty()){
906  // error - uri of subscription not found
907  int langNum = requestInfo.getSession().getLanguageNum();
908  int lod = requestInfo.getSession().getProtocolLOD();
909  String info = "<subscription uri=\"\" invalidProperty=\"uri\"/>";
910  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
912  String msg = "Subscription's uri was not found.";
913  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
914  }
915  return;
916  }
917 
918  try{
919  id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(), ""));
920  } catch(NumberFormatException ex){
921  // error - bad subscription ID
922  int langNum = requestInfo.getSession().getLanguageNum();
923  int lod = requestInfo.getSession().getProtocolLOD();
924  String info = "<subscription uri=\"" + uri + "\" invalidProperty=\"uri\"/>";
925  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
927  String msg = "Trying to decode wrong subscription's id.";
928  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
929  }
930  return;
931  }
932 
933  // get subscription from DB
934  PersistM persistMan = AppBean.getPersistenceManager();
935  Subscription currentPackage = null;
936 
937  Object[] params = new Object[2];
938  params[0] = "id";
939  params[1] = id;
940  @SuppressWarnings("unchecked")
941  List<Subscription> pakckageList = persistMan.queryDB("Subscription.findById", params);
942  if(pakckageList != null && !pakckageList.isEmpty()) { // ifuser was found
943  currentPackage = pakckageList.get(0);
944  }else{
945  // error - cant find subscription
946  int langNum = requestInfo.getSession().getLanguageNum();
947  int lod = requestInfo.getSession().getProtocolLOD();
948  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
950  String msg = "Subscription with this id doesn't exists: " + id;
951  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
952  }
953  return;
954  }
955 
956  String name = changeSubscriptionEl.getAttribute("name");
957  if(name == null || name.isEmpty()){
958  // error - name of subscription not found
959  int langNum = requestInfo.getSession().getLanguageNum();
960  int lod = requestInfo.getSession().getProtocolLOD();
961  String info = "<subscription uri=\"" + uri + "\" invalidProperty=\"name\"/>";
962  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
964  String msg = "Subscription name was not found.";
965  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
966  }
967  return;
968  }
969 
970  subsPackage.setName(name);
971  subsPackage.setUser(requestInfo.getSession().getUser());
972  subsPackage.setId(id);
973  subsPackage.setGroup(currentPackage.getGroup());
974 
975  // find sources elements
976  NodeList sourceNodes = changeSubscriptionEl.getElementsByTagName("source");
977  if(sourceNodes != null && sourceNodes.getLength() > 0){
978  for (int index = 0; index < sourceNodes.getLength(); index++) {
979  Element sourceEl = (Element) sourceNodes.item(index);
980  if (sourceEl != null) {
981  Source actualSubscription = processSource(sourceEl, requestInfo, subsPackage);
982  if (actualSubscription != null) {
983  subsPackage.addSubscription(actualSubscription);
984  } else {
985  int langNum = requestInfo.getSession().getLanguageNum();
986  int lod = requestInfo.getSession().getProtocolLOD();
987  String info = "<subscription uri=\"" + uri + "\" invalidProperty=\"source\"/>";
988  requestInfo.addError(lod, langNum, Localisation.ERROR_65_SUBSCRIPTION_MALFORMED, info);
989  }
990  }
991  }
992  }
993 
994  requestInfo.addUpdatedSubscriptions(subsPackage);
995  } // procesChangeSubscription()
996 
997  /**
998  * Method process the element with subscriptions for delete.
999  *
1000  * @param removeSubscriptionEl element with subscriptions for delete
1001  * @param requestInfo Informations about client request
1002  */
1003  private void procesRemoveSubscription(Element removeSubscriptionEl, RequestInfo requestInfo){
1004  String uri = removeSubscriptionEl.getAttribute("uri");
1005  Integer id = null;
1006  if(uri == null || uri.isEmpty()){
1007  // error - uri of subscription not found
1008  int langNum = requestInfo.getSession().getLanguageNum();
1009  int lod = requestInfo.getSession().getProtocolLOD();
1010  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1012  String msg = "Subscription's uri was not found.";
1013  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1014  }
1015  return;
1016  }
1017 
1018  try{
1019  id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(), ""));
1020  } catch(NumberFormatException ex){
1021  // error - bad subscription id
1022  int langNum = requestInfo.getSession().getLanguageNum();
1023  int lod = requestInfo.getSession().getProtocolLOD();
1024  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1026  String msg = "Trying to decode wrong subscription's id.";
1027  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1028  }
1029  return;
1030  }
1031 
1032  // get subscription from DB
1033  PersistM persistMan = AppBean.getPersistenceManager();
1034  Subscription currentPackage = null;
1035 
1036  Object[] params = new Object[2];
1037  params[0] = "id";
1038  params[1] = id;
1039  @SuppressWarnings("unchecked")
1040  List<Subscription> pakckageList = persistMan.queryDB("Subscription.findById", params);
1041  if(pakckageList != null && !pakckageList.isEmpty()) { // ifuser was found
1042  currentPackage = pakckageList.get(0);
1043  }else{
1044  // error - can't find subscription
1045  int langNum = requestInfo.getSession().getLanguageNum();
1046  int lod = requestInfo.getSession().getProtocolLOD();
1047  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1049  String msg = "Subscription with this id doesn't exists.";
1050  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1051  }
1052  return;
1053  }
1054 
1055  requestInfo.addDeletedSubscription(currentPackage);
1056  } // procesRemoveSubscription()
1057 
1058  /**
1059  * Method process the element with subscription to subscribe.
1060  *
1061  * @param subscribeEl element with subscription to subscribe
1062  * @param requestInfo Informations about client request
1063  */
1064  private void processSubscribe(Element subscribeEl, RequestInfo requestInfo){
1065  Subscription subscriptionToSubs = null;
1066  String uri = subscribeEl.getAttribute("subscriptionUri");
1067  Integer id = null;
1068  if(uri == null || uri.isEmpty()){
1069  // error - uri of subscription not found
1070  int langNum = requestInfo.getSession().getLanguageNum();
1071  int lod = requestInfo.getSession().getProtocolLOD();
1072  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1074  String msg = "Uri of subscription not found: " + uri;
1075  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1076  }
1077  return;
1078  }
1079 
1080  try{
1081  id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(), ""));
1082  } catch(NumberFormatException ex){
1083  // error - bad subscription id
1084  int langNum = requestInfo.getSession().getLanguageNum();
1085  int lod = requestInfo.getSession().getProtocolLOD();
1086  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1088  String msg = "Can't decode id of subscription: " + id;
1089  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1090  }
1091  return;
1092  }
1093 
1094  // get subscription from DB
1095  PersistM persistMan = AppBean.getPersistenceManager();
1096 
1097  Object[] params = new Object[2];
1098  params[0] = "id";
1099  params[1] = id;
1100  @SuppressWarnings("unchecked")
1101  List<Subscription> pakckageList = persistMan.queryDB("Subscription.findById", params);
1102  if(pakckageList != null && !pakckageList.isEmpty()) { // ifuser was found
1103  subscriptionToSubs = pakckageList.get(0);
1104  }else{
1105  // error - can't find subscription
1106  int langNum = requestInfo.getSession().getLanguageNum();
1107  int lod = requestInfo.getSession().getProtocolLOD();
1108  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1110  String msg = "";
1111  if(id != null){
1112  msg = "Can't find subscription with id:" + id.toString();
1113  }
1114  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1115  }
1116  return;
1117  }
1118 
1119  requestInfo.addToSubscribe(subscriptionToSubs);
1120  }
1121 
1122  /**
1123  * Method process the element with subscription to unsubscribe.
1124  *
1125  * @param unsubscribeEl element with subscription to unsubscribe
1126  * @param requestInfo Informations about client request
1127  */
1128  private void processUnsubscribe(Element unsubscribeEl, RequestInfo requestInfo){
1129  Subscription subscriptionToUnsubs = null;
1130  String uri = unsubscribeEl.getAttribute("subscriptionUri");
1131  Integer id = null;
1132  if (uri == null || uri.isEmpty()) {
1133  // error - uri of subscription not found
1134  int langNum = requestInfo.getSession().getLanguageNum();
1135  int lod = requestInfo.getSession().getProtocolLOD();
1136  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1138  String msg = "Uri of subscription not found.";
1139  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1140  }
1141  return;
1142  }
1143 
1144  try {
1145  id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(), ""));
1146  } catch(NumberFormatException ex){
1147  // error - bad subscription id
1148  int langNum = requestInfo.getSession().getLanguageNum();
1149  int lod = requestInfo.getSession().getProtocolLOD();
1150  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1152  String msg = "Can't decode id of subscription: " + id + " from uri " + uri;
1153  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1154  }
1155  return;
1156  }
1157 
1158  // get subscription from DB
1159  PersistM persistMan = AppBean.getPersistenceManager();
1160 
1161  Object[] params = new Object[2];
1162  params[0] = "id";
1163  params[1] = id;
1164  @SuppressWarnings("unchecked")
1165  List<Subscription> pakckageList = persistMan.queryDB("Subscription.findById", params);
1166  if(pakckageList != null && !pakckageList.isEmpty()) { // ifuser was found
1167  subscriptionToUnsubs = pakckageList.get(0);
1168  }else{
1169  //error - can't find subscription
1170  int langNum = requestInfo.getSession().getLanguageNum();
1171  int lod = requestInfo.getSession().getProtocolLOD();
1172  requestInfo.addError(lod, langNum, Localisation.ERROR_64_UNKNOWN_SUB_URI);
1173 
1175  String msg = "Unable to find subscription with id = " + id;
1176  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1177  }
1178  return;
1179  }
1180 
1181  // insert to list
1182  requestInfo.addToUnsubscribe(subscriptionToUnsubs);
1183  }
1184 
1185  /**
1186  * Method process the element with request for list of subscriptions.
1187  *
1188  * @param subscriptionsQueryEl element with request for list of subscriptions
1189  * @param requestInfo Informations about client request
1190  */
1191  private void processSubscriptionsQuery(Element subscriptionsQueryEl,RequestInfo requestInfo){
1192  ArrayList<String> query = new ArrayList<String>(P2Constants.SUBS_QUERY_COUNT);
1193 
1194  String subsUri = subscriptionsQueryEl.getAttribute("subscriptionUri");
1195  if(subsUri == null){
1196  subsUri = "";
1197  }
1198  query.add(P2Constants.SUBS_QUERY_URI, subsUri);
1199 
1200  String authorUri = subscriptionsQueryEl.getAttribute("authorUri");
1201  if(authorUri == null){
1202  authorUri = "";
1203  }
1204  query.add(P2Constants.SUBS_QUERY_AUTHOR, authorUri);
1205 
1206  String groupUri = subscriptionsQueryEl.getAttribute("groupUri");
1207  if(groupUri == null){
1208  groupUri = "";
1209  }
1210  query.add(P2Constants.SUBS_QUERY_GROUP, groupUri);
1211  requestInfo.setSubscriptionQuery(query);
1212  }
1213 
1214  /**
1215  * Method process text modification message
1216  * Informations are stored to requestInfo.
1217  *
1218  * @param modificationEl Element to process
1219  * @param requestInfo Informations about client request
1220  */
1221  private void processDocumentModification(Element modificationEl, RequestInfo requestInfo){
1222 
1223  String lastModNumberStr = modificationEl.getAttribute("lastApplied");
1224 
1225  /* Parsing number */
1226  int lastModNumber;
1227  if (lastModNumberStr != null && !lastModNumberStr.isEmpty()) {
1228  try {
1229  lastModNumber = Integer.parseInt(lastModNumberStr);
1230  } catch (NumberFormatException nfe) {
1231  int langNum = requestInfo.getSession().getLanguageNum();
1232  int lod = requestInfo.getSession().getProtocolLOD();
1233  String info = "<modification id=\"" + lastModNumberStr + "\"/>";
1234  requestInfo.addError(lod, langNum, Localisation.ERROR_50_BAD_MODIFICATION, info);
1235 
1237  String msg = "Bad number of last applied modification.";
1238  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1239  }
1240  return;
1241  }
1242  } else {
1243  int langNum = requestInfo.getSession().getLanguageNum();
1244  int lod = requestInfo.getSession().getProtocolLOD();
1245  String info = "<modification id=\"" + lastModNumberStr + "\"/>";
1246  requestInfo.addError(lod, langNum, Localisation.ERROR_50_BAD_MODIFICATION, info);
1247 
1249  String msg = "Bad number of last applied modification.";
1250  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1251  }
1252  return;
1253  }
1254 
1255  // Add last modification number to requestInfo
1256  requestInfo.setLastModificationNumber(lastModNumber);
1257 
1258  //Get all modifications from message
1259  NodeList childNodes = modificationEl.getChildNodes();
1260  int tmpNum = childNodes.getLength();
1261 
1262  for (int i = 0; i < tmpNum; i++) { // for each modification
1263  Node node = childNodes.item(i);
1264 
1265  if (node.getNodeType() == Node.ELEMENT_NODE) {
1266  Element e = (Element) node;
1267  String tagName = e.getTagName();
1268 
1269  if (tagName != null && !tagName.isEmpty()) {
1270 
1271  if (tagName.equals("replace")) {
1272  processDocumentReplace(e, requestInfo);
1273  } else if (tagName.equals("insertBefore")) {
1274  processDocumentInsertBefore(e, requestInfo);
1275  } else if (tagName.equals("insertAfter")) {
1276  processDocumentInsertAfter(e, requestInfo);
1277  }
1278  }
1279  }
1280  } // for each modification
1281  } // processDocumentModification()
1282 
1283  /**
1284  * Method process the message about text modification - replace
1285  * Informations are stored to requestInfo.
1286  *
1287  * @param replaceEl Element to process
1288  * @param requestInfo Informations about client request
1289  */
1290  private void processDocumentReplace(Element replaceEl, RequestInfo requestInfo){
1291 
1292  String path = replaceEl.getAttribute("path");
1293  String offsetStr = replaceEl.getAttribute("offset");
1294  String lengthStr = replaceEl.getAttribute("length");
1295 
1296 
1297  /* parsing offset */
1298  Integer offset = null;
1299  if(offsetStr != null && !offsetStr.isEmpty()){
1300  try{
1301  offset = Integer.parseInt(offsetStr);
1302  }
1303  catch (NumberFormatException nfe) {
1304  int langNum = requestInfo.getSession().getLanguageNum();
1305  int lod = requestInfo.getSession().getProtocolLOD();
1306  String info = "<modification id=\"" + requestInfo.getLastModificationNumber() + "\"/>";
1307  requestInfo.addError(lod, langNum, Localisation.ERROR_50_BAD_MODIFICATION, info);
1309  String msg = "Bad offset in text modification: " + offsetStr;
1310  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1311  }
1312  return;
1313  }
1314  }
1315 
1316  /* parsing length */
1317  Integer length = null;
1318  if(lengthStr != null && !lengthStr.isEmpty()){
1319  try {
1320  length = Integer.parseInt(lengthStr);
1321  }
1322  catch (NumberFormatException nfe) {
1323  int langNum = requestInfo.getSession().getLanguageNum();
1324  int lod = requestInfo.getSession().getProtocolLOD();
1325  String info = "<modification id=\"" + requestInfo.getLastModificationNumber() + "\"/>";
1326  requestInfo.addError(lod, langNum, Localisation.ERROR_50_BAD_MODIFICATION, info);
1328  String msg = "Bad length in text modification: " + lengthStr;
1329  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1330  }
1331  return;
1332  }
1333  }
1334 
1335  /* getting content */
1336  String content = MessageProcessor.getElementContent(replaceEl);
1337 
1338  /* setting up new modification */
1339  path = UpdatableFragment.improveXPath(path);
1340  TextModification newMod = new TextModification(path, offset, length, content, Constants.TEXT_MOD_REPLACE);
1341  requestInfo.addTextModification(newMod);
1342  } // processDocumentReplace()
1343 
1344  /**
1345  * Method process the message about text modification - insertBefore
1346  * Informations are stored to requestInfo.
1347  *
1348  * @param insertBeforeEl Element to process
1349  * @param requestInfo Informations about client request
1350  */
1351  private void processDocumentInsertBefore(Element insertBeforeEl, RequestInfo requestInfo){
1352  String path = insertBeforeEl.getAttribute("path");
1353 
1354  /* getting content */
1355  String content = MessageProcessor.getElementContent(insertBeforeEl);
1356 
1357  /* setting up new modification */
1358  path = UpdatableFragment.improveXPath(path);
1359  TextModification newMod = new TextModification(path, content, Constants.TEXT_MOD_INS_BEFORE);
1360  requestInfo.addTextModification(newMod);
1361  }
1362 
1363  /**
1364  * Method process the message about text modification - insertAfter
1365  * Informations are stored to requestInfo.
1366  *
1367  * @param insertAfterEl Messages to process
1368  * @param requestInfo Informations about client request
1369  */
1370  private void processDocumentInsertAfter(Element insertAfterEl, RequestInfo requestInfo){
1371 
1372  String path = insertAfterEl.getAttribute("path");
1373 
1374  /* getting content */
1375  String content = MessageProcessor.getElementContent(insertAfterEl);
1376 
1377  /* setting up new modification */
1378  path = UpdatableFragment.improveXPath(path);
1379  TextModification newMod = new TextModification(path, content, Constants.TEXT_MOD_INS_AFTER);
1380  requestInfo.addTextModification(newMod);
1381  }
1382 
1383  /**
1384  * Method process the element with subscription source and return it as object.
1385  *
1386  * @param subscriptionEl element with subscription source
1387  * @param requestInfo Informations about client request
1388  * @param subs Subscription to which this source belongs
1389  * @return subscription source object
1390  */
1391  private Source processSource(Element subscriptionEl, RequestInfo requestInfo, Subscription subs){
1392  Source newSubscription = new Source();
1393  String subscribe = subscriptionEl.getAttribute("subscribe");
1394  if(subscribe == null || subscribe.isEmpty()){
1395  // error - cant find information about positive or negative subscription
1397  String msg = "Cannot find information about positive or negative subscription.";
1398  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1399  }
1400  return null;
1401  }
1402 
1403  // get subscribe parameter
1404  boolean subscribeVal = false;
1405  if(subscribe.equalsIgnoreCase("true")){
1406  subscribeVal = true;
1407  }
1408 
1409  // get typeUri parameter
1410  String typeUri = subscriptionEl.getAttribute("typeUri");
1411  if(typeUri == null){
1412  typeUri = "";
1413  }
1414 
1415  // get authorUri parameter
1416  String authorUri = subscriptionEl.getAttribute("authorUri");
1417  if(authorUri == null){
1418  authorUri = "";
1419  }
1420 
1421  // get groupUri parameter
1422  String groupUri = subscriptionEl.getAttribute("groupUri");
1423  if(groupUri == null){
1424  groupUri = "";
1425  }
1426 
1427  newSubscription.setPolarity(subscribeVal);
1428  newSubscription.setAnnotType(typeUri);
1429  newSubscription.setUser(authorUri);
1430  newSubscription.setSource(groupUri);
1431  newSubscription.setRefSubscription(subs);
1432 
1433  return newSubscription;
1434  } // processSource()
1435 
1436  /**
1437  * Method process the element with document for resynchronization.
1438  *
1439  * @param resynchronizeEl element with document for resynchronization
1440  * @param requestInfo Informations about client request
1441  */
1442  private void processResynchronize(Element resynchronizeEl, RequestInfo requestInfo){
1443  // Get content of resynchronized document
1444  String content = MessageProcessor.getElementContent(resynchronizeEl);
1445  if(content == null){
1446  int langNum = requestInfo.getSession().getLanguageNum();
1447  int lod = requestInfo.getSession().getProtocolLOD();
1448  requestInfo.addError(lod, langNum, Localisation.ERROR_23_MISSING_DOCUMENT_CONTENT);
1450  String msg = "Resynchronization with empty content of the document.";
1451  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1452  }
1453  return;
1454  }
1455  requestInfo.setResyncDocContent(content);
1456  }
1457 
1458  /**
1459  * Method process the element with document for synchronize.
1460  *
1461  * @param synchronizeEl element with document for synchronize
1462  * @param requestInfo Informations about client request
1463  */
1464  private void processSynchronize(Element synchronizeEl, RequestInfo requestInfo){
1465  String uri = synchronizeEl.getAttribute("uri");
1466  if (uri == null) {
1467  uri = "";
1468  }
1469 
1470  if (uri.isEmpty()) {
1471  // if URI of resource is empty, error
1472  int langNum = requestInfo.getSession().getLanguageNum();
1473  int lod = requestInfo.getSession().getProtocolLOD();
1474  requestInfo.addError(lod, langNum, Localisation.ERROR_22_MISSING_DOCUMENT_URI);
1476  String msg = "Synchronization without URI of the resource.";
1477  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1478  }
1479  return;
1480  }
1481 
1482  // process attribute with linearization
1483  String linearize = synchronizeEl.getAttribute("linearize");
1484  if (linearize != null && linearize.equalsIgnoreCase("true")) {
1485  requestInfo.setSyncLinearized(true);
1486  }else{
1487  requestInfo.setSyncLinearized(false);
1488  }
1489 
1490  // process attribute with overwrite (forced synchronization)
1491  String overwrite = synchronizeEl.getAttribute("overwrite");
1492  if (overwrite != null && overwrite.equalsIgnoreCase("true")) {
1493  requestInfo.setSyncWithOverwrite(true);
1494  }else{
1495  requestInfo.setSyncWithOverwrite(false);
1496  }
1497 
1498  // get content of synchronized document
1499  String content = MessageProcessor.getElementContent(synchronizeEl);
1500  if (content == null) { // if content is empty - error
1501  int langNum = requestInfo.getSession().getLanguageNum();
1502  int lod = requestInfo.getSession().getProtocolLOD();
1503  requestInfo.addError(lod, langNum, Localisation.ERROR_23_MISSING_DOCUMENT_CONTENT);
1505  String msg = "Synchronization with empty content of the document.";
1506  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1507  }
1508  }
1509  // create object with synchronized document
1510  AnnotDocument syncDoc = new AnnotDocument(uri, content);
1511  requestInfo.setSyncDocumentData(syncDoc); // store document into requestInfo
1512 
1513  } // processSynchronize()
1514 
1515  /**
1516  * Method that process element with request for reloading either all or single annotation
1517  *
1518  * @param reloadAnnotationEl Element with request
1519  * @param requestInfo Informations about client request
1520  */
1521  private void processReloadAnnotation(Element reloadAnnotationEl, RequestInfo requestInfo){
1522  String annotUri = reloadAnnotationEl.getAttribute("uri");
1523 
1524  /* If uri is missing, user wants to reload all his annotations */
1525  if(annotUri == null || annotUri.isEmpty()){
1526  requestInfo.setReloadAll(true);
1527  return;
1528  }
1529 
1530  //Get ID of annotation
1531  String reloadIdStr = annotUri.replace(AppBean.getBaseAnnotUri(), "");
1532 
1533  //Parse ID
1534  Integer reloadId = null;
1535  if (!reloadIdStr.isEmpty()) {
1536  try {
1537  reloadId = Integer.parseInt(reloadIdStr);
1538  } catch (NumberFormatException ex) {
1539  int langNum = requestInfo.getSession().getLanguageNum();
1540  int lod = requestInfo.getSession().getProtocolLOD();
1541  String contextMsg = "<annotation uri=\"" + annotUri + "\"/>";
1542  requestInfo.addError(lod, langNum, Localisation.ERROR_34_RELOAD_ANNOT_NOT_FOUND, contextMsg);
1543 
1545  String msg = "Bad id of reloaded annotation: " + reloadIdStr;
1546  Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1547  }
1548  return;
1549  }
1550  }
1551 
1552  // Search for annotation
1553  Object[] params = new Object[2];
1554  params[0] = "id";
1555  params[1] = reloadId;
1556 
1557  List reloadList = AppBean.getPersistenceManager().queryDB("Annotation.findById", params);
1558  if(reloadList != null && !reloadList.isEmpty()){
1559  Annotation a = (Annotation) reloadList.get(0);
1560  requestInfo.addReloadAnnotations(a);
1561  }
1562  else{
1563  int langNum = requestInfo.getSession().getLanguageNum();
1564  int lod = requestInfo.getSession().getProtocolLOD();
1565  String contextMsg = "<annotation uri=\"" + annotUri + "\"/>";
1566  requestInfo.addError(lod, langNum, Localisation.ERROR_34_RELOAD_ANNOT_NOT_FOUND, contextMsg);
1567 
1569  String msg = "Unable to find requested annotation: " + annotUri;
1570  Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1571  }
1572  }
1573  } // processReloadAnnotation()
1574 
1575  /**
1576  * Method process the element with query for entity types.
1577  *
1578  * @param entityQueryEl element with query for entity types
1579  * @param requestInfo Informations about client request
1580  */
1581  private void processEntityQuery(Element entityQueryEl, RequestInfo requestInfo){
1582  String type = entityQueryEl.getAttribute("type");
1583  String filter = entityQueryEl.getAttribute("name");
1584  String maxResultsStr = entityQueryEl.getAttribute("maxResults");
1585  int maxResults = -1;
1586 
1587  if (filter.isEmpty()) {
1588  int langNum = requestInfo.getSession().getLanguageNum();
1589  int lod = requestInfo.getSession().getProtocolLOD();
1590  requestInfo.addError(lod, langNum, Localisation.ERROR_63_EMPTY_ENTITY_FILTER);
1591 
1592  requestInfo.setSettings(requestInfo.getSession().getSettings());
1594  String msg = "Empty name of parameter of dictionary request.";
1595  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1596  }
1597 
1598  return;
1599  }
1600 
1601  if (maxResultsStr != null && !maxResultsStr.isEmpty()) {
1602  try {
1603  maxResults = Integer.parseInt(maxResultsStr);
1604  } catch (NumberFormatException ex) {
1605  int langNum = requestInfo.getSession().getLanguageNum();
1606  int lod = requestInfo.getSession().getProtocolLOD();
1607  requestInfo.addError(lod, langNum, Localisation.ERROR_96_BAD_MAX_ENTITIES);
1609  String msg = "Bad form of maximum results input: " + maxResultsStr;
1610  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1611  }
1612  return;
1613  }
1614  }
1615 
1616  requestInfo.setEntityRequest(new RequestInfo.EntityRequest(type,filter, maxResults));
1617  } // processEntityQuery()
1618 
1619  /**
1620  * Process settings message.
1621  * Informations are stored into requestInfo.
1622  * If error occurs, generates error message.
1623  *
1624  * @param settingsEl Element with settings message
1625  * @param requestInfo Informations about client request
1626  */
1627  private void processSettings(Element settingsEl, RequestInfo requestInfo){
1628  // create new empty list of parameters of user settings
1629  ArrayList<Settings> settings = new ArrayList<Settings>();
1630  // get list of elements with parameters
1631  NodeList paramNL = settingsEl.getElementsByTagName("param");
1632  int paramCnt = paramNL.getLength();
1633  for (int i = 0; i < paramCnt; i++) { // for each parameter
1634  Element paramEl = (Element) paramNL.item(i);
1635  String name = paramEl.getAttribute("name");
1636  String value = paramEl.getAttribute("value");
1637  String description = paramEl.getAttribute("description");
1638 
1639  if(!paramEl.hasAttribute("value")){
1640  value = null;
1641  }
1642 
1643  if (name == null) {
1644  name = "";
1645  }
1646  if (description == null) {
1647  description = "";
1648  }
1649  if (name.isEmpty()) { // if name is empty, parameter is bad
1650  int langNum = requestInfo.getSession().getLanguageNum();
1651  int lod = requestInfo.getSession().getProtocolLOD();
1652  // create error message
1653  String info = "<param name=\"\" invalidAttribute=\"name\"/>";
1654  requestInfo.addError(lod, langNum, Localisation.ERROR_21_SETTINGS_MALFORMED, info);
1655  // set old settings to informations about request
1656  // (sent valid actual settings to client)
1657  requestInfo.setSettings(requestInfo.getSession().getSettings());
1659  String msg = "Empty name of parameter of settings.";
1660  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1661  }
1662  return; // if one parameter is bad, whole setting is bad and can't be updated
1663  }
1664  // create object with parameter of user settings
1665  Settings param = new Settings(requestInfo.getSession().getUser(), name, value, description);
1666  settings.add(param); // add parameter to the new list of parameters
1667  } // for each parameter
1668  // store new list of parameters to the informations about request
1669  if(!settings.isEmpty()){
1670  requestInfo.setSettings(settings);
1671  }else{
1672  requestInfo.setSettings(null);
1673  }
1674  } // processSettings()
1675 
1676  /**
1677  * Gets settings of given user
1678  *
1679  * @param user User which settings should be found
1680  * @return Settings of given user
1681  */
1682  private ArrayList<Settings> getUserSettings(User user){
1683  ArrayList<Settings> result = new ArrayList<Settings>();
1684  PersistM persistMan = AppBean.getPersistenceManager();
1685 
1686  Object[] params = new Object[2];
1687  params[0] = "userId";
1688  params[1] = user.getId();
1689  @SuppressWarnings("unchecked")
1690  List<Settings> settingsList = persistMan.queryDB("Settings.findByUser", params);
1691 
1692  if(settingsList != null){
1693  result.addAll(settingsList);
1694  }
1695 
1696  return result;
1697  }
1698 
1699  /**
1700  * Method gets id of user group by strip off base URI.
1701  *
1702  * @param uri uri of group
1703  * @return id of group uri
1704  */
1705  private Integer getGroupIdFromUri(String uri){
1706  if(uri != null){
1707  String groupIdStr = uri.replace(AppBean.getBaseGroupUri(), "");
1708  Integer id = null;
1709 
1710  try{
1711  id = Integer.parseInt(groupIdStr);
1712  }
1713 
1714  catch(NumberFormatException ex){
1715  int langNum = requestInfo.getSession().getLanguageNum();
1716  int lod = requestInfo.getSession().getProtocolLOD();
1717  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
1719  String msg = "Bad id of group: " + groupIdStr;
1720  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1721  }
1722  return null;
1723  }
1724  return id;
1725  }
1726 
1727  return null;
1728  }
1729 
1730  /**
1731  * Method adds a user to the group specified by id.
1732  *
1733  * @param id identification of group
1734  * @param requestInfo Informations about client request
1735  */
1736  private void joinToGroup(Integer id, RequestInfo requestInfo){
1737  // query database for group
1738  Object[] params = new Object[2];
1739  params[0] = "id";
1740  params[1] = id;
1741 
1742  // find group in DB
1743  List gList = AppBean.getPersistenceManager().queryDB("UserGroup.findById", params);
1744  if(gList != null && !gList.isEmpty()) {
1745  // ifgroup was found
1746  UserGroup jGroup = (UserGroup) gList.get(0);
1747  User user = requestInfo.getSession().getUser();
1748 
1749  // test ifuser is in group
1750  if(!user.getGroups().contains(jGroup)) {
1751  // ifuser isn't in this group
1752  if(jGroup.getName().equalsIgnoreCase(Constants.ADMIN_GROUP)) {
1753  int langNum = requestInfo.getSession().getLanguageNum();
1754  int lod = requestInfo.getSession().getProtocolLOD();
1755  String info = "<group name=\"" + Constants.ADMIN_GROUP + "\" uri=\"" + AppBean.getBaseGroupUri() + id.toString() + "\"/>";
1756  requestInfo.addError(lod, langNum, Localisation.ERROR_57_JOIN_ADMINISTRATORS, info);
1758  String msg = "User is trying to join to administrators: " + user.getName();
1759  Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
1760  }
1761  } else {
1762  // add group to user's groups
1763  user.addGroup(jGroup);
1764  // add user to group
1765  jGroup.addUser(user);
1766  // add group into list of just added groups
1767  requestInfo.addJoinedGroup(jGroup);
1768  }
1769  }
1770  } else {
1771  // ifgroup wasn't found - error
1772  int langNum = requestInfo.getSession().getLanguageNum();
1773  int lod = requestInfo.getSession().getProtocolLOD();
1774  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
1776  String msg = "Group to join was not found.";
1777  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1778  }
1779  }
1780  } // joinToGroup()
1781 
1782  /**
1783  * Method removes a user to the group specified by id.
1784  *
1785  * @param id identification of group
1786  * @param requestInfo Informations about client request
1787  */
1788  private void leaveGroup(Integer id, RequestInfo requestInfo){
1789  // query database for group
1790  Object[] params = new Object[2];
1791  params[0] = "id";
1792  params[1] = id;
1793 
1794  // find group in DB
1795  List gList = AppBean.getPersistenceManager().queryDB("UserGroup.findById", params);
1796  if(gList != null && !gList.isEmpty()) {
1797 
1798  // ifgroup was found
1799  UserGroup lGroup = (UserGroup) gList.get(0);
1800  User user = requestInfo.getSession().getUser();
1801 
1802  // test ifuser is in group
1803  if(user.getGroups().contains(lGroup)) {
1804  // ifuser is in this group
1805  if(lGroup.getName().equalsIgnoreCase(Constants.ADMIN_GROUP) && lGroup.getUsers().size() < 2) {
1806  int langNum = requestInfo.getSession().getLanguageNum();
1807  int lod = requestInfo.getSession().getProtocolLOD();
1808  requestInfo.addError(lod, langNum, Localisation.ERROR_58_LAST_ADMIN);
1810  String msg = "Last administrator is trying to leave group.";
1811  Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
1812  }
1813  } else {
1814  // remove group from user's groups
1815  user.getGroups().remove(lGroup);
1816  // remove user from group
1817  lGroup.getUsers().remove(user);
1818  // add group to list of just leaved groups
1819  requestInfo.addLeavedGroup(lGroup);
1820  }
1821  } else {
1822  // ifuser isn't in this group
1823  int langNum = requestInfo.getSession().getLanguageNum();
1824  int lod = requestInfo.getSession().getProtocolLOD();
1825  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
1827  String msg = "Group to leave is not in joined groups.";
1828  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1829  }
1830  }
1831  } else {
1832  // ifgroup wasn't found - error
1833  int langNum = requestInfo.getSession().getLanguageNum();
1834  int lod = requestInfo.getSession().getProtocolLOD();
1835  requestInfo.addError(lod, langNum, Localisation.ERROR_45_UNKNOWN_GROUP);
1837  String msg = "Group to leave was not found.";
1838  Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1839  }
1840  }
1841  } // leaveGroup()
1842 } // public class P2Processor
void processDocumentInsertAfter(Element insertAfterEl, RequestInfo requestInfo)
void processXMLDocument(Element mainElement, RequestInfo requestInfo)
Persistence manager (database manipulator)
Definition: PersistM.java:35
void processSettings(Element settingsEl, RequestInfo requestInfo)
ArrayList< String > processUsersQuerry(Element userQueryEl)
Class representing annotated copy of document.
void procesAddSubscription(Element addSubscriptionEl, RequestInfo requestInfo)
ArrayList< String > processGroupsQuery(Element groupsQueryEl, RequestInfo requestInfo)
void procesChangeSubscription(Element changeSubscriptionEl, RequestInfo requestInfo)
void processUnsubscribe(Element unsubscribeEl, RequestInfo requestInfo)
void leaveGroup(Integer id, RequestInfo requestInfo)
void processDocumentReplace(Element replaceEl, RequestInfo requestInfo)
void processSubscribe(Element subscribeEl, RequestInfo requestInfo)
void processDocumentInsertBefore(Element insertBeforeEl, RequestInfo requestInfo)
Source processSource(Element subscriptionEl, RequestInfo requestInfo, Subscription subs)
Static class which parses and process XML with messages.
Class representing user group.
Definition: UserGroup.java:47
Class representing parameter of user settings.
Definition: Settings.java:45
User processLogin(Element loginEl, RequestInfo requestInfo)
Class which process messages related to suggestions in protocol v 2.0.
void processLeave(Element leaveEl, RequestInfo requestInfo)
Class which parses and process XML with messages with types for protocol version 2.
void processEntityQuery(Element entityQueryEl, RequestInfo requestInfo)
Class representing user.
Definition: User.java:51
Class representing modification of annotated document text.
void processReloadAnnotation(Element reloadAnnotationEl, RequestInfo requestInfo)
void processSubscriptionsQuery(Element subscriptionsQueryEl, RequestInfo requestInfo)
Class which parses and process XML with messages with annotations for protocol version 2...
void processJoin(Element joinEl, RequestInfo requestInfo)
Processed informations about client request.
void processResynchronize(Element resynchronizeEl, RequestInfo requestInfo)
void joinToGroup(Integer id, RequestInfo requestInfo)
void procesRemoveSubscription(Element removeSubscriptionEl, RequestInfo requestInfo)
void processSynchronize(Element synchronizeEl, RequestInfo requestInfo)
Class which parses and process XML with messages for protocol version 2.
Class responsible for localised strings.
Informations about client session.
Class representing source of subscription.
Definition: Source.java:47
void processDocumentModification(Element modificationEl, RequestInfo requestInfo)