14 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0;
24 import static cz.vutbr.fit.knot.annotations.comet.protocolV2_0.P2AnnotBaseProcessor.getUriType;
44 import java.util.logging.Level;
45 import java.util.logging.Logger;
46 import org.w3c.dom.Element;
47 import org.w3c.dom.NodeList;
66 String minConfidenceStr = suggQueryEl.getAttribute(
"minConfidence");
67 if(minConfidenceStr == null || minConfidenceStr.isEmpty()){
69 int langNum = requestInfo.getSession().getLanguageNum();
70 int lod = requestInfo.getSession().getProtocolLOD();
73 String msg =
"Can't found minimal confidence attribute in request.";
74 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
79 Integer minConfidence;
81 minConfidence = Integer.parseInt(minConfidenceStr);
82 }
catch(NumberFormatException ex){
84 int langNum = requestInfo.getSession().getLanguageNum();
85 int lod = requestInfo.getSession().getProtocolLOD();
88 String msg =
"Can't decode minConfidence value. Value is: " + minConfidenceStr;
89 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
94 Integer autoConfirm = null;
96 String autoConfirmStr = suggQueryEl.getAttribute(
"autoConfirm");
97 if (autoConfirmStr != null && !autoConfirmStr.isEmpty()) {
99 autoConfirm = Integer.parseInt(autoConfirmStr);
100 }
catch (NumberFormatException ex) {
102 int langNum = requestInfo.getSession().getLanguageNum();
103 int lod = requestInfo.getSession().getProtocolLOD();
106 String msg =
"Can't decode autoConfirm value. Value is: " + autoConfirmStr;
107 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
113 ArrayList<Fragment> fragments =
new ArrayList<Fragment>();
114 NodeList fragmentsElems = suggQueryEl.getElementsByTagName(
"fragments");
115 Element fragmentsEl = (Element) fragmentsElems.item(0);
116 if(fragmentsEl != null) {
119 if(fragments == null || fragments.isEmpty()){
124 fragments.add(
new Fragment(
"", null, null));
127 ArrayList<String> typesUris = null;
128 NodeList suggTypesElems = suggQueryEl.getElementsByTagName(
"types");
129 Element suggTypesEl = (Element) suggTypesElems.item(0);
130 if(suggTypesEl != null) {
132 if(typesUris == null || typesUris.isEmpty()){
138 if(autoConfirm == null){
139 requestInfo.setAutoconfirmRequested(
false);
141 requestInfo.setAutoconfirmRequested(
true);
144 requestInfo.getSession().setAutoConfirm(autoConfirm);
145 requestInfo.getSession().setMinConfidence(minConfidence);
146 requestInfo.getSession().setSuggestionsFr(fragments);
147 requestInfo.getSession().setSuggestionsTypes(typesUris);
148 requestInfo.setSuggFragmentChanged(
true);
150 requestInfo.getSession().setSugRequestFlag(Boolean.TRUE);
153 if (autoConfirm != null && autoConfirm > 0 && autoConfirm <= 100) {
165 ArrayList<Suggestion> allSuggest;
166 if (requestInfo.
getSession().getDefaultGroup() == null) {
167 int lod = requestInfo.getSession().getProtocolLOD();
170 String msg =
"User is not in any group.";
171 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.SEVERE, msg);
175 allSuggest = SuggestionManager.getSuggestionsFromDB(requestInfo.getSession().getSyncDocument().getId());
176 ArrayList<Suggestion> updatedSuggs =
new ArrayList<Suggestion>();
178 ArrayList<Suggestion> rSug = SuggestionManager.getNestedSuggFromToDelete(allSuggest, removedSug);
188 NodeList confirmedElems = suggConfirmEl.getElementsByTagName(
"suggestion");
189 HashMap<String,Annotation> confirmedSuggestions =
new HashMap<String,Annotation>();
190 ArrayList<Annotation> annotList =
new ArrayList<Annotation>();
192 for(
int index = 0; index < confirmedElems.getLength(); index ++){
193 Element suggEl = (Element) confirmedElems.item(index);
196 String suggModified = suggEl.getAttribute(
"modified");
197 if (suggModified == null && suggModified.isEmpty()) {
199 int langNum = requestInfo.getSession().getLanguageNum();
200 int lod = requestInfo.getSession().getProtocolLOD();
201 String suggUri = suggEl.getAttribute(
"uri");
202 if (suggUri == null) {
203 NodeList annotsElems = suggEl.getElementsByTagName(
"oa:Annotation");
204 Element annotEl = (Element) annotsElems.item(0);
205 if (annotEl != null) {
206 suggUri = annotEl.getAttribute(
"rdf:about");
209 if (suggUri == null) {
212 String info =
"<suggestion uri=\"" + suggUri +
"\"/>";
215 String msg =
"Can't find information about modification in suggestion. Suggestion is not comfirmed. Index: " + Integer.toString(index);
216 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
221 boolean modified = Boolean.valueOf(suggModified);
226 NodeList annotsElems = suggEl.getElementsByTagName(
"oa:Annotation");
227 Element annotEl = (Element) annotsElems.item(0);
228 if (annotEl != null) {
230 if (newAnnotation != null) {
232 String idString = newAnnotation.getTmpId();
235 logEntry.setConfirmedVersion(newAnnotation);
236 requestInfo.getFlier().AddAddedAnnotation(newAnnotation);
239 confirmedSuggestions.put(newAnnotation.getTmpId(),newAnnotation);
240 annotList.add(newAnnotation);
248 int langNum = requestInfo.getSession().getLanguageNum();
249 int lod = requestInfo.getSession().getProtocolLOD();
250 String suggUri = suggEl.getAttribute(
"uri");
251 if (suggUri == null) {
254 String info =
"<suggestion uri=\"" + suggUri +
"\"/>";
257 String msg =
"There isn't oa:Annotation element in suggestion element of suggestion confirmation.";
258 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
263 String suggUri = suggEl.getAttribute(
"uri");
264 if(suggUri == null && suggUri.isEmpty()){
266 int langNum = requestInfo.getSession().getLanguageNum();
267 int lod = requestInfo.getSession().getProtocolLOD();
268 String info =
"<suggestion uri=\"\"/>";
271 String msg =
"Can't find URI of confirmed suggestion. URI of confirmed suggestion is required.";
272 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
277 String idString = suggUri.replace(AppBean.getBaseUri() +
"/sugg/",
"");
284 if (requestInfo.
getSession().getSendedSuggestions() != null && !requestInfo.
getSession().getSendedSuggestions().isEmpty()) {
287 id = Integer.parseInt(logEntry.getTmpId());
288 }
catch (NumberFormatException nfe) {
290 String msg =
"The ID of the confirmed suggestion is not a number: " + logEntry.getTmpId();
291 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
295 if (
id != null && requestInfo.
getSession().isSuggInSendedSuggestions(id)) {
297 Suggestion sended = SuggestionManager.getSuggestionFromList(id, allSuggest);
298 if (sended == null) {
300 String msg =
"Unable to confirm suggestion with id = " +
id +
". Suggestion with this id is not found in sended suggestions list.";
301 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
307 sendedSug.setTmpId(logEntry.getTmpId());
308 sendedSug.updateWithSuggestion(sended);
309 sendedSug.setUser(requestInfo.getSession().getUser());
310 sendedSug.setAuthorIdStr(requestInfo.getSession().getUser().getURIV2());
311 sendedSug.setAuthorAddress(requestInfo.getSession().getUser().getEmail());
312 sendedSug.setAuthorName(requestInfo.getSession().getUser().getName());
313 sendedSug.setCreated(
new Date());
315 confirmedSuggestions.put(sended.getURIV2(), sendedSug);
316 annotList.add(sendedSug);
317 if (logEntry.getConfirmedVersion() == null) {
318 logEntry.setConfirmedVersion(sendedSug);
319 requestInfo.getFlier().AddAddedAnnotation(sendedSug);
321 if (!modified && requestInfo.
getSession().getKBRefMode()) {
323 sendedSug.getAttributes().add(uAAt);
325 logEntry.setSuggestion(sendedSug);
328 requestInfo.addConfirmedSuggestion(logEntry);
332 String msg =
"Suggestion with the following ID not found: " + logEntry.getTmpId();
333 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
341 if (requestInfo.
getSession().getEnableUpdatePositiveFeedback()) {
355 ArrayList<SuggestionLogEntry> suggLog = requestInfo.getConfirmedSuggestions();
356 Integer groupId = requestInfo.getSession().getDefaultGroup().getId();
358 ArrayList<SuggestionLogEntry> addToLog =
new ArrayList<SuggestionLogEntry>();
360 ArrayList<Suggestion> allSugg = requestInfo.getSession().getWholeSendedSuggestions();
361 if (allSugg != null && !allSugg.isEmpty()) {
362 HashMap<Integer, ArrayList<SuggestionFragment>> sugToLinFragments =
new HashMap<Integer, ArrayList<SuggestionFragment>>();
363 SECAPISuggestionTranslator.linearizeSuggestions(sugToLinFragments, requestInfo.getSession().getParsedSyncDocument(), allSugg);
365 int docLength = requestInfo.getSession().getParsedLinDocument().length();
367 Iterator<SuggestionLogEntry> confSugIt = suggLog.iterator();
368 while (confSugIt.hasNext()) {
372 Integer confirmedSuggestionId = Integer.parseInt(confSugLogEntry.getTmpId());
374 ArrayList<SuggestionFragment> suggFragList = confirmedSuggestion.getFragmentsAL();
375 AnnotType confirmedSuggType = confirmedSuggestion.getAnnotType();
378 String confirmedURI = confirmedSuggestion.getSAEntityIdentifier();
379 if (confirmedURI != null && !confirmedURI.isEmpty()) {
380 if (suggFragList != null && !suggFragList.isEmpty()) {
381 if (suggFragList.size() >= 2) {
387 int rightSep = docLength;
388 Integer curOffset = null;
389 ArrayList<SuggestionFragment> frags = sugToLinFragments.get(confirmedSuggestionId);
391 if (frags != null && !frags.isEmpty()) {
397 curOffset = frag.getOffset();
398 Iterator<Integer> sepIt = separators.iterator();
399 while (sepIt.hasNext()) {
400 Integer s = sepIt.next();
401 if (s < curOffset && leftSep < s) {
404 if (s > curOffset && s < rightSep) {
410 Iterator<Suggestion> allSuggIt = allSugg.iterator();
411 while (allSuggIt.hasNext()) {
415 frags = sugToLinFragments.get(actualSugg.getId());
416 if (frags != null && !frags.isEmpty()) {
422 curOffset = frag.getOffset();
428 Integer actualSuggId = actualSugg.getId();
429 AnnotType actualSuggType = actualSugg.getAnnotType();
430 String actualURI = actualSugg.getSAEntityIdentifier();
431 if (actualSuggId != null && confirmedSuggestionId != null && !actualSuggId.equals(confirmedSuggestionId)
432 && actualSuggType != null && confirmedSuggType != null && actualSuggType.equals(confirmedSuggType)
433 && actualURI != null && confirmedURI.equals(actualURI)) {
435 ArrayList<SuggestionFragment> tmpFragList = actualSugg.getFragmentsAL();
436 if (tmpFragList.size() >= 2) {
440 if (tmpFragList.size() == suggFragList.size()) {
441 Iterator<SuggestionFragment> tmpFragListIt = tmpFragList.iterator();
442 Iterator<SuggestionFragment> suggFragListIt = suggFragList.iterator();
443 Boolean errFlag =
false;
445 while (tmpFragListIt.hasNext()) {
454 String path1 = tmpFrag1.getPath();
455 String path2 = tmpFrag2.getPath();
456 if (path1 != null && path2 != null && path1.equals(path2)) {
457 Integer offset1 = tmpFrag1.getOffset();
458 Integer offset2 = tmpFrag2.getOffset();
459 if (offset1 != null && offset2 != null && offset1.equals(offset2)) {
465 if (curOffset != null) {
466 if (curOffset < leftSep || curOffset > rightSep) {
476 sendedSug.setTmpId(tmpLogEntry.getTmpId());
477 sendedSug.updateWithSuggestion(actualSugg);
478 sendedSug.setUser(requestInfo.getSession().getUser());
479 sendedSug.setAuthorIdStr(requestInfo.getSession().getUser().getURIV2());
480 sendedSug.setAuthorAddress(requestInfo.getSession().getUser().getEmail());
481 sendedSug.setAuthorName(requestInfo.getSession().getUser().getName());
482 sendedSug.setCreated(
new Date());
483 tmpLogEntry.setConfirmedVersion(sendedSug);
485 addToLog.add(tmpLogEntry);
486 requestInfo.getFlier().AddAddedAnnotation(sendedSug);
487 requestInfo.addAutoconfirmedSuggestion(tmpLogEntry);
497 suggLog.addAll(addToLog);
509 Object[] params = {
"id",
id};
510 @SuppressWarnings(
"unchecked")
511 List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB(
"Suggestion.findById",params);
512 if(suggestionList != null && !suggestionList.isEmpty()){
513 return suggestionList.get(0);
548 ArrayList<Integer> result =
new ArrayList<Integer>();
549 Iterator<String> sepIt = Constants.REFUSE_BORDER_SEPARATOR.iterator();
550 while (sepIt.hasNext()) {
551 String sep = sepIt.next();
552 int offset = doc.indexOf(sep);
553 while (offset >= 0) {
555 offset = doc.indexOf(sep, offset + 1);
558 Collections.sort(result);
572 Iterator<SugBaseAttribute> sAttIt = sug.getAttributes().iterator();
573 while (sAttIt.hasNext()) {
578 if (at.
getSimpleType() != null && (at.getSimpleType().equalsIgnoreCase(
"linkedSuggestion")
579 || at.getSimpleType().equalsIgnoreCase(
"nestedSuggestion")
580 || at.getSimpleType().equalsIgnoreCase(
"linkedAnnotation")
581 || at.getSimpleType().equalsIgnoreCase(
"nestedAnnotation"))) {
600 if (requestInfo.
getSession().getDefaultGroup() == null) {
601 int lod = requestInfo.getSession().getProtocolLOD();
604 String msg =
"User is not in any group.";
605 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.SEVERE, msg);
612 ArrayList<Suggestion> allSuggest = SuggestionManager.getSuggestionsFromDB(requestInfo.getSession().getSyncDocument().getId());
613 if (allSuggest == null || allSuggest.isEmpty()) {
615 int langNum = requestInfo.getSession().getLanguageNum();
616 int lod = requestInfo.getSession().getProtocolLOD();
619 String msg =
"Suggestions are not ready (it is necessary to try it later).";
620 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
624 ArrayList<Suggestion> filteredSuggest =
new ArrayList<Suggestion>(allSuggest);
625 SuggestionManager.filtrateSuggestions(requestInfo, session, filteredSuggest);
626 ArrayList<Suggestion> shouldHave = SuggestionManager.addAllDependencies(filteredSuggest, allSuggest);
627 ArrayList<Suggestion> updatedSuggs =
new ArrayList<Suggestion>();
629 ArrayList<Suggestion> rSug = SuggestionManager.getNestedSuggFromToDelete(shouldHave, removedSug);
631 ArrayList<AnnotType> newTypes =
new ArrayList<AnnotType>();
632 SuggestionManager.checkTypes(session, shouldHave, newTypes,
true);
633 SuggestionManager.persistTypes(newTypes);
635 String msgTypes = SuggestionManager.printTypes(requestInfo, session, newTypes);
637 SuggestionManager.sendToOthers(requestInfo, msgTypes);
643 ArrayList<Suggestion> allConfSugs =
new ArrayList<Suggestion>();
645 Iterator<Suggestion> shouldHaveIt = shouldHave.iterator();
646 while (shouldHaveIt.hasNext()) {
654 allConfSugs.add(sug);
658 allConfSugs = SuggestionManager.addAllDependencies(allConfSugs, shouldHave);
660 HashMap<String,Annotation> confirmedSuggestions =
new HashMap<String,Annotation>();
661 ArrayList<Annotation> annotList =
new ArrayList<Annotation>();
663 Iterator<Suggestion> confSugIt = allConfSugs.iterator();
664 while (confSugIt.hasNext()) {
666 Integer
id = sended.getId();
667 String idString = id.toString();
673 sendedSug.setTmpId(logEntry.getTmpId());
674 sendedSug.updateWithSuggestion(sended);
675 sendedSug.setUser(requestInfo.getSession().getUser());
676 sendedSug.setAuthorIdStr(requestInfo.getSession().getUser().getURIV2());
677 sendedSug.setAuthorAddress(requestInfo.getSession().getUser().getEmail());
678 sendedSug.setAuthorName(requestInfo.getSession().getUser().getName());
679 sendedSug.setCreated(
new Date());
681 confirmedSuggestions.put(sended.getURIV2(), sendedSug);
682 annotList.add(sendedSug);
683 if (logEntry.getConfirmedVersion() == null) {
684 logEntry.setConfirmedVersion(sendedSug);
685 requestInfo.getFlier().AddAddedAnnotation(sendedSug);
687 if (requestInfo.getSession().getKBRefMode()) {
689 sendedSug.getAttributes().add(uAAt);
691 logEntry.setSuggestion(sendedSug);
693 if (!requestInfo.getConfirmedSuggestions().contains(logEntry)) {
694 requestInfo.addConfirmedSuggestion(logEntry);
695 requestInfo.addAutoconfirmedSuggestion(logEntry);
714 Iterator<Annotation> connectIt = annotsToConnect.iterator();
715 while (connectIt.hasNext()) {
722 Iterator<BaseAttribute> attributesIt = actualAnnot.getAttributes().iterator();
723 while (attributesIt.hasNext()) {
728 if (actualAttribute.
getUri() != null && !actualAttribute.getUri().isEmpty()) {
731 String annotUri = actualAttribute.getUri();
734 if (uriType.equals(
"sugg")) {
735 Annotation findedAnnot = tmpIdMap.get(actualAttribute.getUri());
736 if (findedAnnot != null) {
737 ((LinkedAnnotationAttribute) actualAttribute).setValue(findedAnnot);
739 }
else if (uriType.equals(
"serv")) {
741 String idString = annotUri.replace(AppBean.getBaseUri() +
"/serv/",
"");
743 id = Integer.decode(idString);
744 }
catch (NumberFormatException ex) {
746 int langNum = requestInfo.getSession().getLanguageNum();
747 int lod = requestInfo.getSession().getProtocolLOD();
748 String info =
"<attribute annotationUri=\"" + actualAnnot.getURIV2()
750 +
"\" name=\"" + actualAttribute.getName()
752 +
"\" type=\"" + actualAttribute.getTypeUriV2() +
"\"/>";
755 String msg =
"Can't decode suggestion id. Id value: " + idString;
756 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
761 PersistM persistMan = AppBean.getPersistenceManager();
763 Object[] annotParams =
new Object[2];
764 annotParams[0] =
"id";
767 @SuppressWarnings(
"unchecked")
768 List<Annotation> annotList = persistMan.queryDB(
"Annotation.findById", annotParams);
769 if (annotList == null || annotList.isEmpty()) {
771 int langNum = requestInfo.getSession().getLanguageNum();
772 int lod = requestInfo.getSession().getProtocolLOD();
773 String info =
"<attribute annotationUri=\"" + actualAnnot.getURIV2()
775 +
"\" name=\"" + actualAttribute.getName()
777 +
"\" type=\"" + actualAttribute.getTypeUriV2() +
"\"/>";
780 String msg =
"Can't find linked annot in DB. Id value: " + idString;
781 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
786 LinkedAnnotationAttribute actualLinked = (LinkedAnnotationAttribute) actualAttribute;
787 actualLinked.setValue(annotList.get(0));
788 actualLinked.setAttributeType(annotList.get(0).getAnnotType());
795 NestedAnnotationAttribute nestedAttr = (NestedAnnotationAttribute) actualAttribute;
796 if (actualAttribute.
getUri() != null && !actualAttribute.getUri().isEmpty()) {
798 Annotation findedAnnot = tmpIdMap.get(actualAttribute.getUri());
799 nestedAttr.setValue(findedAnnot);
800 findedAnnot.setNestedInAnnot(nestedAttr.getRefAnnotation());
816 NodeList refusedElems = suggRefuseEl.getElementsByTagName(
"suggestion");
818 for(
int index = 0; index < refusedElems.getLength(); index ++){
819 Element suggEl = (Element) refusedElems.item(index);
821 String suggUri = suggEl.getAttribute(
"uri");
822 if(suggUri == null && suggUri.isEmpty()){
824 int langNum = requestInfo.getSession().getLanguageNum();
825 int lod = requestInfo.getSession().getProtocolLOD();
826 String info =
"<suggestion uri=\"\"/>";
829 String msg =
"Can't find uri of refused annotation suggestion.";
830 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
835 String idString = suggUri.replace(AppBean.getBaseUri() +
"/sugg/",
"");
840 if (requestInfo.
getSession().getSendedSuggestions() != null && !requestInfo.
getSession().getSendedSuggestions().isEmpty()) {
843 id = Integer.parseInt(idString);
844 }
catch (NumberFormatException nfe) {
846 String msg =
"The ID of the refused suggestion is not a number: " + idString;
847 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
851 if (
id != null && requestInfo.
getSession().isSuggInSendedSuggestions(id)) {
853 refused.updateWithSuggestion(requestInfo.getSession().getWholeSendedSuggestion(
id));
854 logEntry.setSuggestion(refused);
858 String msg =
"Suggestion with the following ID not found: " + idString;
859 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
864 requestInfo.addRefusedSuggestion(logEntry);
879 NodeList getAltElems = getAltEl.getElementsByTagName(
"suggestion");
881 for(
int index = 0; index < getAltElems.getLength(); index ++){
882 Element suggEl = (Element) getAltElems.item(index);
884 String suggUri = suggEl.getAttribute(
"uri");
885 if(suggUri == null && suggUri.isEmpty()){
887 int langNum = requestInfo.getSession().getLanguageNum();
888 int lod = requestInfo.getSession().getProtocolLOD();
892 String msg =
"Can't find uri of suggestion.";
893 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
898 String idString = suggUri.replace(AppBean.getBaseUri() +
"/sugg/",
"");
901 if (requestInfo.
getSession().getSendedSuggestions() != null && !requestInfo.
getSession().getSendedSuggestions().isEmpty()) {
904 id = Integer.parseInt(idString);
905 }
catch (NumberFormatException nfe) {
907 String msg =
"The ID of the suggestion is not a number: " + idString;
908 Logger.getLogger(P2SuggestionProcessor.class.getName()).log(Level.ALL, msg);
912 if (
id != null && requestInfo.
getSession().isSuggInSendedSuggestions(id)) {
913 requestInfo.addSugToAlternativesRequestedFor(requestInfo.getSession().getWholeSendedSuggestion(
id));
917 String msg =
"Suggestion with the following ID was not found: " + idString;
918 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
935 NodeList fragmentElems = fragmentsEl.getElementsByTagName(
"fragment");
936 ArrayList<Fragment> resultsFragments =
new ArrayList<Fragment>(fragmentElems.getLength());
939 for(
int index = 0; index < fragmentElems.getLength(); index++){
940 Element currentFragmentsEl = (Element) fragmentElems.item(0);
941 if(currentFragmentsEl != null){
945 String xPathString = currentFragmentsEl.getAttribute(
"path");
946 if(xPathString == null || xPathString.isEmpty()){
948 int langNum = requestInfo.getSession().getLanguageNum();
949 int lod = requestInfo.getSession().getProtocolLOD();
952 String msg =
"XPath attribute is required in suggestion request fragment element.";
953 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
959 String attributeString = currentFragmentsEl.getAttribute(
"offset");
960 if (attributeString == null || attributeString.isEmpty()) {
964 offset = Integer.parseInt(attributeString);
965 }
catch (NumberFormatException ex) {
967 int langNum = requestInfo.getSession().getLanguageNum();
968 int lod = requestInfo.getSession().getProtocolLOD();
971 String msg =
"Can't decode fragment offset. Value of offset: " + attributeString;
972 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
979 String lengthString = currentFragmentsEl.getAttribute(
"length");
980 if(lengthString == null || lengthString.isEmpty()){
984 length = Integer.parseInt(lengthString);
985 }
catch (NumberFormatException ex) {
987 int langNum = requestInfo.getSession().getLanguageNum();
988 int lod = requestInfo.getSession().getProtocolLOD();
991 String msg =
"Can't decode fragment length. Value of length: " + lengthString;
992 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
999 String sPath = UpdatableFragment.improveXPath(xPathString);
1001 newFragment =
new Fragment(sPath, offset, length);
1003 resultsFragments.add(newFragment);
1006 return resultsFragments;
1018 NodeList annotTypeElems = typesEl.getElementsByTagName(
"type");
1019 ArrayList<String> resultsAnnotType =
new ArrayList<String>(annotTypeElems.getLength());
1022 for (
int index = 0; index < annotTypeElems.getLength(); index++) {
1023 Element currentAnnotTypesEl = (Element) annotTypeElems.item(0);
1024 if (currentAnnotTypesEl != null) {
1026 String typeUriString = currentAnnotTypesEl.getAttribute(
"uri");
1027 if (typeUriString == null || typeUriString.isEmpty()) {
1029 int langNum = requestInfo.getSession().getLanguageNum();
1030 int lod = requestInfo.getSession().getProtocolLOD();
1031 String info =
"<type uri=\"\"/>";
1034 String msg =
"Annotation type uri is required.";
1035 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1041 PersistM persistMan = AppBean.getPersistenceManager();
1043 Object[] params =
new Object[2];
1045 params[1] = typeUriString;
1047 @SuppressWarnings(
"unchecked")
1048 List<AnnotType> annotTypeList = persistMan.queryDB(
"AnnotType.findByUri", params);
1049 if(annotTypeList != null && !annotTypeList.isEmpty()){
1050 resultsAnnotType.add(typeUriString);
1053 int langNum = requestInfo.getSession().getLanguageNum();
1054 int lod = requestInfo.getSession().getProtocolLOD();
1055 String info =
"<type uri=\"" + typeUriString +
"\"/>";
1058 String msg =
"Can't find annotation type of suggestion request. Type uri: " + typeUriString;
1059 Logger.getLogger(MessageProcessor.class.getName()).log(Level.ALL, msg);
1066 return resultsAnnotType;
1080 ArrayList<Suggestion> removedSuggestions =
new ArrayList<Suggestion>();
1081 UserGroup defGroup = requestInfo.getSession().getDefaultGroup();
1082 int defaultUserGroupID = defGroup.getId();
1084 List<SuggestionFeedback> feedList = SuggestionManager.getFeedbackFromDB(requestInfo.getSession().getSyncDocument().getId(), defaultUserGroupID);
1085 ArrayList<SuggestionFeedback> feedListOtherGroups =
new ArrayList<SuggestionFeedback>();
1087 if (requestInfo.
getSession().getUser() != null) {
1088 Iterator<UserGroup> allUserGroups = requestInfo.getSession().getUser().getGroupsAL().iterator();
1089 while(allUserGroups.hasNext()){
1091 if(group.
getId() != defaultUserGroupID){
1092 List<SuggestionFeedback> feed = SuggestionManager.getFeedbackFromDB(requestInfo.getSession().getSyncDocument().getId(), group.
getId());
1093 feedListOtherGroups.addAll(feed);
1099 for (Iterator<SuggestionFeedback> it = feedList.iterator(); it.hasNext();) {
1104 Suggestion sgFromList = SuggestionManager.getSuggestionFromList(fb.getSuggestion().getId(), list);
1105 if (sgFromList != null) {
1111 for (Iterator<SuggestionFeedback> it = feedListOtherGroups.iterator(); it.hasNext();) {
1116 Suggestion sgFromList = SuggestionManager.getSuggestionFromList(fb.getSuggestion().getId(), list);
1117 if (sgFromList != null) {
1122 return removedSuggestions;
1136 ArrayList<Suggestion> removedSuggestions)
1138 for (Iterator<Suggestion> itList = list.iterator(); itList.hasNext(); ) {
1140 List atrs = sg.getAttributes();
1142 for (Iterator it2 = atrs.iterator(); it2.hasNext();) {
1143 Object obj = (Object) it2.next();
1144 Object value = null;
1146 value = ((SugLinkedAttribute) obj).getValue();
1149 value = ((SugNestedAttribute) obj).getValue();
1152 if (((Suggestion) value).equals(sgFromList)) {
1153 if (obj instanceof SugLinkedAttribute) {
1154 ((SugLinkedAttribute) obj).setValue(fb.getAnnot());
1156 ((SugLinkedAttribute) obj).setUri(fb.getAnnot().getURIV2());
1158 ((SugLinkedAttribute) obj).setUri(null);
1160 if (modified != null && !modified.contains(sg)) {
1164 if (obj instanceof SugNestedAttribute) {
1165 ((SugNestedAttribute) obj).setValue(fb.getAnnot());
1167 ((SugNestedAttribute) obj).setUri(fb.getAnnot().getURIV2());
1169 ((SugNestedAttribute) obj).setUri(null);
1171 if (modified != null && !modified.contains(sg)) {
1179 list.remove(sgFromList);
1180 removedSuggestions.add(sgFromList);
1190 private ArrayList<Suggestion>
cutRefusedSuggLinks(ArrayList<Suggestion> userSuggestions, ArrayList<Suggestion> refusedSuggestions){
1191 ArrayList<Suggestion> changedSuggestions =
new ArrayList<Suggestion>();
1192 if(userSuggestions != null && !userSuggestions.isEmpty() && refusedSuggestions != null && !refusedSuggestions.isEmpty()){
1193 Iterator<Suggestion> userSuggIt = userSuggestions.iterator();
1194 while(userSuggIt.hasNext()){
1196 List attrList = actualSugg.getAttributes();
1197 Iterator attrListIt = attrList.iterator();
1199 while(attrListIt.hasNext()){
1200 Object actualObject = (Object) attrListIt.next();
1203 SugLinkedAttribute actualLink = (SugLinkedAttribute)actualObject;
1205 Iterator<Suggestion> refSugIterator = refusedSuggestions.iterator();
1206 while(refSugIterator.hasNext()){
1208 if(((Suggestion)actualLink.
getValue()).getId().equals(refSugIterator.next().getId())){
1210 actualLink.setValue(null);
1211 actualLink.setUri(null);
1212 if(!changedSuggestions.contains(actualSugg)){
1213 changedSuggestions.add(actualSugg);
1220 SugNestedAttribute actualLink = (SugNestedAttribute)actualObject;
1222 Iterator<Suggestion> refSugIterator = refusedSuggestions.iterator();
1223 while(refSugIterator.hasNext()){
1225 if(((Suggestion)actualLink.
getValue()).getId().equals(refSugIterator.next().getId())){
1227 actualLink.setValue(null);
1228 actualLink.setUri(null);
1229 if(!changedSuggestions.contains(actualSugg)){
1230 changedSuggestions.add(actualSugg);
1239 return changedSuggestions;
static final int ERROR_40_BAD_SUGG_TYPE
ArrayList< Fragment > processSuggFragments(Element fragmentsEl, RequestInfo requestInfo)
static final int LOG_LEVEL_ALL_ERRORS
Attribute manager provides a way how to create new attributes for prupose of suggestion.
Persistence manager (database manipulator)
static final int CONFIRMED_MANUALLY_EDITED
Suggestion getSuggestion()
Class representing attribute of type NestedAnnotation for peupose of suggestion.
Class representing attribute of type NestedAnnotation.
void feedbackChangeRef(ArrayList< Suggestion > list, Suggestion sgFromList, ArrayList< Suggestion > modified, SuggestionFeedback fb, ArrayList< Suggestion > removedSuggestions)
Class which implements Comparator to sort arrayList of SuggestionFragment alphabetically.
Singleton for storing global variables.
static final int REFUSED_MANUALLY
Class representing attribute of type AnnotationLink.
boolean haveNestedOrLinked(Suggestion sug)
static final int CONFIRMED_MANUALLY
static final int ERROR_97_NOT_IN_GROUP
Class representing attribute of suggestion.
Class representing suggested annotation fragment.
ArrayList< Suggestion > getSuggestionWithoutFeedback(RequestInfo requestInfo, ArrayList< Suggestion > list, ArrayList< Suggestion > modified)
ArrayList< SuggestionLogEntry > updatePositiveFeedback(RequestInfo requestInfo)
void processSuggestionRefuse(Element suggRefuseEl, RequestInfo requestInfo)
static final int ERROR_107_BAD_AUTOCONFIRM
Abstract class provides a parser for the annotation of protocol version 2.
Suggested annotation with informations about suggestion.
Static class which parses and process XML with messages.
Class representing user group.
String getUriInOntology()
static final String UPDATABLE_AN_AT_NAME
Annotation processAnnotation(Element annotationEl, RequestInfo requestInfo)
Methods for translating output from SEC API to the Suggestion objects.
void connectAnnotations(ArrayList< Annotation > annotsToConnect, HashMap< String, Annotation > tmpIdMap, RequestInfo requestInfo)
void processSuggestionAutoConfirm(Integer minConfidence, RequestInfo requestInfo)
int compare(SuggestionFragment frag1, SuggestionFragment frag2)
Class provides offerining of suggestions with usage of local knowledge repository.
String getAnnotatedText()
Class which process messages related to suggestions in protocol v 2.0.
static final int ERROR_95_MISSING_CONFIDENCE
void processGetAlternatives(Element getAltEl, RequestInfo requestInfo)
Base class representing attribute of annotation.
Class for XML document fragment.
static final int LOG_LEVEL
Class representing type of annotation.
static final int ERROR_103_MISSING_MODIFIED_SUG
Class representing attribute of type Boolean.
EditorSession getSession()
static final int LOG_LEVEL_ALL
Class representing attribute of type AnnotationLink for prupose of suggestion.
void processSuggestionQuery(Element suggQueryEl, RequestInfo requestInfo)
List< SugBaseAttribute > getAttributes()
static final int ERROR_8_SUG_FRAGMENT
ArrayList< SuggestionLogEntry > getConfirmedSuggestions()
Processed informations about client request.
Class representing suggestion of annotation.
static final int ERROR_101_SUGGESTIONR_NOT_READY
static final int ERROR_7_ATTRIBUTE_VALUE
Class responsible for localised strings.
static final int CONFIRMED_AUTOMATICALLY
Informations about client session.
Represents database entitiy with suggestion feedback. feedback.
ArrayList< String > processSuggTypes(Element typesEl, RequestInfo requestInfo)
ArrayList< SuggestionLogEntry > getRefusedSuggestions()
static Suggestion getSuggestionFromDB(Integer id)
ArrayList< Suggestion > cutRefusedSuggLinks(ArrayList< Suggestion > userSuggestions, ArrayList< Suggestion > refusedSuggestions)
Class representing annotated fragment.
List< BaseAttribute > getAttributes()
Class representing annotation.
void processSuggestionConfirm(Element suggConfirmEl, RequestInfo requestInfo)
static final int ERROR_28_BAD_CONFIRM
static String getUriType(String uri)
static ArrayList< Integer > findSeparators(String doc)