4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
EditorSession.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: EditorSession.java
5  * Description: Class with informations about client (annotations editor) session
6  */
7 
8 /**
9  * @file EditorSession.java
10  *
11  * @brief Informations about client session
12  */
13 
14 package cz.vutbr.fit.knot.annotations.comet;
15 
16 import com.sun.grizzly.comet.CometContext;
17 import com.sun.grizzly.comet.CometEngine;
23 import cz.vutbr.fit.knot.annotations.entity.*;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.ListIterator;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32 import javax.persistence.Query;
33 import org.w3c.dom.Document;
34 
35 /**
36  * Class with informations about client (annotations editor) session
37  *
38  * @brief Informations about client session
39  * @author idytrych
40  */
41 public class EditorSession {
42 
43  /** Id of session*/
44  private long sessionId;
45  /** User logged in this session */
46  private User user = null;
47  /** Communication protocol version */
48  private String protocolVersion;
49  /** List of subscribed sources */
50  private ArrayList<SubscribedSource> subscribedSources;
51  /** List of unsubscribed sources (Black List) */
52  private ArrayList<SubscribedSource> unsubscribedSources;
53  /** Fragments to which are to be suggested annotations */
54  private ArrayList<Fragment> suggestionsFr;
55  /** Annotation types to be suggested (list with filters) */
56  private ArrayList<String> suggestionsTypes;
57  /** List of queried annotation types */
58  private ArrayList<String> queriedTypes;
59  /** Synchronized document */
60  private AnnotDocument syncDocument = null;
61  /** Linearized synchronized document */
62  private String parsedLinDocument = null;
63  /** Indicator of linearization */
64  private boolean linearization = false;
65  /** Language to use in server */
66  private String language = "eng";
67  /** Number of language to use in server */
69  /** List with attributes which should be filtered out */
70  private ArrayList<String> attFilter;
71  /**
72  * Should be negative feedback updated for suggestions refused by same
73  * fragment as some confirmed have? If it will be updated and we have
74  * two suggestions on same fragment and same two suggestions on more
75  * same fragments, confirmation on one of them refuses second one from
76  * all other fragments.
77  */
78  private boolean updateNegFeedbackForRefusedBySame = false;
79  /**
80  * Should be other similar (same annotated text and URI of entity)
81  * suggestions in same part of document confirmed?
82  */
83  private boolean enableUpdatePositiveFeedback = false;
84  /**
85  * Should be alternatives automatically activated?
86  */
87  private boolean autoActivateAlternatives = false;
88  /** String with messages to be sent via comet */
89  private String messagesTSVC = "";
90  /** Cache for annotation suggestions */
91  private ArrayList<SuggestionLogEntry> suggestionsCache;
92  /** Time stamp that indicate last activity time of session */
93  private long lastActivityTime;
94  /** Time stamp that indicate last confirm time of session */
95  private long lastConfirmTime;
96  /** Array of IDs of suggestions which was sent to client (client's cache) */
97  private volatile ArrayList<Integer> sendedSuggestions;
98  /** Comet handler associated with this session */
99  private AnnotCometServlet.AnnotHandler cometHandler = null;
100  /** Comet context associated with this session */
101  private String cometContext = null;
102  /** List of subscribed subscriptions */
103  private ArrayList<Subscription> subscribeList = null;
104  /** Parsed synchronized document */
105  private Document parsedSyncDocument = null;
106  /** Flag which denotes that suggestions was requested so an empty diff cannot be omitted. */
107  private Boolean sugRequestFlag = false;
108  /** Should be confidence displayed for suggestions */
109  private boolean displaySugConfidence = true;
110  /** Is KB_Ref mode on? */
111  private boolean KBRefMode = false;
112 
113  /** Minimal confidence used to filtrate suggestions */
114  private Integer minConfidence;
115  /** Minimal level of confidence to auto confirm suggestion */
116  private Integer autoConfirm;
117  /** Are variables dependent on document ID initialized? */
118  private Boolean docIDdependentVariablesInitialized = false;
119 
120  /**
121  * Constructor of reference objects for searching purposes - no initialization
122  * needed
123  */
124  public EditorSession(long sessId) {
125  sessionId = sessId;
126  }
127 
128  /**
129  * Constructor - sets the session id to new generated value and initialize
130  * variables
131  */
133  sessionId = AppBean.getNextSessId();
134  this.protocolVersion = protocolVersion;
135  subscribedSources = new ArrayList<SubscribedSource>();
136  unsubscribedSources = new ArrayList<SubscribedSource>();
137  queriedTypes = new ArrayList<String>();
138  this.suggestionsFr = new ArrayList<Fragment>();
139  suggestionsCache = new ArrayList<SuggestionLogEntry>();
140  sendedSuggestions = new ArrayList<Integer>();
141  suggestionsTypes = new ArrayList<String>();
142  attFilter = new ArrayList<String>();
143  }
144 
145  /**
146  * Gets id of this session
147  *
148  * @return Returns id of this session
149  */
150  public long getSessionId() {
151  return sessionId;
152  }
153 
154  /**
155  * Gets agreed communication protocol version
156  *
157  * @return Returns communication protocol version
158  */
159  public String getProtocolVersion() {
160  return protocolVersion;
161  }
162 
163  /**
164  * Sets agreed communication protocol version
165  *
166  * @param protocolVersion Communication protocol version
167  */
168  public void setProtocolVersion(String protocolVersion) {
169  this.protocolVersion = protocolVersion;
170  }
171 
172  /**
173  * Gets protocol level of development. Higher level activates newer functions.
174  *
175  * @return Protocol level of development (1 for protocol v. 1.0)
176  */
177  public int getProtocolLOD() {
178  if (protocolVersion.equals("1.0")){
180  }
181  if (protocolVersion.equals("2.0")){
183  }
184 
185  if (protocolVersion.charAt(0) == '2'){
187  }
188  else{
190  }
191  }
192 
193  /**
194  * Gets appropriate version of namespaces based on protocol LOD
195  *
196  * @return Appropriate version of namespaces based on protocol LOD
197  */
198  public int getNamespacesLOD(){
199  int protocolVer = this.getProtocolLOD();
200 
201  if(protocolVer < Constants.PROTOCOL_LOD_V2){
203  }
204  else{
206  }
207  }
208 
209  /**
210  * Gets list of fragments to which are to be suggested annotations
211  *
212  * @return Returns list of fragments to which are to be suggested annotations
213  */
214  public ArrayList<Fragment> getSuggestionsFr() {
215  return suggestionsFr;
216  }
217 
218  /**
219  * Sets list of fragments to which are to be suggested annotations
220  *
221  * @param suggestionsFr List of fragments to which are to be suggested annotations
222  */
223  public void setSuggestionsFr(ArrayList<Fragment> suggestionsFr) {
224  this.suggestionsFr = suggestionsFr;
225  }
226 
227  /**
228  * Adds fragment to which are to be suggested annotations to the list
229  *
230  * @param suggestionsFr Fragment to which are to be suggested annotations
231  */
233  this.suggestionsFr.add(suggestionsFr);
234  }
235 
236  /**
237  * Adds source of annotations to list of subscribed sources
238  *
239  * @param source Source of annotations to be added
240  */
241  public void addSource(SubscribedSource source) {
242  subscribedSources.add(source);
243  }
244 
245  /**
246  * Removes source of annotations from list of subscribed sources
247  *
248  * @param source Source of annotations to be removed
249  */
250  public void removeSource(SubscribedSource source) {
251  subscribedSources.remove(source);
252  }
253 
254  /**
255  * Check whether source of annotations is in the list of subscribed sources
256  *
257  * @param source Source of annotations to be searched
258  * @return If source is in the list, returns true, false otherwise
259  */
260  public boolean containsSource(SubscribedSource source) {
261  return subscribedSources.contains(source);
262  }
263 
264  /**
265  * Adds unsubscribed source of annotation to list of unsubscribed sources (black list)
266  *
267  * @param source Unsubscribed source of annotations to be added
268  */
270  unsubscribedSources.add(source);
271  }
272 
273  /**
274  * Removes unsubscribed source of annotation from list of unsubscribed sources (black list)
275  *
276  * @param source Unsubscribed source of annotations to be removed
277  */
279  unsubscribedSources.remove(source);
280  }
281  /**
282  * Check whether source of annotations is in the list of unsubscribed sources
283  *
284  * @param source Source of annotations to be searched in the list of unsubscribed
285  * @return If source is found, returns true, otherwise return false
286  */
288  return unsubscribedSources.contains(source);
289  }
290 
291  /**
292  * Gets queried types of annotations (list of strings with filters which was used)
293  *
294  * @return Returns queried types of annotations (list of strings with filters which was used)
295  */
296  public ArrayList<String> getQueriedTypes() {
297  return queriedTypes;
298  }
299 
300  /**
301  * Sets queried types of annotations (list of strings with filters which was used)
302  *
303  * @param queriedTypes Queried types of annotations (list of strings with filters which was used)
304  */
305  public void setQueriedTypes(ArrayList<String> queriedTypes) {
306  this.queriedTypes = queriedTypes;
307  }
308 
309  /**
310  * Adds queried type(s) of annotations to the list (string with filter)
311  *
312  * @param queriedType Queried type(s) of annotations to the list (string with filter)
313  */
314  public void addQueriedTypes(String queriedType) {
315  this.queriedTypes.add(queriedType);
316  }
317 
318  /**
319  * Gets time stamp of activity time of session
320  *
321  * @return Returns time stamp of activity time of session
322  */
323  public long getLastActivityTime() {
324  return lastActivityTime;
325  }
326 
327  /**
328  * Sets time stamp of activity time of session
329  *
330  * @param lastActivityTime time stamp of activity time of session
331  */
333  this.lastActivityTime = lastActivityTime;
334  }
335 
336  /**
337  * Gets time stamp of confirm time of session
338  *
339  * @return Returns time stamp of confirm time of session
340  */
341  public long getLastConfirmTime() {
342  return lastConfirmTime;
343  }
344 
345  /**
346  * Sets time stamp of confirm time of session
347  *
348  * @param lastConfirmTime Time stamp of confirm time of session
349  */
351  this.lastConfirmTime = lastConfirmTime;
352  }
353 
354  /**
355  * Checks whether editor connected to this session is subscribed to get given
356  * annotation.
357  *
358  * @param annot Checked annotation
359  * @param testDoc If matching of document must be checked then true, false otherwise
360  * @return If annotation matches to subscriptions, returns true, false otherwise
361  */
362  public boolean isSubscribed(Annotation annot, boolean testDoc) {
363  return isSubscribed(annot, null, true);
364  }
365 
366  /**
367  * Checks whether editor connected to this session is subscribed to get given
368  * annotation.
369  *
370  * @param annot Checked annotation
371  * @param sources List of sources to which annotation belongs to
372  * @param testDoc If matching of document must be checked then true, false otherwise
373  * @return If annotation matches to subscriptions, returns true, false otherwise
374  */
375  public boolean isSubscribed(Annotation annot, ArrayList<String> sources, boolean testDoc) {
376  if (testDoc) {
377  if (syncDocument == null) {
378  return false;
379  }
380  if (!syncDocument.equals(annot.getSourceDocument())) {
381  return false;
382  }
383  }
384  return isSubscribed(annot, sources);
385  }
386 
387  /**
388  * Checks whether editor connected to this session is subscribed to get given
389  * annotation. User groups of annotation author are taken into account.
390  *
391  * @param annot Checked annotation
392  * @param testDoc If matching of document must be checked then true, false otherwise
393  * @return If annotation matches to subscriptions, returns true, false otherwise
394  */
395  public boolean isSubscribedWG(Annotation annot, boolean testDoc) {
396  ArrayList<String> sources = new ArrayList<String>();
397  return isSubscribedWG(annot, sources, true);
398  }
399 
400  /**
401  * Checks whether editor connected to this session is subscribed to get given
402  * annotation. User groups of annotation author are taken into account.
403  *
404  * @param annot Checked annotation
405  * @param sources List of sources to which annotation belongs to
406  * @param testDoc If matching of document must be checked then true, false otherwise
407  * @return If annotation matches to subscriptions, returns true, false otherwise
408  */
409  public boolean isSubscribedWG(Annotation annot, ArrayList<String> sources, boolean testDoc) {
410  if (testDoc) {
411  if (syncDocument == null) {
412  return false;
413  }
414  if (!syncDocument.equals(annot.getSourceDocument())) {
415  return false;
416  }
417  }
418  return isSubscribedWG(annot, sources);
419  }
420 
421  /**
422  * Checks whether editor connected to this session is subscribed to get given
423  * annotation.
424  *
425  * @param annot Checked annotation
426  * @return If annotation matches to subscriptions, returns true, false otherwise
427  */
428  public boolean isSubscribed(Annotation annot) {
429  return isSubscribed(annot, null);
430  }
431 
432  /**
433  * Checks whether editor connected to this session is subscribed to get given
434  * annotation. User groups of annotation author are taken into account.
435  *
436  * @param annot Checked annotation
437  * @return If annotation matches to subscriptions, returns true, false otherwise
438  */
439  public boolean isSubscribedWG(Annotation annot) {
440  ArrayList<String> sources = new ArrayList<String>();
441  return isSubscribedWG(annot, sources);
442  }
443 
444  /**
445  * Checks whether editor connected to this session is subscribed to get given
446  * annotation. User groups of annotation author are taken into account.
447  *
448  * @param annot Checked annotation
449  * @param sources List of sources to which annotation belongs to
450  * @return If annotation matches to subscriptions, returns true, false otherwise
451  */
452  public boolean isSubscribedWG(Annotation annot, ArrayList<String> sources) {
453  if (annot.getUser() != null) {
454  Iterator<UserGroup> gIter = annot.getUser().getGroups().iterator();
455  while (gIter.hasNext()) {
456  UserGroup userGroup = gIter.next();
457  sources.add(AppBean.getBaseGroupUri() + userGroup.getId());
458  }
459  }
460  return isSubscribed(annot, sources);
461  }
462 
463  /**
464  * Method sets comet context for this session.
465  *
466  * @param cometContext string with comet context
467  */
468  public void setCometContext(String cometContext) {
469  this.cometContext = cometContext;
470  }
471 
472  /**
473  * Method sets handler to comet that belongs to session.
474  *
475  * @param cometHandler comet handler for this session
476  */
478  this.cometHandler = cometHandler;
479  }
480 
481  /**
482  * Method gets comet context for this session.
483  *
484  * @return Returns comet context for this session.
485  */
486  public String getCometContext() {
487  return this.cometContext;
488  }
489 
490  /**
491  * Method gets handler to comet that belongs to session.
492  *
493  * @return Returns comet handler for this session
494  */
496  return this.cometHandler;
497  }
498 
499  /**
500  * Method provides asynchronous sending messages trough comet channel. Basically
501  * send notify to comet engine and that wake comet for this session.
502  */
503  public void notifyComet(){
504  if(cometHandler != null && cometContext != null){
505  CometEngine engine = CometEngine.getEngine();
506  CometContext<?> context = engine.getCometContext(cometContext);
507  try{
508  context.notify(null,cometHandler);
509  }
510  catch(Exception e){
511  String msg = "Can't notify comet.";
512  Logger.getLogger(EditorSession.class.getName()).log(Level.ALL, msg);
513  }
514  }
515  }
516 
517  /**
518  * The method finds the corresponding subscriptions for submitted type of
519  * annotation, users and resources.
520  *
521  * @param list List of subscribed or unsubscribed annotations
522  * @param annot Annotation from which Identification of user (URI or address) will be get
523  * @param type Annotation type for which method searching for a record annotation type
524  * @param sources List of sources to which annotation belongs to
525  * @return Returns list of SubscribedSources that corresponds with type of annotation
526  */
527  static public ArrayList<SubscribedSource> listOfMatches(ArrayList<SubscribedSource> list, Annotation annot, AnnotType type, ArrayList<String> sources) {
528  ArrayList<SubscribedSource> resultList = new ArrayList<SubscribedSource>();
529  if(list == null){
530  return resultList;
531  }
532  ListIterator<SubscribedSource> iter = list.listIterator();
533  SubscribedSource subS = null;
534 
535  try{
536 
537  if (sources != null) {
538  if (!sources.isEmpty()) {
539  ListIterator<String> sIter = sources.listIterator();
540  String source = null;
541  while (sIter.hasNext()) {
542  source = sIter.next();
543  iter = list.listIterator();
544  while (iter.hasNext()) {
545  subS = iter.next();
546  if (subS.matches(type.getUri(), annot.getUser().getURI(), source) || subS.matches(type.getUri(), annot.getUser().getURIV2(), source)) {
547  resultList.add(subS);
548  }
549  }
550  }
551  } else {
552  while (iter.hasNext()) {
553  subS = iter.next();
554  if (subS.matches(type.getUri(), annot.getUser().getURI(), null) || subS.matches(type.getUri(), annot.getUser().getURIV2(), null)) {
555  resultList.add(subS);
556  }
557  }
558  }
559  } else {
560  while (iter.hasNext()) {
561  subS = iter.next();
562  if (subS.matches(type.getUri(), annot.getUser().getURI(), null) || subS.matches(type.getUri(), annot.getUser().getURIV2(), null)) {
563  resultList.add(subS);
564  }
565  }
566  }
567  // For clients with bad protocol or for unknown user
568  iter = list.listIterator();
569  if (sources != null) {
570  if (!sources.isEmpty()) {
571  ListIterator<String> sIter = sources.listIterator();
572  String source = null;
573  while (sIter.hasNext()) {
574  source = sIter.next();
575  iter = list.listIterator();
576  while (iter.hasNext()) {
577  subS = iter.next();
578  if (subS.matches(type.getUri(), annot.getAuthorAddress(), source)) {
579  resultList.add(subS);
580  }
581  }
582  }
583  } else {
584  while (iter.hasNext()) {
585  subS = iter.next();
586  if (subS.matches(type.getUri(), annot.getAuthorAddress(), null)) {
587  resultList.add(subS);
588  }
589  }
590  }
591  } else {
592  while (iter.hasNext()) {
593  subS = iter.next();
594  if (subS.matches(type.getUri(), annot.getAuthorAddress(), null)) {
595  resultList.add(subS);
596  }
597  }
598  }
599 
600  } catch(Exception e) {
601  throw new NullPointerException("NullPointerException was occurs in EditorSessionModule, while trying to find corresponding subscriptions");
602  }
603  return resultList;
604  } // listOfMatches()
605 
606  /**
607  * Checks whether list contain subscribed (or unsubscribed) source rule other
608  * then "hungry type" rule (rule where type isn't fill).
609  *
610  * @param list List of subscribed sources (rules)
611  * @return Returns true if found other rule then "hungry type" rule otherwise return false
612  */
613  static public boolean containTypeRule(ArrayList<SubscribedSource> list){
614 
615  ListIterator<SubscribedSource> iter = list.listIterator();
616 
617  while(iter.hasNext()){
618  SubscribedSource actualSource = iter.next();
619  if(actualSource.getType() != null)
620  {
621  if((!actualSource.getType().startsWith("*"))){
622  return true;
623  }
624  }
625  }
626 
627  return false;
628  }
629 
630  /**
631  * Checks whether list contain subscribed (or unsubscribed) source rule other
632  * then "hungry user" rule (rule where user isn't fill).
633  *
634  * @param list List of subscribed sources (rules)
635  * @return Returns true if found other rule then "hungry user" rule otherwise return false
636  */
637  static public boolean containUserRule(ArrayList<SubscribedSource> list)
638  {
639  ListIterator<SubscribedSource> iter = list.listIterator();
640 
641  while(iter.hasNext()){
642  SubscribedSource actualSource = iter.next();
643 
644  if(actualSource.getUser() != null){
645  return true;
646  }
647  }
648 
649  return false;
650  }
651 
652  /**
653  * Checks whether list contain subscribed (or unsubscribed) source rule other
654  * then "hungry source" rule (rule where source isn't fill).
655  *
656  * @param list List of subscribed sources (rules)
657  * @return Returns true if found other rule then "hungry source" rule otherwhise retrun false
658  */
659  static public boolean containSourceRule(ArrayList<SubscribedSource> list)
660  {
661  ListIterator<SubscribedSource> iter = list.listIterator();
662 
663  while(iter.hasNext()){
664  SubscribedSource actualSource = iter.next();
665 
666  if(actualSource.getUri() != null){
667  return true;
668  }
669  }
670 
671  return false;
672  }
673 
674  /**
675  * Method finds every rule for all given annotations type ancestors and returns if is subscribed or unsubscribed.
676  *
677  * @param rootType type where will checking begin
678  * @param annot annotation that is checked
679  * @param sources sources for current user
680  * @param unsubResult list of found unsubscribed rules
681  * @param subResult list of found subscribed files
682  * @return value that represent if is current annotation subscribed unsubscribed or method don't find any rule
683  */
684  private int checkBranch(AnnotType rootType, Annotation annot, ArrayList<String> sources,
685  ArrayList<SubscribedSource> unsubResult, ArrayList<SubscribedSource> subResult){
686 
687  AnnotType actualType = rootType;
688 
689  while(actualType != null) //climb tree of types from nod to root
690  {
691  int ancestorsCount = actualType.getAncestorTypes().size();
692 
693  if(ancestorsCount <= 1){
694 
695  // check if is current type type of annotation in unsubscribed list
696  unsubResult.clear();
697  unsubResult.addAll(listOfMatches(unsubscribedSources,annot,actualType,sources));
698 
699  // or in subscribed list
700  subResult.clear();
701  subResult.addAll(listOfMatches(subscribedSources,annot,actualType,sources));
702 
703  if(!subResult.isEmpty() && containTypeRule(subResult)){
704  return Constants.SUBSCRIBED; // if was type found in subscribed then return true
705  }else{
706  if(!unsubResult.isEmpty() && containTypeRule(unsubResult)){
707  return Constants.UNSUBSCRIBED; // if was type of annotation found in unsubscribed then return false
708  }
709  }
710 
711  actualType = actualType.getAncestorType();
712  }else{
713  Iterator<AnnotType> typeIt = actualType.getAncestorTypes().iterator();
714  int resultsArray[] = new int [ancestorsCount];
715  boolean unsubscribedOccur = false;
716 
717  for(int i = 0;typeIt.hasNext();i++){
718  resultsArray[i] = checkBranch(typeIt.next(),annot,sources,unsubResult,subResult);
719  if(resultsArray[i] == Constants.SUBSCRIBED) return Constants.SUBSCRIBED;
720  if(resultsArray[i] == Constants.UNSUBSCRIBED) unsubscribedOccur = true;
721  }
722 
723  if(unsubscribedOccur) return Constants.UNSUBSCRIBED;
724  else return Constants.NOTHING;
725  }
726  }
727  return Constants.NOTHING;
728  }
729 
730  /**
731  * Checks whether editor connected to this session is subscribed to get given
732  * annotation.
733  *
734  * @param annot Checked annotation
735  * @param sources List of sources to which annotation belongs to
736  * @return If annotation matches to subscriptions, returns true, false otherwise
737  */
738  public boolean isSubscribed(Annotation annot, ArrayList<String> sources) {
739 
740  AnnotType type = annot.getAnnotType();
741 
742  ArrayList<SubscribedSource> unsubResult = new ArrayList<SubscribedSource>();
743  ArrayList<SubscribedSource> subResult = new ArrayList<SubscribedSource>();
744 
745  switch(checkBranch(annot.getAnnotType(),annot,sources,unsubResult,subResult)){
746  case Constants.SUBSCRIBED: return true;
747  case Constants.UNSUBSCRIBED: return false;
748  default:
749  }
750 
751  //if there occured only hungry subscriptions
752 
753  if(!subResult.isEmpty() || !unsubResult.isEmpty())
754  {
755  if(containUserRule(subResult)){
756  return true;
757  }
758  if(containUserRule(unsubResult)){
759  return false;
760  }
761  if(containSourceRule(subResult)){
762  return true;
763  }
764  if(containSourceRule(unsubResult)){
765  return false;
766  }
767  }
768 
769  return false;
770  } // isSubscribed()
771 
772  /**
773  * Gets list of subscribed sources
774  *
775  * @return List of subscribed sources
776  */
777  public ArrayList<SubscribedSource> getSubscribedSources() {
778  return subscribedSources;
779  }
780 
781  /**
782  * Gets user logged in this session
783  *
784  * @return Returns user logged in this session
785  */
786  public User getUser() {
787  return user;
788  }
789 
790  /**
791  * Sets user logged in this session
792  *
793  * @param user User logged in this session
794  */
795  public void setUser(User user) {
796  this.user = user;
797  }
798 
799  /**
800  * Gets synchronized document
801  *
802  * @return Returns synchronized document
803  */
805  return syncDocument;
806  }
807 
808  /**
809  * Sets synchronized document
810  *
811  * @param syncDocument Synchronized document
812  */
814  this.docIDdependentVariablesInitialized = false;
815  if(this.syncDocument != null && this.syncDocument.getId() != null){
816  AppBean.decrementDocumentUsage(this.syncDocument.getId());
817  }
818  if (syncDocument != null && syncDocument.getId() != null) {
819  this.docIDdependentVariablesInitialized = true;
820  if(AppBean.getDocumentUsage(syncDocument.getId()) == 0){
821  AppBean.removePossibleModificationSets(syncDocument.getId());
822  AppBean.initLastDocModification(syncDocument.getId());
823  }
824  AppBean.incrementDocumentUsage(syncDocument.getId());
825  }
826  this.syncDocument = syncDocument;
827  }
828 
829  /**
830  * If we synchronize a new document then
831  * we dont have doc.id when we first call setSyncDocument
832  */
835  syncDocument != null && syncDocument.getId() != null)
836  {
838  AppBean.removePossibleModificationSets(syncDocument.getId());
839  AppBean.initLastDocModification(syncDocument.getId());
840  }
841  AppBean.incrementDocumentUsage(syncDocument.getId());
842  }
843  }
844 
845  /**
846  * Returns status of linearization
847  *
848  * @return If linearization is enabled, returns true, false otherwise
849  */
850  public boolean isLinearization() {
851  return linearization;
852  }
853 
854  /**
855  * Sets linearization
856  *
857  * @param linearization If linearization is enabled then true, false otherwise
858  */
859  public void setLinearization(boolean linearization) {
860  this.linearization = linearization;
861  }
862 
863  public ArrayList<String> getSuggestionsTypes() {
864  return suggestionsTypes;
865  }
866 
867  public void setSuggestionsTypes(ArrayList<String> suggestionsTypes) {
868  this.suggestionsTypes = suggestionsTypes;
869  }
870 
871  public void addSuggestionType(String suggestionsType){
872  if(this.suggestionsTypes == null){
873  this.suggestionsTypes = new ArrayList<String>();
874  }
875 
876  this.suggestionsTypes.add(suggestionsType);
877  }
878 
879  public void clearSuggestionsTypes(){
880  if(this.suggestionsTypes == null){
881  this.suggestionsTypes = new ArrayList<String>();
882  }
883 
884  this.suggestionsTypes.clear();
885  }
886 
887  public boolean isSuggestionType(){
888  if(this.suggestionsTypes == null){
889  this.suggestionsTypes = new ArrayList<String>();
890  }
891 
892  return this.suggestionsTypes.isEmpty();
893  }
894 
895  /**
896  * Sets parsed synchronized document
897  *
898  * @param doc New document
899  */
900  public void setParsedSyncDocument(Document doc) {
901  this.parsedSyncDocument = doc;
902  }
903 
904  /**
905  * Gets parsed synchronized document
906  *
907  * @return Returns parsed synchronized document
908  */
909  public Document getParsedSyncDocument() {
910  return this.parsedSyncDocument;
911  }
912 
913  /**
914  * Gets parsed linearized document
915  *
916  * @return Returns parsed linearized document
917  */
918  public String getParsedLinDocument() {
919  return parsedLinDocument;
920  }
921 
922  /**
923  * Gets content of cache for annotation suggestions
924  *
925  * @return Returns content of cache for annotation suggestions
926  */
927  public ArrayList<SuggestionLogEntry> getSuggestionsCache() {
928  return suggestionsCache;
929  }
930 
931  /**
932  * Sets content of cache for annotation suggestions
933  *
934  * @param suggestionsCache Content of cache for annotation suggestions
935  */
936  public void setSuggestionsCache(ArrayList<SuggestionLogEntry> suggestionsCache) {
937  this.suggestionsCache = suggestionsCache;
938  }
939 
940  /**
941  * Sets parsed linearized document
942  *
943  * @param parsedLinDocument Parsed linearized document
944  */
946  this.parsedLinDocument = parsedLinDocument;
947  }
948 
949  /**
950  * Gets string with messages to be sent via comet
951  *
952  * @return Returns string with messages to be sent via comet
953  */
954  public String getMessagesTSVC() {
955  return messagesTSVC;
956  }
957 
958  /**
959  * Sets string with messages to be sent via comet
960  *
961  * @param messagesTSVC String with messages to be sent via comet
962  */
963  public void setMessagesTSVC(String messagesTSVC) {
964  this.messagesTSVC = messagesTSVC;
965  }
966 
967  /**
968  * Returns true if this session contaions any messages for send via coment
969  *
970  * @return is messages string not empty?
971  */
972  public boolean hasMessagesTSVC() {
973  if(this.messagesTSVC != null){
974  return !this.messagesTSVC.isEmpty();
975  }
976  return false;
977  }
978 
979  /**
980  * Gets and cleans string with messages to be sent via comet
981  *
982  * @return Returns string with messages to be sent via comet
983  */
984  public synchronized String getAndCleanMessages() {
985  String retStr = messagesTSVC;
986  messagesTSVC = "";
987  return retStr;
988  }
989 
990  /**
991  * Adds message to string with messages to be sent via comet
992  *
993  * @param message Message to be sent via comet
994  */
995  public synchronized void addMessageTS(String message) {
996  messagesTSVC = messagesTSVC + message;
997  }
998 
999  /**
1000  * Gets list of subscriptions.
1001  *
1002  * @return list of subscriptions
1003  */
1004  public ArrayList<Subscription> getSubscribeList() {
1005  return subscribeList;
1006  }
1007 
1008  /**
1009  * Sets list of subscriptions.
1010  *
1011  * @param subscribeList list of subscriptions
1012  */
1013  public void setSubscribeList(ArrayList<Subscription> subscribeList) {
1014  this.subscribeList = subscribeList;
1015  }
1016 
1017 
1018  /**
1019  * Remove subscription from subscribe list.
1020  *
1021  * @param subscription subscription to delete
1022  */
1023  public void deleteFromSubscribeList(Subscription subscription){
1024  if(this.subscribeList != null && !subscribeList.isEmpty()){
1025  Iterator<Subscription> subscribeListIt = subscribeList.iterator();
1026  while(subscribeListIt.hasNext()){
1027  if(subscription.getId() != null && subscription.equals(subscribeListIt.next())){
1028  subscribeListIt.remove();
1029  return;
1030  }
1031  }
1032  }
1033  }
1034 
1035 
1036  /**
1037  * Add subscription to subscribe list.
1038  *
1039  * @param subscription subscription to add
1040  */
1041  public void addToSubscribeList(Subscription subscription){
1042  if(this.subscribeList != null){
1043  if(!isInSubscribeList(subscription)){
1044  this.subscribeList.add(subscription);
1045  }
1046  }else{
1047  this.subscribeList = new ArrayList<Subscription>();
1048  this.subscribeList.add(subscription);
1049  }
1050  }
1051 
1052  /**
1053  * Gets subscription from subscribe list by id.
1054  *
1055  * @param id id of searched subscription
1056  */
1058  if(this.subscribeList != null && !subscribeList.isEmpty()){
1059  Iterator<Subscription> subscribeListIt = subscribeList.iterator();
1060  while(subscribeListIt.hasNext()){
1061  Subscription currentSubscription = subscribeListIt.next();
1062  if(currentSubscription.getId().equals(id)){
1063  return currentSubscription;
1064  }
1065  }
1066  }
1067 
1068  return null;
1069  }
1070 
1071 
1072  /**
1073  * Tests if given subscription is already in list.
1074  *
1075  * @param subscription searched subscription
1076  *
1077  * @return true if subscription is already in list, false otherwise
1078  */
1079  public boolean isInSubscribeList(Subscription subscription){
1080  if(this.subscribeList != null && !subscribeList.isEmpty()){
1081  Iterator<Subscription> subscribeListIt = subscribeList.iterator();
1082  while(subscribeListIt.hasNext()){
1083  if(subscription.getId() != null && subscription.getId().equals(subscribeListIt.next().getId())){
1084  return true;
1085  }
1086  }
1087  }
1088  return false;
1089  }
1090 
1091  /**
1092  * Removes subscription sources from subscribe and unsubscribe list.
1093  *
1094  * @param subscription subscriprion which source will be remove from list
1095  */
1096  public void deleteFromSubscribes(Subscription subscription){
1097  // delete positive sources from session
1098  ArrayList<SubscribedSource> sourcePosList = subscription.getSourcesAsSubSource(true);
1099  if(sourcePosList != null && !sourcePosList.isEmpty()){
1100  Iterator<SubscribedSource> posSourcesIt = sourcePosList.iterator();
1101  while(posSourcesIt.hasNext()){
1102  SubscribedSource currentSource = posSourcesIt.next();
1104  }
1105  }
1106 
1107  // delete negative sources from session
1108  ArrayList<SubscribedSource> sourceNegList = subscription.getSourcesAsSubSource(false);
1109  if(sourceNegList != null && !sourceNegList.isEmpty()){
1110  Iterator<SubscribedSource> negSourcesIt = sourceNegList.iterator();
1111  while(negSourcesIt.hasNext()){
1112  SubscribedSource currentSource = negSourcesIt.next();
1114  }
1115  }
1116  }
1117 
1118  /**
1119  * Adds subscription sources to subscribe and unsubscribe list.
1120  *
1121  * @param subscription subscriprion which source will be add to list
1122  */
1123  public void addToSubscribes(Subscription subscription){
1124  // add positive sources to session
1125  ArrayList<SubscribedSource> sourcePosList = subscription.getSourcesAsSubSource(true);
1126  if(sourcePosList != null && !sourcePosList.isEmpty()){
1127  Iterator<SubscribedSource> posSourcesIt = sourcePosList.iterator();
1128  while(posSourcesIt.hasNext()){
1129  SubscribedSource currentSource = posSourcesIt.next();
1130  addSource(currentSource);
1131  }
1132  }
1133 
1134  // add negative sources to session
1135  ArrayList<SubscribedSource> sourceNegList = subscription.getSourcesAsSubSource(false);
1136  if(sourceNegList != null && !sourceNegList.isEmpty()){
1137  Iterator<SubscribedSource> negSourcesIt = sourceNegList.iterator();
1138  while(negSourcesIt.hasNext()){
1139  SubscribedSource currentSource = negSourcesIt.next();
1140  addUnsubscribeSource(currentSource);
1141  }
1142  }
1143  }
1144 
1145  /**
1146  * Finds subscription source in subscribed or unsubscribed list and remove it.
1147  *
1148  * @param sources list where method will be search for subscription source
1149  * @param subSource subscription source that will be delete from list
1150  */
1151  private void findSubscriptionAndDelete(ArrayList<SubscribedSource> sources, SubscribedSource subSource){
1152  if(sources != null && !sources.isEmpty()){
1153  Iterator<SubscribedSource> sourcesIt = sources.iterator();
1154  while(sourcesIt.hasNext()){
1155  SubscribedSource actualSource = sourcesIt.next();
1156  boolean isTypeEqual = false;
1157  boolean isUriEqual = false;
1158  boolean isSourceEqual = false;
1159 
1160  if((actualSource.getType() != null && subSource.getType() != null) &&
1161  (actualSource.getType().equals(subSource.getType()))){
1162  isTypeEqual = true;
1163  }else if((actualSource.getType() == null && subSource.getType() == null) ){
1164  isTypeEqual = true;
1165  }
1166 
1167  if((actualSource.getUri() != null && subSource.getUri() != null) &&
1168  (actualSource.getUri().equals(subSource.getUri()))){
1169  isUriEqual = true;
1170  }else if((actualSource.getUri() == null && subSource.getUri() == null) ){
1171  isUriEqual = true;
1172  }
1173 
1174  if((actualSource.getUser() != null && subSource.getUser() != null) &&
1175  (actualSource.getUser().equals(subSource.getUser()))){
1176  isSourceEqual = true;
1177  }else if((actualSource.getUser() == null && subSource.getUser() == null) ){
1178  isSourceEqual = true;
1179  }
1180 
1181  if(isTypeEqual && isUriEqual && isSourceEqual){
1182  sourcesIt.remove();
1183  return;
1184  }
1185  }
1186  }
1187  }
1188 
1189  /**
1190  * Gets user settings for logged in user from database
1191  *
1192  * @return Returns list of parameters of user settings or null, if nobody logged in
1193  */
1194  public ArrayList<Settings> getSettings() {
1195  if (this.user == null) {
1196  return null;
1197  }
1198  PersistM pm = AppBean.getPersistenceManager();
1199  ArrayList<Settings> settings = new ArrayList<Settings>();
1200  Object[] params = new Object[2];
1201  params[0] = "userId";
1202  params[1] = this.user.getId();
1203 
1204  @SuppressWarnings("unchecked")
1205  List<Settings> sList = pm.queryDB("Settings.findByUser", params);
1206  if (sList != null && !sList.isEmpty()) {
1207  Iterator<Settings> sIterator = sList.iterator();
1208  while (sIterator.hasNext()) {
1209  settings.add(sIterator.next());
1210  }
1211  }
1212  return settings;
1213  }
1214 
1215  /**
1216  * Gets list with names of attributes which should be filtered out
1217  *
1218  * @return Returns list with names of attributes which should be filtered out
1219  */
1220  public ArrayList<String> getAttFilter() {
1221  if (attFilter == null) {
1222  attFilter = new ArrayList<String>();
1223  }
1224  if (!attFilter.contains(Constants.UPDATABLE_AN_AT_NAME)) {
1225  attFilter.add(Constants.UPDATABLE_AN_AT_NAME);
1226  }
1227  return attFilter;
1228  }
1229 
1230  /**
1231  * Sets list with names of attributes which should be filtered out
1232  *
1233  * @param attFilter List with names of attributes which should be filtered out
1234  */
1235  public void setAttFilter(ArrayList<String> attFilter) {
1236  this.attFilter = attFilter;
1237  }
1238 
1239  /**
1240  * Actualizes attribute filter from user's settings
1241  */
1242  public void actualizeAttFilter() {
1243  if (this.user == null) {
1244  return;
1245  }
1246  PersistM pm = AppBean.getPersistenceManager();
1247  Settings attFilterParam = null;
1248  Object[] params = new Object[4];
1249  params[0] = "userId";
1250  params[1] = this.user.getId();
1251  params[2] = "name";
1253  List sList = pm.queryDB("Settings.findByUserAndName", params);
1254  if (sList != null && !sList.isEmpty()) {
1255  attFilterParam = (Settings) sList.get(0);
1256  }
1257  if (attFilterParam != null) {
1258  String attFilterParamStr = attFilterParam.getValue();
1259  if (attFilterParamStr != null && !attFilterParamStr.isEmpty()) {
1260  String[] splitted = attFilterParamStr.split(",");
1261  attFilter = new ArrayList<String>(Arrays.asList(splitted));
1262  } else {
1263  attFilter = new ArrayList<String>();
1264  }
1265  }
1266  } // actualizeAttFilter()
1267 
1268  /**
1269  * Actualizes all cached settings
1270  */
1279  }
1280 
1281  /**
1282  * Actualizes whether negative feedback should updated for suggestions refused
1283  * by same fragment as some confirmed have.
1284  */
1286  if (this.user == null) {
1287  return;
1288  }
1289  PersistM pm = AppBean.getPersistenceManager();
1290  Settings negFeedParam = null;
1291  Object[] params = new Object[4];
1292  params[0] = "userId";
1293  params[1] = this.user.getId();
1294  params[2] = "name";
1296  List sList = pm.queryDB("Settings.findByUserAndName", params);
1297  if (sList != null && !sList.isEmpty()) {
1298  negFeedParam = (Settings) sList.get(0);
1299  } else {
1301  }
1302  if (negFeedParam != null) {
1303  String negFeedParamStr = negFeedParam.getValue();
1304  if (negFeedParamStr != null && !negFeedParamStr.isEmpty()) {
1305  if (negFeedParamStr.contentEquals("1") || negFeedParamStr.equalsIgnoreCase("true")) {
1307  } else {
1309  }
1310  } else {
1312  }
1313  } else {
1315  }
1316  } // actualizeNegFeedbackSetting()
1317 
1318  /**
1319  * Should be negative feedback updated for suggestions refused by same
1320  * fragment as some confirmed have?
1321  *
1322  * @return Returns whether negative feedback should updated for suggestions
1323  * refused by same fragment as some confirmed have.
1324  */
1327  }
1328 
1329  /**
1330  * Sets whether negative feedback should updated for suggestions refused
1331  * by same fragment as some confirmed have.
1332  *
1333  * @param updateNegFeedbackForRefusedBySame Should be negative feedback updated
1334  * for suggestions refused by same
1335  * fragment as some confirmed have?
1336  */
1338  this.updateNegFeedbackForRefusedBySame = updateNegFeedbackForRefusedBySame;
1339  }
1340 
1341  /**
1342  * Actualizes whether alternatives should be automatically activated
1343  */
1344  public void actualizeAutoAltSetting() {
1345  if (this.user == null) {
1346  return;
1347  }
1348  PersistM pm = AppBean.getPersistenceManager();
1349  Settings negFeedParam = null;
1350  Object[] params = new Object[4];
1351  params[0] = "userId";
1352  params[1] = this.user.getId();
1353  params[2] = "name";
1355  List sList = pm.queryDB("Settings.findByUserAndName", params);
1356  if (sList != null && !sList.isEmpty()) {
1357  negFeedParam = (Settings) sList.get(0);
1358  } else {
1359  autoActivateAlternatives = false;
1360  }
1361  if (negFeedParam != null) {
1362  String negFeedParamStr = negFeedParam.getValue();
1363  if (negFeedParamStr != null && !negFeedParamStr.isEmpty()) {
1364  if (negFeedParamStr.contentEquals("1") || negFeedParamStr.equalsIgnoreCase("true")) {
1365  autoActivateAlternatives = true;
1366  } else {
1367  autoActivateAlternatives = false;
1368  }
1369  } else {
1370  autoActivateAlternatives = false;
1371  }
1372  } else {
1373  autoActivateAlternatives = false;
1374  }
1375  } // actualizeAutoAltSetting()
1376 
1377  /**
1378  * Should be alternatives automatically activated?
1379  *
1380  * @return Returns whether alternatives should be automatically activated
1381  */
1382  public boolean getAutoActivateAlternatives() {
1383  return autoActivateAlternatives;
1384  }
1385 
1386  /**
1387  * Sets whether alternatives should be automatically activated
1388  *
1389  * @param autoActivateAlternatives Should be alternatives automatically activated?
1390  */
1392  this.autoActivateAlternatives = autoActivateAlternatives;
1393  }
1394 
1395  /**
1396  * Actualizes whether other similar (same annotated text and URI of entity)
1397  * suggestions in same part of document should be confirmed
1398  */
1400  if (this.user == null) {
1401  return;
1402  }
1403  PersistM pm = AppBean.getPersistenceManager();
1404  Settings posFeedParam = null;
1405  Object[] params = new Object[4];
1406  params[0] = "userId";
1407  params[1] = this.user.getId();
1408  params[2] = "name";
1410  List sList = pm.queryDB("Settings.findByUserAndName", params);
1411  if (sList != null && !sList.isEmpty()) {
1412  posFeedParam = (Settings) sList.get(0);
1413  } else {
1415  }
1416  if (posFeedParam != null) {
1417  String posFeedParamStr = posFeedParam.getValue();
1418  if (posFeedParamStr != null && !posFeedParamStr.isEmpty()) {
1419  if (posFeedParamStr.contentEquals("1") || posFeedParamStr.equalsIgnoreCase("true")) {
1421  } else {
1423  }
1424  } else {
1426  }
1427  } else {
1429  }
1430  } // actualizeEnableUpdatePositiveFeedback()
1431 
1432  /**
1433  * Should be other similar (same annotated text and URI of entity)
1434  * suggestions in same part of document confirmed?
1435  *
1436  * @return Returns whether other similar (same annotated text and URI of entity)
1437  * suggestions in same part of document should be confirmed
1438  */
1441  }
1442 
1443  /**
1444  * Sets whether other similar (same annotated text and URI of entity)
1445  * suggestions in same part of document should be confirmed
1446  *
1447  * @param enableUpdatePositiveFeedback Should be other similar (same
1448  * annotated text and URI of entity)
1449  * suggestions in same part of document
1450  * confirmed?
1451  */
1453  this.enableUpdatePositiveFeedback = enableUpdatePositiveFeedback;
1454  }
1455 
1456  /**
1457  * Get language used in this session
1458  *
1459  * @return Returns language used in this session
1460  */
1461  public String getLanguage() {
1462  return language;
1463  }
1464 
1465  /**
1466  * Get number of language used in this session
1467  *
1468  * @return Returns number of language used in this session
1469  */
1470  public int getLanguageNum() {
1471  return languageNum;
1472  }
1473 
1474  /**
1475  * Set language for this session. If language code is not found, language
1476  * is set to English.
1477  *
1478  * @param language Language code according to ISO 639-2
1479  * @return If succeed and language code is found, returns true, false otherwise
1480  */
1481  public boolean setLanguage(String language) {
1482  int lNum = Localisation.LANGUAGE_CODES.indexOf(language);
1483  if (lNum < 0) {
1484  this.language = "eng";
1485  this.languageNum = Localisation.LANGUAGE_ENG;
1486  return true;
1487  }
1488  this.language = language;
1489  this.languageNum = lNum;
1490  return false;
1491  }
1492 
1493  /**
1494  * Actualize language settings from database
1495  *
1496  * @return If succeed, returns true, false otherwise
1497  */
1498  public boolean actualizeLanguage() {
1499  if (this.user == null) {
1500  return true;
1501  }
1502  PersistM pm = AppBean.getPersistenceManager();
1503  Settings langParam = null;
1504  Object[] params = new Object[4];
1505  params[0] = "userId";
1506  params[1] = this.user.getId();
1507  params[2] = "name";
1509  List sList = pm.queryDB("Settings.findByUserAndName", params);
1510  if (sList != null && !sList.isEmpty()) {
1511  langParam = (Settings) sList.get(0);
1512  } else {
1513  return true;
1514  }
1515  return setLanguage(langParam.getValue());
1516  }
1517 
1518  /**
1519  * Refreshes informations about user from DB
1520  */
1521  public void refreshUser() {
1522  if (user != null) {
1523  User u = (User) AppBean.getPersistenceManager().getEntityById("User", user.getId());
1524  if (u != null) {
1525  user = u;
1526  }
1527  }
1528  } // refreshUser()
1529 
1530  /**
1531  * Gets default group of logged in user from database.
1532  * If according user settings parameter is correctly set, it will be used.
1533  * If parameter is not set, first group of this user fetched from database
1534  * will be returned.
1535  *
1536  * @return Default group of logged in user
1537  */
1539  UserGroup retGroup = null;
1540  if (user == null) {
1541  return null;
1542  }
1543  PersistM pm = AppBean.getPersistenceManager();
1544  Settings langParam = null;
1545  Object[] params = new Object[4];
1546  params[0] = "userId";
1547  params[1] = this.user.getId();
1548  params[2] = "name";
1550  List sList = pm.queryDB("Settings.findByUserAndName", params);
1551  Settings groupParam = null;
1552  if (sList != null && !sList.isEmpty()) {
1553  groupParam = (Settings) sList.get(0);
1554  }
1555  if (groupParam != null) {
1556  String grStr = groupParam.getValue();
1557  if (grStr != null && !grStr.isEmpty()) {
1558  grStr = grStr.replace(AppBean.getBaseGroupUri(), "");
1559  Integer grId = null;
1560  try {
1561  grId = Integer.parseInt(grStr);
1562  } catch (NumberFormatException nfe) {
1564  String msg = "NumberFormatException in getDefaultGroup.";
1565  Logger.getLogger(EditorSession.class.getName()).log(Level.ALL, msg);
1566  }
1567  grId = null;
1568  }
1569  if (grId != null) {
1570  UserGroup cmpG = new UserGroup(grId);
1571  List<UserGroup> groupList = user.getGroups();
1572  int index = groupList.indexOf(cmpG);
1573  if (index >= 0) {
1574  retGroup = groupList.get(index);
1575  }
1576  }
1577  }
1578  }
1579  if (retGroup == null) {
1580  if (!user.getGroups().isEmpty()) {
1581  Iterator<UserGroup> grIt = user.getGroups().iterator();
1582  while (grIt.hasNext() && retGroup == null) {
1583  UserGroup gr = grIt.next();
1584  retGroup = gr;
1585  }
1586  }
1587  }
1588  return retGroup;
1589  } // getDefaultGroup()
1590 
1591  /***************************************
1592  * Suggestion
1593  ***************************************/
1594 
1595  /**
1596  * Sets minimal confidence
1597  *
1598  * @param minConfidence Number of minimal confidence
1599  */
1600  public void setMinConfidence(Integer minConfidence){
1601  this.minConfidence = minConfidence;
1602  }
1603 
1604  /**
1605  * Gets number of minimal confidence
1606  *
1607  * @return number of minimal confidence
1608  */
1609  public Integer getMinConfidence(){
1610  return minConfidence;
1611  }
1612 
1613  /**
1614  * Gets minimal level of confidence to auto confirm suggestion
1615  *
1616  * @return Returns minimal level of confidence to auto confirm suggestion
1617  */
1618  public Integer getAutoConfirm() {
1619  return autoConfirm;
1620  }
1621 
1622  /**
1623  * Sets minimal level of confidence to auto confirm suggestion
1624  *
1625  * @param autoConfirm Minimal level of confidence to auto confirm suggestion
1626  */
1627  public void setAutoConfirm(Integer autoConfirm) {
1628  this.autoConfirm = autoConfirm;
1629  }
1630 
1631  /**
1632  * Sets array of sent suggestions (client's cache)
1633  *
1634  * @param sugArray New array of sent suggestions
1635  */
1636  public void setSendedSugg(ArrayList<Integer> sugArray){
1637  synchronized (this) {
1638  sendedSuggestions = new ArrayList<Integer>();
1639  sendedSuggestions.addAll(sugArray);
1640  }
1641  }
1642 
1643  /**
1644  * Adds suggestion to the array of sent suggestions (client's cache)
1645  *
1646  * @param suggestion Suggestion to add
1647  */
1648  public void addSendedSugg(Suggestion suggestion){
1649  synchronized (sendedSuggestions) {
1650  if (!sendedSuggestions.contains(suggestion.getId())) {
1651  sendedSuggestions.add(suggestion.getId());
1652  }
1653  }
1654  }
1655 
1656  /**
1657  * Adds array of suggestions to the array of sent suggestions (client's cache)
1658  *
1659  * @param sugArray Array of suggestions to add
1660  */
1661  public void addSendedSugg(ArrayList<Suggestion> sugArray){
1662  synchronized (sendedSuggestions) {
1663  if (!sendedSuggestions.isEmpty()) {
1664  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1665  while (sugArrayIt.hasNext()) {
1666  addSendedSugg(sugArrayIt.next());
1667  }
1668  } else {
1669  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1670  while (sugArrayIt.hasNext()) {
1671  sendedSuggestions.add(sugArrayIt.next().getId());
1672  }
1673  }
1674  }
1675  }
1676 
1677  /**
1678  * Removes suggestion from the array of sended suggestions (client's cache)
1679  *
1680  * @param suggestion Suggestion to remove
1681  */
1682  public void deleteSendedSugg(Suggestion suggestion){
1683  synchronized (sendedSuggestions) {
1684  sendedSuggestions.remove(suggestion.getId());
1685  }
1686  }
1687 
1688  /**
1689  * Removes suggestions from the array of sended suggestions (client's cache)
1690  *
1691  * @param sugArray Array of suggestions to remove
1692  */
1693  public void deleteSendedSugg(ArrayList<Suggestion> sugArray){
1694  synchronized (sendedSuggestions) {
1695  if (!sendedSuggestions.isEmpty()) {
1696  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1697  while (sugArrayIt.hasNext()) {
1698  deleteSendedSugg(sugArrayIt.next());
1699  }
1700  }
1701  }
1702  }
1703 
1704  /**
1705  * Differences array of suggestions with array of sent ones and return these
1706  * suggestions which are not in sent
1707  *
1708  * @param sugArray Array to differences
1709  * @return Returns suggestions which are not in sent
1710  */
1711  public ArrayList<Suggestion> diffSendedSug(ArrayList<Suggestion> sugArray){
1712  synchronized (sendedSuggestions) {
1713  ArrayList<Suggestion> result = new ArrayList<Suggestion>(sugArray.size());
1714  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1715  while (sugArrayIt.hasNext()) {
1716  Suggestion actualSugg = sugArrayIt.next();
1717  if (!sendedSuggestions.contains(actualSugg.getId())) {
1718  result.add(actualSugg);
1719  }
1720  }
1721  return result;
1722  }
1723  }
1724 
1725  /**
1726  * Differences array of suggestions with array of sent ones and return these
1727  * suggestions which are in sent
1728  *
1729  * @param sugArray Array to differences
1730  * @return Returns suggestions which are in sent
1731  */
1732  public ArrayList<Suggestion> haveSendedSug(ArrayList<Suggestion> sugArray){
1733  synchronized (sendedSuggestions) {
1734  ArrayList<Suggestion> result = new ArrayList<Suggestion>(sugArray.size());
1735  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1736  while (sugArrayIt.hasNext()) {
1737  Suggestion actualSugg = sugArrayIt.next();
1738  if (sendedSuggestions.contains(actualSugg.getId())) {
1739  result.add(actualSugg);
1740  }
1741  }
1742  return result;
1743  }
1744  }
1745 
1746  /**
1747  * Differences array of suggestions with array of sent ones and return these
1748  * suggestions which are in sent but not in given array
1749  *
1750  * @param sugArray Array to differences
1751  * @return Returns suggestions which are in sent but not in given array
1752  */
1753  public ArrayList<Integer> diffStoredSug(ArrayList<Suggestion> sugArray){
1754  synchronized (sendedSuggestions) {
1755  ArrayList<Integer> result = new ArrayList<Integer>(sugArray.size());
1756  Iterator<Integer> sugArrayIdIt = sendedSuggestions.iterator();
1757  while (sugArrayIdIt.hasNext()) {
1758  Integer actualSuggId = sugArrayIdIt.next();
1759  Iterator<Suggestion> sugArrayIt = sugArray.iterator();
1760  boolean founded = false;
1761  while (sugArrayIt.hasNext()) {
1762  Suggestion actualSugg = sugArrayIt.next();
1763  if (actualSugg.getId().equals(actualSuggId)) {
1764  founded = true;
1765  break;
1766  }
1767  }
1768 
1769  if (!founded) {
1770  result.add(actualSuggId);
1771  }
1772  }
1773  return result;
1774  }
1775  }
1776 
1777  /**
1778  * Tries to find an ID of the suggestion in the sendedSuggestions array and
1779  * returns the result of the search as a boolean value
1780  *
1781  * @param suggID ID of the suggestion that we are searching for
1782  * @return True if the suggestion ID is contained, false otherwise
1783  */
1784  public boolean isSuggInSendedSuggestions(Integer suggID) {
1785  synchronized (sendedSuggestions) {
1786  if (sendedSuggestions.indexOf(suggID) >= 0) {
1787  return true;
1788  }
1789  return false;
1790  }
1791  }
1792 
1793  /**
1794  * Gets array of sent suggestions IDs (client's cache)
1795  *
1796  * @return Returns array of sent suggestions IDs
1797  */
1798  public ArrayList<Integer> getSendedSuggestions() {
1799  return sendedSuggestions;
1800  }
1801 
1802  /**
1803  * Get all sent suggestions.
1804  *
1805  * @return Returns list of sent suggestions
1806  */
1807  public ArrayList<Suggestion> getWholeSendedSuggestions() {
1808  synchronized (this) {
1809  ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>();
1810 
1811  Iterator<Integer> it = sendedSuggestions.iterator();
1812  while(it.hasNext()){
1813  Query query = AppBean.getPersistenceManager().getEM().createNamedQuery("Suggestion.findById");
1814  query.setParameter("id", it.next());
1815  List sList = query.getResultList();
1816  if (sList != null && !sList.isEmpty()) {
1817  suggestions.add((Suggestion) sList.get(0));
1818  }
1819  }
1820  return suggestions;
1821  }
1822  }
1823 
1824  /**
1825  * Get sended suggestion.
1826  *
1827  * @return Returns sended suggestion
1828  */
1830  Query query = AppBean.getPersistenceManager().getEM().createNamedQuery("Suggestion.findById");
1831  query.setParameter("id", id);
1832  List sList = query.getResultList();
1833  if (sList != null && !sList.isEmpty()) {
1834  return (Suggestion) sList.get(0);
1835  }
1836  return null;
1837  }
1838 
1839  /**
1840  * Returns whether suggestions was requested so an empty diff cannot be omitted.
1841  *
1842  * @return Returns whether suggestions was requested so an empty diff cannot be omitted
1843  */
1844  public synchronized Boolean getSugRequestFlag() {
1845  return sugRequestFlag;
1846  }
1847 
1848  /**
1849  * Sets whether suggestions was requested so an empty diff cannot be omitted.
1850  *
1851  * @param sugRequestFlag Was suggestions requested (can be empty diff omitted)?
1852  */
1853  public synchronized void setSugRequestFlag(Boolean sugRequestFlag) {
1854  this.sugRequestFlag = sugRequestFlag;
1855  }
1856 
1857  /**
1858  * Returns whether confidence should be displayed for suggestions
1859  *
1860  * @return Returns whether confidence should be displayed for suggestions
1861  */
1862  public boolean getDisplaySugConfidence() {
1863  return displaySugConfidence;
1864  }
1865 
1866  /**
1867  * Sets whether confidence should be displayed for suggestions
1868  *
1869  * @param displaySugConfidence Should be confidence displayed for suggestions?
1870  */
1872  this.displaySugConfidence = displaySugConfidence;
1873  }
1874 
1875  /**
1876  * Actualizes whether confidence should be displayed for suggestions
1877  */
1879  if (this.user == null) {
1880  return;
1881  }
1882  PersistM pm = AppBean.getPersistenceManager();
1883  Settings posFeedParam = null;
1884  Object[] params = new Object[4];
1885  params[0] = "userId";
1886  params[1] = this.user.getId();
1887  params[2] = "name";
1889  List sList = pm.queryDB("Settings.findByUserAndName", params);
1890  if (sList != null && !sList.isEmpty()) {
1891  posFeedParam = (Settings) sList.get(0);
1892  } else {
1893  displaySugConfidence = true;
1894  }
1895  if (posFeedParam != null) {
1896  String posFeedParamStr = posFeedParam.getValue();
1897  if (posFeedParamStr != null && !posFeedParamStr.isEmpty()) {
1898  if (posFeedParamStr.contentEquals("1") || posFeedParamStr.equalsIgnoreCase("true")) {
1899  displaySugConfidence = true;
1900  } else {
1901  displaySugConfidence = false;
1902  }
1903  } else {
1904  displaySugConfidence = false;
1905  }
1906  } else {
1907  displaySugConfidence = true;
1908  }
1909  } // actualizeDisplaySugConfidence()
1910 
1911  /**
1912  * Gets whether KB_Ref mode is on
1913  *
1914  * @return Returns whether KB_Ref mode is on
1915  */
1916  public boolean getKBRefMode() {
1917  return KBRefMode;
1918  }
1919 
1920  /**
1921  * Sets whether KB_Ref mode is on
1922  *
1923  * @param KBRefMode Is KB_Ref mode on?
1924  */
1925  public void setKBRefMode(boolean KBRefMode) {
1926  this.KBRefMode = KBRefMode;
1927  }
1928 
1929  /**
1930  * Actualizes whether KB_Ref mode is on
1931  */
1932  public void actualizeKBRefMode() {
1933  if (this.user == null) {
1934  return;
1935  }
1936  PersistM pm = AppBean.getPersistenceManager();
1937  Settings kRMParam = null;
1938  Object[] params = new Object[4];
1939  params[0] = "userId";
1940  params[1] = this.user.getId();
1941  params[2] = "name";
1943  List sList = pm.queryDB("Settings.findByUserAndName", params);
1944  if (sList != null && !sList.isEmpty()) {
1945  kRMParam = (Settings) sList.get(0);
1946  } else {
1947  KBRefMode = false;
1948  }
1949  if (kRMParam != null) {
1950  String kRMParamStr = kRMParam.getValue();
1951  if (kRMParamStr != null && !kRMParamStr.isEmpty()) {
1952  if (kRMParamStr.contentEquals("1") || kRMParamStr.equalsIgnoreCase("true")) {
1953  KBRefMode = true;
1954  } else {
1955  KBRefMode = false;
1956  }
1957  } else {
1958  KBRefMode = false;
1959  }
1960  } else {
1961  KBRefMode = false;
1962  }
1963  } // actualizeKBRefMode()
1964 
1965  /**
1966  * Compares this with other object and returns, whether objects are same type
1967  * and have same id.
1968  *
1969  * @param obj Object to compare with
1970  * @return If object is same type and have same id, returns true, false otherwise
1971  */
1972  @Override
1973  public boolean equals(Object obj) {
1974  if (obj == null) {
1975  return false;
1976  }
1977  if (getClass() != obj.getClass()) {
1978  return false;
1979  }
1980  final EditorSession other = (EditorSession) obj;
1981  if (this.sessionId != other.sessionId) {
1982  return false;
1983  }
1984  return true;
1985  }
1986 
1987  /**
1988  * Returns hash code of this object. Hash is based on sessionID.
1989  *
1990  * @return Hash code
1991  */
1992  @Override
1993  public int hashCode() {
1994  int hash = 3;
1995  hash = 89 * hash + (int) (this.sessionId ^ (this.sessionId >>> 32));
1996  return hash;
1997  }
1998 
1999 } // class EditorSession
static final String SETTINGS_PARAM_UPDATE_NEG_FEEDBACK_FOR_REFUSED_BY_SAME
Definition: Constants.java:282
boolean isSubscribed(Annotation annot, ArrayList< String > sources)
static ArrayList< SubscribedSource > listOfMatches(ArrayList< SubscribedSource > list, Annotation annot, AnnotType type, ArrayList< String > sources)
int checkBranch(AnnotType rootType, Annotation annot, ArrayList< String > sources, ArrayList< SubscribedSource > unsubResult, ArrayList< SubscribedSource > subResult)
void deleteFromSubscribeList(Subscription subscription)
synchronized void setSugRequestFlag(Boolean sugRequestFlag)
Persistence manager (database manipulator)
Definition: PersistM.java:35
void setUpdateNegFeedbackForRefusedBySame(boolean updateNegFeedbackForRefusedBySame)
static final String SETTINGS_PARAM_DISPLAY_SUG_CONFIDENCE
Definition: Constants.java:288
boolean isInSubscribeList(Subscription subscription)
boolean isSubscribedWG(Annotation annot, boolean testDoc)
boolean containsSource(SubscribedSource source)
void setDisplaySugConfidence(boolean displaySugConfidence)
Class representing annotated copy of document.
boolean isSubscribedWG(Annotation annot, ArrayList< String > sources, boolean testDoc)
void setAutoActivateAlternatives(boolean autoActivateAlternatives)
Singleton for storing global variables.
Definition: AppBean.java:47
ArrayList< Suggestion > haveSendedSug(ArrayList< Suggestion > sugArray)
volatile ArrayList< Integer > sendedSuggestions
ArrayList< Integer > diffStoredSug(ArrayList< Suggestion > sugArray)
static final String SETTINGS_PARAM_ENABLE_UPDATE_POSITIVE_FEEDBACK
Definition: Constants.java:284
void setParsedLinDocument(String parsedLinDocument)
void addUnsubscribeSource(SubscribedSource source)
void setSubscribeList(ArrayList< Subscription > subscribeList)
void deleteFromSubscribes(Subscription subscription)
static boolean containSourceRule(ArrayList< SubscribedSource > list)
void addToSubscribeList(Subscription subscription)
void findSubscriptionAndDelete(ArrayList< SubscribedSource > sources, SubscribedSource subSource)
boolean containsUnsubscribedSource(SubscribedSource source)
static final String SETTINGS_PARAM_DEFAULT_GROUP
Definition: Constants.java:278
Class representing user group.
Definition: UserGroup.java:47
Class representing parameter of user settings.
Definition: Settings.java:45
void setSuggestionsTypes(ArrayList< String > suggestionsTypes)
void setSendedSugg(ArrayList< Integer > sugArray)
static boolean containTypeRule(ArrayList< SubscribedSource > list)
ArrayList< SuggestionLogEntry > getSuggestionsCache()
boolean isSubscribed(Annotation annot, ArrayList< String > sources, boolean testDoc)
void setCometHandler(AnnotHandler cometHandler)
Class representing type of annotation.
Definition: AnnotType.java:58
Class representing user.
Definition: User.java:51
void setSuggestionsCache(ArrayList< SuggestionLogEntry > suggestionsCache)
void setAttFilter(ArrayList< String > attFilter)
void setEnableUpdatePositiveFeedback(boolean enableUpdatePositiveFeedback)
void removeUnsubscribeSource(SubscribedSource source)
void setSyncDocument(AnnotDocument syncDocument)
static final String SETTINGS_PARAM_AUTO_ALTERNATIVES
Definition: Constants.java:286
void setQueriedTypes(ArrayList< String > queriedTypes)
void setSuggestionsFr(ArrayList< Fragment > suggestionsFr)
ArrayList< SubscribedSource > getSubscribedSources()
boolean isSubscribed(Annotation annot, boolean testDoc)
Class representing suggestion of annotation.
Definition: Suggestion.java:87
static boolean containUserRule(ArrayList< SubscribedSource > list)
synchronized void addMessageTS(String message)
void deleteSendedSugg(ArrayList< Suggestion > sugArray)
Class responsible for localised strings.
static final String SETTINGS_PARAM_SERVER_LANGUAGE
Definition: Constants.java:276
Informations about client session.
void addToSubscribes(Subscription subscription)
Class representing annotated fragment.
Definition: Fragment.java:48
static synchronized int getDocumentUsage(Integer documentId)
Definition: AppBean.java:465
ArrayList< SuggestionLogEntry > suggestionsCache
ArrayList< SubscribedSource > unsubscribedSources
ArrayList< Suggestion > diffSendedSug(ArrayList< Suggestion > sugArray)
ArrayList< SubscribedSource > subscribedSources
void addSendedSugg(ArrayList< Suggestion > sugArray)
boolean isSubscribedWG(Annotation annot, ArrayList< String > sources)