19 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0;
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;
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);
78 NodeList loginMsg = mainElement.getElementsByTagName(
"login");
79 Element loginEl = (Element) loginMsg.item(0);
80 if(loginEl != null && loginEl.getParentNode().isSameNode(mainElement)) {
83 requestInfo.setLoggedIn(user);
84 session.setUser(user);
85 session.actualizeAllCachedSettings();
89 AppBean.getSessionsCleaner().setSessionConfirm(session.
getSessionId());
90 requestInfo.appendToReply(P2MessagesCreator.getXMLLoggedUser(user));
95 NodeList disconnMsg = mainElement.getElementsByTagName(
"disconnect");
96 Element disconnEl = (Element) disconnMsg.item(0);
97 if(disconnEl != null) {
100 AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
102 AppBean.removeSession(session);
104 requestInfo.setDisconnect(
true);
113 Iterator<UserGroup> groupsIt = user.getGroupsAL().iterator();
114 while(groupsIt.hasNext()){
115 requestInfo.getSession().addSource(
new SubscribedSource(
"*", null, groupsIt.next().getUri()));
120 user = session.getUser();
125 NodeList disconnMsg = mainElement.getElementsByTagName(
"disconnect");
126 Element disconnEl = (Element) disconnMsg.item(0);
127 int lod = session.getProtocolLOD();
130 String msg =
"User is not logged in.";
131 Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
133 if(disconnEl != null) {
136 AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
139 AppBean.removeSession(session);
140 requestInfo.setDisconnect(
true);
150 NodeList logoutMsg = mainElement.getElementsByTagName(
"logout");
151 Element logoutEl = (Element) logoutMsg.item(0);
152 if(logoutEl != null) {
154 AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
158 session.setUser(null);
159 requestInfo.setLogout(
true);
163 NodeList usersQueryMsg = mainElement.getElementsByTagName(
"getUsers");
164 Element usersQueryEl = (Element) usersQueryMsg.item(0);
165 if(usersQueryEl != null) {
169 boolean restrictions[];
170 NodeList includeOnlyNodes = usersQueryEl.getElementsByTagName(
"includeOnly");
171 Element includeOnlyEl = (Element) includeOnlyNodes.item(0);
172 if(includeOnlyEl != null){
177 restrictions =
new boolean[]{
true,
true,
true,
true,
true,
true};
181 requestInfo.setUsersQueryV2(searchPattern);
182 requestInfo.setUsersRestrictionsV2(restrictions);
186 NodeList groupJoinMsgs = mainElement.getElementsByTagName(
"joinUserGroup");
187 Element joinEl = (Element) groupJoinMsgs.item(0);
193 NodeList groupLeaveMsgs = mainElement.getElementsByTagName(
"leaveUserGroup");
194 Element leaveEl = (Element) groupLeaveMsgs.item(0);
200 NodeList groupsQueryMsgs = mainElement.getElementsByTagName(
"getUserGroups");
201 Element groupsQueryEl = (Element) groupsQueryMsgs.item(0);
202 if(groupsQueryEl != null){
206 boolean restrictions[];
207 NodeList includeOnlyNodes = groupsQueryEl.getElementsByTagName(
"includeOnly");
208 Element includeOnlyEl = (Element) includeOnlyNodes.item(0);
209 if(includeOnlyEl != null){
214 restrictions =
new boolean[]{
true,
true,
true,
true,
true,
true};
218 requestInfo.setUsersGroupRestrictionsV2(restrictions);
222 requestInfo.setGroupsQueryV2(searchPattern);
226 NodeList documentSyncMsg = mainElement.getElementsByTagName(
"synchronize");
227 Element documentSyncEl = (Element) documentSyncMsg.item(0);
228 if(documentSyncEl != null) {
233 NodeList documentResyncMsg = mainElement.getElementsByTagName(
"resynchronize");
234 Element documentResyncEl = (Element) documentResyncMsg.item(0);
235 if(documentResyncEl != null){
240 NodeList subscriptAddMsg = mainElement.getElementsByTagName(
"createSubscription");
241 Element subscriptAddEl = (Element) subscriptAddMsg.item(0);
242 if(subscriptAddEl != null) {
248 NodeList subscriptRemoveMsg = mainElement.getElementsByTagName(
"removeSubscription");
249 Element subscriptRemoveEl = (Element) subscriptRemoveMsg.item(0);
250 if(subscriptRemoveEl != null) {
256 NodeList subscriptChangeMsg = mainElement.getElementsByTagName(
"modifySubscription");
257 Element subscriptChangeEl = (Element) subscriptChangeMsg.item(0);
258 if(subscriptChangeEl != null) {
264 NodeList subscribeMsg = mainElement.getElementsByTagName(
"subscribe");
265 Element subscribeEl = (Element) subscribeMsg.item(0);
266 if(subscribeEl != null) {
272 NodeList unsubscribeMsg = mainElement.getElementsByTagName(
"unsubscribe");
273 Element unsubscribeEl = (Element) unsubscribeMsg.item(0);
274 if(unsubscribeEl != null) {
280 NodeList subscrQueryMsg = mainElement.getElementsByTagName(
"getSubscriptions");
281 Element subscrQueryEl = (Element) subscrQueryMsg.item(0);
282 if(subscrQueryEl != null) {
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()) {
295 requestInfo.setQueryTypeAttOnto(attrGr);
299 NodeList modificationMsg = mainElement.getElementsByTagName(
"modification");
300 Element modificationEl = (Element) modificationMsg.item(0);
301 if(modificationEl != null){
306 NodeList addTypesMsg = mainElement.getElementsByTagName(
"addTypes");
307 Element addTypesEl = (Element) addTypesMsg.item(0);
308 if(addTypesEl != null) {
309 annotTypeProcessor.procesTypesAdd(addTypesEl,
requestInfo);
313 NodeList modifyTypesMsg = mainElement.getElementsByTagName(
"modifyTypes");
314 Element modifyTypesEl = (Element) modifyTypesMsg.item(0);
315 if(modifyTypesEl != null) {
316 annotTypeProcessor.procesTypesChange(modifyTypesEl,
requestInfo);
320 NodeList removeTypesMsg = mainElement.getElementsByTagName(
"removeTypes");
321 Element removeTypesEl = (Element) removeTypesMsg.item(0);
322 if(removeTypesEl != null) {
323 annotTypeProcessor.procesTypesRemove(removeTypesEl,
requestInfo);
327 NodeList queryTypesMsg = mainElement.getElementsByTagName(
"getTypes");
328 Element queryTypesEl = (Element) queryTypesMsg.item(0);
329 if(queryTypesEl != null) {
330 annotTypeProcessor.procesTypeQuery(queryTypesEl,
requestInfo);
334 NodeList addAnnotationsMsg = mainElement.getElementsByTagName(
"createAnnotations");
335 Element addAnnotationsEl = (Element) addAnnotationsMsg.item(0);
336 if(addAnnotationsEl != null) {
338 annotationProcessor.processAddAnnotations(addAnnotationsEl,
requestInfo);
342 NodeList changeAnnotationsMsg = mainElement.getElementsByTagName(
"modifyAnnotations");
343 Element changeAnnotationsEl = (Element) changeAnnotationsMsg.item(0);
344 if(changeAnnotationsEl != null) {
346 annotationProcessor.processChangeAnnotations(changeAnnotationsEl,
requestInfo);
350 NodeList removeAnnotationsMsg = mainElement.getElementsByTagName(
"removeAnnotations");
351 Element removeAnnotationsEl = (Element) removeAnnotationsMsg.item(0);
352 if(removeAnnotationsEl != null) {
354 annotationProcessor.processDeleteAnnotations(removeAnnotationsEl,
requestInfo);
359 NodeList reloadAnnotationMsg = mainElement.getElementsByTagName(
"reloadAnnotation");
360 Element reloadAnnotationEl = (Element) reloadAnnotationMsg.item(0);
361 if(reloadAnnotationEl != null){
367 NodeList getEntityTypesMsg = mainElement.getElementsByTagName(
"getEntityTypes");
368 Element getEntityTypesEl = (Element) getEntityTypesMsg.item(0);
369 if (getEntityTypesEl != null) {
371 requestInfo.setGetEntityTypes(
true);
375 NodeList suggQueryMsg = mainElement.getElementsByTagName(
"suggestAnnotations");
376 Element suggQueryEl = (Element) suggQueryMsg.item(0);
377 if (suggQueryEl != null) {
378 suggestionsProcessor.processSuggestionQuery(suggQueryEl,
requestInfo);
382 NodeList suggConfirmMsg = mainElement.getElementsByTagName(
"confirmSuggestions");
383 Element suggConfirmEl = (Element) suggConfirmMsg.item(0);
384 if (suggConfirmEl != null) {
385 suggestionsProcessor.processSuggestionConfirm(suggConfirmEl,
requestInfo);
389 NodeList suggRefuseMsg = mainElement.getElementsByTagName(
"refuseSuggestions");
390 Element suggRefuseEl = (Element) suggRefuseMsg.item(0);
391 if (suggRefuseEl != null) {
392 suggestionsProcessor.processSuggestionRefuse(suggRefuseEl,
requestInfo);
396 NodeList getAlternativesForMsg = mainElement.getElementsByTagName(
"getAlternativesFor");
397 Element getAlternativesForEl = (Element) getAlternativesForMsg.item(0);
398 if (getAlternativesForEl != null) {
399 suggestionsProcessor.processGetAlternatives(getAlternativesForEl,
requestInfo);
403 NodeList entityQueryMsg = mainElement.getElementsByTagName(
"getEntities");
404 Element entityQueryEl = (Element) entityQueryMsg.item(0);
405 if (entityQueryEl != null) {
411 NodeList settingsMsg = mainElement.getElementsByTagName(
"updateParameters");
412 Element settingsEl = (Element) settingsMsg.item(0);
413 if (settingsEl != null) {
418 NodeList disconnMsg = mainElement.getElementsByTagName(
"disconnect");
419 Element disconnEl = (Element) disconnMsg.item(0);
420 if(disconnEl != null) {
422 AppBean.decrementDocumentUsage(session.getSyncDocument().getId());
424 AppBean.removeSession(session);
425 requestInfo.setDisconnect(
true);
440 PersistM persistMan = AppBean.getPersistenceManager();
443 String userAtt = loginEl.getAttribute(
"login");
450 String passAtt = loginEl.getAttribute(
"password");
457 String tokenAtt = loginEl.getAttribute(
"token");
458 if(tokenAtt == null){
464 String systemAtt = loginEl.getAttribute(
"system");
465 if(systemAtt == null){
471 if(!userAtt.isEmpty() && (!tokenAtt.isEmpty() && !systemAtt.isEmpty())) {
473 String storedToken = AppBean.getExtAuthData(systemAtt, userAtt);
476 if(storedToken == null) {
478 int langNum = requestInfo.getSession().getLanguageNum();
479 int lod = requestInfo.getSession().getProtocolLOD();
482 String msg =
"Unknown authentication token received.";
483 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
489 if(!tokenAtt.equals(storedToken)) {
491 int langNum = requestInfo.getSession().getLanguageNum();
492 int lod = requestInfo.getSession().getProtocolLOD();
495 String msg =
"Bad authentication token received.";
496 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
502 Object[] params =
new Object[4];
505 params[2] =
"comeFrom";
506 params[3] = systemAtt;
507 List uList = persistMan.queryDB(
"User.findByLoginAndSystem", params);
508 if(uList != null && !uList.isEmpty()) {
509 user = (
User) uList.get(0);
516 if(userAtt.isEmpty() || passAtt.isEmpty()) {
518 int langNum = requestInfo.getSession().getLanguageNum();
519 int lod = requestInfo.getSession().getProtocolLOD();
522 String msg =
"Login or password is missing.";
523 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
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();
540 String msg =
"NoSuchAlgorithmException for MD5 algorithm.";
541 Logger.getLogger(P2Processor.class.getName()).log(Level.SEVERE, msg, ex);
546 Object[] params =
new Object[4];
549 params[2] =
"password";
551 List uList = persistMan.queryDB(
"User.findByCredentials", params);
552 if(uList != null && !uList.isEmpty()) {
553 user = (
User) uList.get(0);
559 uList = persistMan.queryDB(
"User.findByCredentials", params);
560 if(uList != null && !uList.isEmpty()) {
561 user = (
User) uList.get(0);
569 uList = persistMan.queryDB(
"User.findByEmailAndPassword", params);
570 if(uList != null && !uList.isEmpty()) {
571 user = (
User) uList.get(0);
577 uList = persistMan.queryDB(
"User.findByEmailAndPassword", params);
578 if(uList != null && !uList.isEmpty()) {
579 user = (
User) uList.get(0);
584 int langNum = requestInfo.getSession().getLanguageNum();
585 int lod = requestInfo.getSession().getProtocolLOD();
588 String msg =
"Authentication by login and password failed (bad login or password).";
589 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
606 String idAttr = userQueryEl.getAttribute(
"uri");
611 String userPrefix = AppBean.getBaseUserUriV2();
612 idAttr = idAttr.replace(userPrefix,
"");
616 String emailAttr = userQueryEl.getAttribute(
"email");
617 if(emailAttr == null){
624 String nameAttr = userQueryEl.getAttribute(
"name");
625 if(nameAttr == null){
632 String groupUriAttr = userQueryEl.getAttribute(
"groupUri");
633 if(groupUriAttr == null){
637 String groupPrefix = AppBean.getBaseGroupUri();
638 groupUriAttr = groupUriAttr.replace(groupPrefix,
"");
656 NodeList restrictionNodes = includeOnlyEl.getElementsByTagName(
"login");
657 Element includeLoginEl = (Element) restrictionNodes.item(0);
658 if(includeLoginEl != null){
663 restrictionNodes = includeOnlyEl.getElementsByTagName(
"name");
664 Element includeNameEl = (Element) restrictionNodes.item(0);
665 if(includeNameEl != null){
670 restrictionNodes = includeOnlyEl.getElementsByTagName(
"email");
671 Element includeEmailEl = (Element) restrictionNodes.item(0);
672 if(includeEmailEl != null){
677 restrictionNodes = includeOnlyEl.getElementsByTagName(
"image");
678 Element includeImageEl = (Element) restrictionNodes.item(0);
679 if(includeImageEl != null){
684 restrictionNodes = includeOnlyEl.getElementsByTagName(
"groups");
685 Element includeGroupsEl = (Element) restrictionNodes.item(0);
686 if(includeGroupsEl != null){
701 String groupUriAttr = joinEl.getAttribute(
"uri");
705 int langNum = requestInfo.getSession().getLanguageNum();
706 int lod = requestInfo.getSession().getProtocolLOD();
709 String msg =
"Join to group without group id.";
710 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
727 String groupUriAttr = leaveEl.getAttribute(
"uri");
731 int langNum = requestInfo.getSession().getLanguageNum();
732 int lod = requestInfo.getSession().getProtocolLOD();
735 String msg =
"Leave to group without group id.";
736 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
754 String nameAttr = groupsQueryEl.getAttribute(
"name");
755 if(nameAttr == null){
761 String uriAttr = groupsQueryEl.getAttribute(
"uri");
766 String groupPrefix = AppBean.getBaseGroupUri();
767 uriAttr = uriAttr.replace(groupPrefix,
"");
770 String withUsersAttr = groupsQueryEl.getAttribute(
"withUsers");
771 if(withUsersAttr == null && withUsersAttr.isEmpty()){
773 withUsersAttr =
"false";
788 String tmpId = addSubscriptionEl.getAttribute(
"tmpId");
789 Integer tmpIdValue = null;
790 if(tmpId == null || tmpId.isEmpty()){
792 int langNum = requestInfo.getSession().getLanguageNum();
793 int lod = requestInfo.getSession().getProtocolLOD();
794 String info =
"<subscription tmpId=\"\" invalidProperty=\"tmpId\"/>";
797 String msg =
"Subscription's temporary id was not found.";
798 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
804 tmpIdValue = Integer.decode(tmpId);
805 }
catch(NumberFormatException ex){
807 int langNum = requestInfo.getSession().getLanguageNum();
808 int lod = requestInfo.getSession().getProtocolLOD();
811 String msg =
"Trying to decode wrong subscription's temporary id: " + tmpId;
812 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
817 String name = addSubscriptionEl.getAttribute(
"name");
818 if(name == null || name.isEmpty()){
820 int langNum = requestInfo.getSession().getLanguageNum();
821 int lod = requestInfo.getSession().getProtocolLOD();
822 String info =
"<subscription tmpId=\"" + tmpId +
"\" invalidProperty=\"name\"/>";
825 String msg =
"Subscription's name was not found.";
826 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
832 PersistM persistMan = AppBean.getPersistenceManager();
835 Object[] params =
new Object[4];
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()) {
844 int langNum = requestInfo.getSession().getLanguageNum();
845 int lod = requestInfo.getSession().getProtocolLOD();
846 String info =
"<subscription tmpId=\"" + tmpId +
"\"/>";
849 String msg =
"Subscription with this name already exists.";
850 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
856 subsPackage.setName(name);
857 subsPackage.setUser(requestInfo.getSession().getUser());
858 subsPackage.setTmpId(tmpIdValue);
860 if(subsPackage.
getUser().getGroups() != null && !subsPackage.
getUser().getGroups().isEmpty()){
861 subsPackage.setGroup(subsPackage.getUser().getGroups().get(0));
863 int langNum = requestInfo.getSession().getLanguageNum();
864 int lod = requestInfo.getSession().getProtocolLOD();
867 String msg =
"User does not have a group.";
868 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
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) {
880 if (actualSubscription != null) {
881 subsPackage.addSubscription(actualSubscription);
883 int langNum = requestInfo.getSession().getLanguageNum();
884 int lod = requestInfo.getSession().getProtocolLOD();
885 String info =
"<subscription tmpId=\"" + tmpId +
"\" invalidProperty=\"source\"/>";
892 requestInfo.addNewSubscriptions(subsPackage);
903 String uri = changeSubscriptionEl.getAttribute(
"uri");
905 if(uri == null || uri.isEmpty()){
907 int langNum = requestInfo.getSession().getLanguageNum();
908 int lod = requestInfo.getSession().getProtocolLOD();
909 String info =
"<subscription uri=\"\" invalidProperty=\"uri\"/>";
912 String msg =
"Subscription's uri was not found.";
913 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
919 id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(),
""));
920 }
catch(NumberFormatException ex){
922 int langNum = requestInfo.getSession().getLanguageNum();
923 int lod = requestInfo.getSession().getProtocolLOD();
924 String info =
"<subscription uri=\"" + uri +
"\" invalidProperty=\"uri\"/>";
927 String msg =
"Trying to decode wrong subscription's id.";
928 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
934 PersistM persistMan = AppBean.getPersistenceManager();
937 Object[] params =
new Object[2];
940 @SuppressWarnings(
"unchecked")
941 List<Subscription> pakckageList = persistMan.queryDB(
"Subscription.findById", params);
942 if(pakckageList != null && !pakckageList.isEmpty()) {
943 currentPackage = pakckageList.get(0);
946 int langNum = requestInfo.getSession().getLanguageNum();
947 int lod = requestInfo.getSession().getProtocolLOD();
950 String msg =
"Subscription with this id doesn't exists: " + id;
951 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
956 String name = changeSubscriptionEl.getAttribute(
"name");
957 if(name == null || name.isEmpty()){
959 int langNum = requestInfo.getSession().getLanguageNum();
960 int lod = requestInfo.getSession().getProtocolLOD();
961 String info =
"<subscription uri=\"" + uri +
"\" invalidProperty=\"name\"/>";
964 String msg =
"Subscription name was not found.";
965 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
970 subsPackage.setName(name);
971 subsPackage.setUser(requestInfo.getSession().getUser());
972 subsPackage.setId(id);
973 subsPackage.setGroup(currentPackage.getGroup());
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) {
982 if (actualSubscription != null) {
983 subsPackage.addSubscription(actualSubscription);
985 int langNum = requestInfo.getSession().getLanguageNum();
986 int lod = requestInfo.getSession().getProtocolLOD();
987 String info =
"<subscription uri=\"" + uri +
"\" invalidProperty=\"source\"/>";
994 requestInfo.addUpdatedSubscriptions(subsPackage);
1004 String uri = removeSubscriptionEl.getAttribute(
"uri");
1006 if(uri == null || uri.isEmpty()){
1008 int langNum = requestInfo.getSession().getLanguageNum();
1009 int lod = requestInfo.getSession().getProtocolLOD();
1012 String msg =
"Subscription's uri was not found.";
1013 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1019 id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(),
""));
1020 }
catch(NumberFormatException ex){
1022 int langNum = requestInfo.getSession().getLanguageNum();
1023 int lod = requestInfo.getSession().getProtocolLOD();
1026 String msg =
"Trying to decode wrong subscription's id.";
1027 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1033 PersistM persistMan = AppBean.getPersistenceManager();
1036 Object[] params =
new Object[2];
1039 @SuppressWarnings(
"unchecked")
1040 List<Subscription> pakckageList = persistMan.queryDB(
"Subscription.findById", params);
1041 if(pakckageList != null && !pakckageList.isEmpty()) {
1042 currentPackage = pakckageList.get(0);
1045 int langNum = requestInfo.getSession().getLanguageNum();
1046 int lod = requestInfo.getSession().getProtocolLOD();
1049 String msg =
"Subscription with this id doesn't exists.";
1050 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1055 requestInfo.addDeletedSubscription(currentPackage);
1066 String uri = subscribeEl.getAttribute(
"subscriptionUri");
1068 if(uri == null || uri.isEmpty()){
1070 int langNum = requestInfo.getSession().getLanguageNum();
1071 int lod = requestInfo.getSession().getProtocolLOD();
1074 String msg =
"Uri of subscription not found: " + uri;
1075 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1081 id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(),
""));
1082 }
catch(NumberFormatException ex){
1084 int langNum = requestInfo.getSession().getLanguageNum();
1085 int lod = requestInfo.getSession().getProtocolLOD();
1088 String msg =
"Can't decode id of subscription: " + id;
1089 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1095 PersistM persistMan = AppBean.getPersistenceManager();
1097 Object[] params =
new Object[2];
1100 @SuppressWarnings(
"unchecked")
1101 List<Subscription> pakckageList = persistMan.queryDB(
"Subscription.findById", params);
1102 if(pakckageList != null && !pakckageList.isEmpty()) {
1103 subscriptionToSubs = pakckageList.get(0);
1106 int langNum = requestInfo.getSession().getLanguageNum();
1107 int lod = requestInfo.getSession().getProtocolLOD();
1112 msg =
"Can't find subscription with id:" + id.toString();
1114 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1119 requestInfo.addToSubscribe(subscriptionToSubs);
1130 String uri = unsubscribeEl.getAttribute(
"subscriptionUri");
1132 if (uri == null || uri.isEmpty()) {
1134 int langNum = requestInfo.getSession().getLanguageNum();
1135 int lod = requestInfo.getSession().getProtocolLOD();
1138 String msg =
"Uri of subscription not found.";
1139 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1145 id = Integer.decode(uri.replace(AppBean.getBaseSubscriptionUri(),
""));
1146 }
catch(NumberFormatException ex){
1148 int langNum = requestInfo.getSession().getLanguageNum();
1149 int lod = requestInfo.getSession().getProtocolLOD();
1152 String msg =
"Can't decode id of subscription: " +
id +
" from uri " + uri;
1153 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1159 PersistM persistMan = AppBean.getPersistenceManager();
1161 Object[] params =
new Object[2];
1164 @SuppressWarnings(
"unchecked")
1165 List<Subscription> pakckageList = persistMan.queryDB(
"Subscription.findById", params);
1166 if(pakckageList != null && !pakckageList.isEmpty()) {
1167 subscriptionToUnsubs = pakckageList.get(0);
1170 int langNum = requestInfo.getSession().getLanguageNum();
1171 int lod = requestInfo.getSession().getProtocolLOD();
1175 String msg =
"Unable to find subscription with id = " + id;
1176 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1182 requestInfo.addToUnsubscribe(subscriptionToUnsubs);
1194 String subsUri = subscriptionsQueryEl.getAttribute(
"subscriptionUri");
1195 if(subsUri == null){
1200 String authorUri = subscriptionsQueryEl.getAttribute(
"authorUri");
1201 if(authorUri == null){
1206 String groupUri = subscriptionsQueryEl.getAttribute(
"groupUri");
1207 if(groupUri == null){
1211 requestInfo.setSubscriptionQuery(query);
1223 String lastModNumberStr = modificationEl.getAttribute(
"lastApplied");
1227 if (lastModNumberStr != null && !lastModNumberStr.isEmpty()) {
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 +
"\"/>";
1237 String msg =
"Bad number of last applied modification.";
1238 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1243 int langNum = requestInfo.getSession().getLanguageNum();
1244 int lod = requestInfo.getSession().getProtocolLOD();
1245 String info =
"<modification id=\"" + lastModNumberStr +
"\"/>";
1249 String msg =
"Bad number of last applied modification.";
1250 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1256 requestInfo.setLastModificationNumber(lastModNumber);
1259 NodeList childNodes = modificationEl.getChildNodes();
1260 int tmpNum = childNodes.getLength();
1262 for (
int i = 0; i < tmpNum; i++) {
1263 Node node = childNodes.item(i);
1265 if (node.getNodeType() == Node.ELEMENT_NODE) {
1266 Element e = (Element) node;
1267 String tagName = e.getTagName();
1269 if (tagName != null && !tagName.isEmpty()) {
1271 if (tagName.equals(
"replace")) {
1273 }
else if (tagName.equals(
"insertBefore")) {
1275 }
else if (tagName.equals(
"insertAfter")) {
1292 String path = replaceEl.getAttribute(
"path");
1293 String offsetStr = replaceEl.getAttribute(
"offset");
1294 String lengthStr = replaceEl.getAttribute(
"length");
1298 Integer offset = null;
1299 if(offsetStr != null && !offsetStr.isEmpty()){
1301 offset = Integer.parseInt(offsetStr);
1303 catch (NumberFormatException nfe) {
1304 int langNum = requestInfo.getSession().getLanguageNum();
1305 int lod = requestInfo.getSession().getProtocolLOD();
1306 String info =
"<modification id=\"" + requestInfo.getLastModificationNumber() +
"\"/>";
1309 String msg =
"Bad offset in text modification: " + offsetStr;
1310 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1317 Integer length = null;
1318 if(lengthStr != null && !lengthStr.isEmpty()){
1320 length = Integer.parseInt(lengthStr);
1322 catch (NumberFormatException nfe) {
1323 int langNum = requestInfo.getSession().getLanguageNum();
1324 int lod = requestInfo.getSession().getProtocolLOD();
1325 String info =
"<modification id=\"" + requestInfo.getLastModificationNumber() +
"\"/>";
1328 String msg =
"Bad length in text modification: " + lengthStr;
1329 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1336 String content = MessageProcessor.getElementContent(replaceEl);
1339 path = UpdatableFragment.improveXPath(path);
1341 requestInfo.addTextModification(newMod);
1352 String path = insertBeforeEl.getAttribute(
"path");
1355 String content = MessageProcessor.getElementContent(insertBeforeEl);
1358 path = UpdatableFragment.improveXPath(path);
1360 requestInfo.addTextModification(newMod);
1372 String path = insertAfterEl.getAttribute(
"path");
1375 String content = MessageProcessor.getElementContent(insertAfterEl);
1378 path = UpdatableFragment.improveXPath(path);
1380 requestInfo.addTextModification(newMod);
1393 String subscribe = subscriptionEl.getAttribute(
"subscribe");
1394 if(subscribe == null || subscribe.isEmpty()){
1397 String msg =
"Cannot find information about positive or negative subscription.";
1398 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1404 boolean subscribeVal =
false;
1405 if(subscribe.equalsIgnoreCase(
"true")){
1406 subscribeVal =
true;
1410 String typeUri = subscriptionEl.getAttribute(
"typeUri");
1411 if(typeUri == null){
1416 String authorUri = subscriptionEl.getAttribute(
"authorUri");
1417 if(authorUri == null){
1422 String groupUri = subscriptionEl.getAttribute(
"groupUri");
1423 if(groupUri == null){
1427 newSubscription.setPolarity(subscribeVal);
1428 newSubscription.setAnnotType(typeUri);
1429 newSubscription.setUser(authorUri);
1430 newSubscription.setSource(groupUri);
1431 newSubscription.setRefSubscription(subs);
1433 return newSubscription;
1444 String content = MessageProcessor.getElementContent(resynchronizeEl);
1445 if(content == null){
1446 int langNum = requestInfo.getSession().getLanguageNum();
1447 int lod = requestInfo.getSession().getProtocolLOD();
1450 String msg =
"Resynchronization with empty content of the document.";
1451 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1455 requestInfo.setResyncDocContent(content);
1465 String uri = synchronizeEl.getAttribute(
"uri");
1470 if (uri.isEmpty()) {
1472 int langNum = requestInfo.getSession().getLanguageNum();
1473 int lod = requestInfo.getSession().getProtocolLOD();
1476 String msg =
"Synchronization without URI of the resource.";
1477 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1483 String linearize = synchronizeEl.getAttribute(
"linearize");
1484 if (linearize != null && linearize.equalsIgnoreCase(
"true")) {
1485 requestInfo.setSyncLinearized(
true);
1487 requestInfo.setSyncLinearized(
false);
1491 String overwrite = synchronizeEl.getAttribute(
"overwrite");
1492 if (overwrite != null && overwrite.equalsIgnoreCase(
"true")) {
1493 requestInfo.setSyncWithOverwrite(
true);
1495 requestInfo.setSyncWithOverwrite(
false);
1499 String content = MessageProcessor.getElementContent(synchronizeEl);
1500 if (content == null) {
1501 int langNum = requestInfo.getSession().getLanguageNum();
1502 int lod = requestInfo.getSession().getProtocolLOD();
1505 String msg =
"Synchronization with empty content of the document.";
1506 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1511 requestInfo.setSyncDocumentData(syncDoc);
1522 String annotUri = reloadAnnotationEl.getAttribute(
"uri");
1525 if(annotUri == null || annotUri.isEmpty()){
1526 requestInfo.setReloadAll(
true);
1531 String reloadIdStr = annotUri.replace(AppBean.getBaseAnnotUri(),
"");
1534 Integer reloadId = null;
1535 if (!reloadIdStr.isEmpty()) {
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 +
"\"/>";
1545 String msg =
"Bad id of reloaded annotation: " + reloadIdStr;
1546 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1553 Object[] params =
new Object[2];
1555 params[1] = reloadId;
1557 List reloadList = AppBean.getPersistenceManager().queryDB(
"Annotation.findById", params);
1558 if(reloadList != null && !reloadList.isEmpty()){
1560 requestInfo.addReloadAnnotations(a);
1563 int langNum = requestInfo.getSession().getLanguageNum();
1564 int lod = requestInfo.getSession().getProtocolLOD();
1565 String contextMsg =
"<annotation uri=\"" + annotUri +
"\"/>";
1569 String msg =
"Unable to find requested annotation: " + annotUri;
1570 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1582 String type = entityQueryEl.getAttribute(
"type");
1583 String filter = entityQueryEl.getAttribute(
"name");
1584 String maxResultsStr = entityQueryEl.getAttribute(
"maxResults");
1585 int maxResults = -1;
1587 if (filter.isEmpty()) {
1588 int langNum = requestInfo.getSession().getLanguageNum();
1589 int lod = requestInfo.getSession().getProtocolLOD();
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);
1601 if (maxResultsStr != null && !maxResultsStr.isEmpty()) {
1603 maxResults = Integer.parseInt(maxResultsStr);
1604 }
catch (NumberFormatException ex) {
1605 int langNum = requestInfo.getSession().getLanguageNum();
1606 int lod = requestInfo.getSession().getProtocolLOD();
1609 String msg =
"Bad form of maximum results input: " + maxResultsStr;
1610 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1616 requestInfo.setEntityRequest(
new RequestInfo.EntityRequest(type,filter, maxResults));
1629 ArrayList<Settings> settings =
new ArrayList<Settings>();
1631 NodeList paramNL = settingsEl.getElementsByTagName(
"param");
1632 int paramCnt = paramNL.getLength();
1633 for (
int i = 0; i < paramCnt; i++) {
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");
1639 if(!paramEl.hasAttribute(
"value")){
1646 if (description == null) {
1649 if (name.isEmpty()) {
1650 int langNum = requestInfo.getSession().getLanguageNum();
1651 int lod = requestInfo.getSession().getProtocolLOD();
1653 String info =
"<param name=\"\" invalidAttribute=\"name\"/>";
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);
1666 settings.add(param);
1669 if(!settings.isEmpty()){
1670 requestInfo.setSettings(settings);
1672 requestInfo.setSettings(null);
1683 ArrayList<Settings> result =
new ArrayList<Settings>();
1684 PersistM persistMan = AppBean.getPersistenceManager();
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);
1692 if(settingsList != null){
1693 result.addAll(settingsList);
1707 String groupIdStr = uri.replace(AppBean.getBaseGroupUri(),
"");
1711 id = Integer.parseInt(groupIdStr);
1714 catch(NumberFormatException ex){
1715 int langNum = requestInfo.getSession().getLanguageNum();
1716 int lod = requestInfo.getSession().getProtocolLOD();
1719 String msg =
"Bad id of group: " + groupIdStr;
1720 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1738 Object[] params =
new Object[2];
1743 List gList = AppBean.getPersistenceManager().queryDB(
"UserGroup.findById", params);
1744 if(gList != null && !gList.isEmpty()) {
1747 User user = requestInfo.getSession().getUser();
1750 if(!user.
getGroups().contains(jGroup)) {
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() +
"\"/>";
1758 String msg =
"User is trying to join to administrators: " + user.getName();
1759 Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
1763 user.addGroup(jGroup);
1765 jGroup.addUser(user);
1767 requestInfo.addJoinedGroup(jGroup);
1772 int langNum = requestInfo.getSession().getLanguageNum();
1773 int lod = requestInfo.getSession().getProtocolLOD();
1776 String msg =
"Group to join was not found.";
1777 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1790 Object[] params =
new Object[2];
1795 List gList = AppBean.getPersistenceManager().queryDB(
"UserGroup.findById", params);
1796 if(gList != null && !gList.isEmpty()) {
1800 User user = requestInfo.getSession().getUser();
1806 int langNum = requestInfo.getSession().getLanguageNum();
1807 int lod = requestInfo.getSession().getProtocolLOD();
1810 String msg =
"Last administrator is trying to leave group.";
1811 Logger.getLogger(P2Processor.class.getName()).log(Level.WARNING, msg);
1815 user.getGroups().
remove(lGroup);
1817 lGroup.getUsers().
remove(user);
1819 requestInfo.addLeavedGroup(lGroup);
1823 int langNum = requestInfo.getSession().getLanguageNum();
1824 int lod = requestInfo.getSession().getProtocolLOD();
1827 String msg =
"Group to leave is not in joined groups.";
1828 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
1833 int langNum = requestInfo.getSession().getLanguageNum();
1834 int lod = requestInfo.getSession().getProtocolLOD();
1837 String msg =
"Group to leave was not found.";
1838 Logger.getLogger(P2Processor.class.getName()).log(Level.ALL, msg);
Constants for protocol version 2.
Class representing subscription.
void processDocumentInsertAfter(Element insertAfterEl, RequestInfo requestInfo)
static int USER_NAME_ATTR
static final int ERROR_1_BAD_CREDENTIALS
AnnotDocument getSyncDocument()
static int USERS_Q_GROUP_ATTR
static final int LOG_LEVEL_ALL_ERRORS
void processXMLDocument(Element mainElement, RequestInfo requestInfo)
Persistence manager (database manipulator)
static final int ERROR_100_UNKNOWN_ERROR
static int SUBS_QUERY_URI
static final int ERROR_64_UNKNOWN_SUB_URI
void processSettings(Element settingsEl, RequestInfo requestInfo)
ArrayList< Settings > getUserSettings(User user)
ArrayList< String > processUsersQuerry(Element userQueryEl)
static final int ERROR_23_MISSING_DOCUMENT_CONTENT
Class representing annotated copy of document.
static final int ERROR_65_SUBSCRIPTION_MALFORMED
void procesAddSubscription(Element addSubscriptionEl, RequestInfo requestInfo)
ArrayList< String > processGroupsQuery(Element groupsQueryEl, RequestInfo requestInfo)
static int SUBS_QUERY_COUNT
static final int LOG_LEVEL_SERVER_INTERNAL_ERRORS
static final int TEXT_MOD_REPLACE
static final int ERROR_45_UNKNOWN_GROUP
static final int ERROR_106_DUPLICIT_SUBSCRIPTION
boolean[] processIncludeOnly(Element includeOnlyEl)
static final String ADMIN_GROUP
void procesChangeSubscription(Element changeSubscriptionEl, RequestInfo requestInfo)
void processUnsubscribe(Element unsubscribeEl, RequestInfo requestInfo)
void leaveGroup(Integer id, RequestInfo requestInfo)
static final int ERROR_22_MISSING_DOCUMENT_URI
void processDocumentReplace(Element replaceEl, RequestInfo requestInfo)
static final int ERROR_97_NOT_IN_GROUP
void processSubscribe(Element subscribeEl, RequestInfo requestInfo)
void processDocumentInsertBefore(Element insertBeforeEl, RequestInfo requestInfo)
static final int TEXT_MOD_INS_AFTER
Source processSource(Element subscriptionEl, RequestInfo requestInfo, Subscription subs)
static int USER_ATTR_COUNT
Static class which parses and process XML with messages.
Class representing user group.
static int SUBS_QUERY_AUTHOR
static int GROUPS_Q_ATTR_COUNT
static int USERS_Q_NAME_ATTR
Class representing parameter of user settings.
static int USERS_Q_URI_ATTR
Integer getGroupIdFromUri(String uri)
User processLogin(Element loginEl, RequestInfo requestInfo)
static final int ERROR_58_LAST_ADMIN
List< UserGroup > getGroups()
Class which process messages related to suggestions in protocol v 2.0.
void processLeave(Element leaveEl, RequestInfo requestInfo)
static final int ERROR_57_JOIN_ADMINISTRATORS
static int USER_LOGIN_ATTR
Class which parses and process XML with messages with types for protocol version 2.
Class for XML document fragment.
void processEntityQuery(Element entityQueryEl, RequestInfo requestInfo)
static final int LOG_LEVEL
Class representing modification of annotated document text.
void processReloadAnnotation(Element reloadAnnotationEl, RequestInfo requestInfo)
EditorSession getSession()
static final int LOG_LEVEL_ALL
static final int ERROR_63_EMPTY_ENTITY_FILTER
void processSubscriptionsQuery(Element subscriptionsQueryEl, RequestInfo requestInfo)
static int USER_GROUPS_ATTR
Class which parses and process XML with messages with annotations for protocol version 2...
static int USER_IMAGE_ATTR
static final int ERROR_50_BAD_MODIFICATION
static int USERS_Q_EMAIL_ATTR
void processJoin(Element joinEl, RequestInfo requestInfo)
static final int WARNING_5_NOT_LOGGED_IN
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.
static int SUBS_QUERY_GROUP
Class responsible for localised strings.
static int USERS_Q_ATTR_COUNT
Subscribed source of annotations.
Informations about client session.
static final int ERROR_34_RELOAD_ANNOT_NOT_FOUND
static final int ERROR_21_SETTINGS_MALFORMED
Class representing annotation.
Class representing source of subscription.
void processDocumentModification(Element modificationEl, RequestInfo requestInfo)
static int USER_EMAIL_ATTR
static final int TEXT_MOD_INS_BEFORE
static final int ERROR_96_BAD_MAX_ENTITIES
static int GROUPS_Q_W_USERS