4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
AlternativeManager.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: AlternativeManager.java
5  * Description: Class for manipulation with alternatives of suggestions
6  */
7 
8 /**
9  * @file AlternativeManager.java
10  *
11  * @brief Class for manipulation with alternatives of suggestions
12  */
13 
14 /**
15  * @package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative
16  *
17  * @brief Classes responsible for work with alternatives of suggestions
18  */
19 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative;
20 
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.logging.Level;
38 import java.util.logging.Logger;
39 import javax.persistence.EntityManager;
40 import javax.persistence.EntityTransaction;
41 import javax.persistence.Query;
42 
43 /**
44  * Class for manipulation with alternatives of suggestions
45  *
46  * @brief Class for manipulation with alternatives of suggestions
47  * @author Marek Kopecky
48  */
49 public class AlternativeManager extends Thread {
50 
51  /** Informations about request from client*/
53 
54  /** Linearized document */
55  String document;
56 
57  /** URI of original document */
58  String documentUri;
59 
60  /** Array for adding new types of alternatives */
61  ArrayList<AnnotType> newTypes;
62 
63  /** New saved suggestions */
64  ArrayList<Suggestion> validSuggestions;
65 
66  /** Suggestion manager */
68 
69  /** ID of synchronized document */
70  Integer docID;
71 
72  /**
73  * Constructor
74  *
75  * @param request Informations about request from client
76  * @param document Linearized document
77  * @param documentUri URI of original document
78  * @param validSuggestions New saved suggestions
79  * @param sugManager Suggestion manager which created this
80  * @param docID ID of synchronized document
81  */
82  public AlternativeManager(RequestInfo request, String document, String documentUri,
83  ArrayList<Suggestion> validSuggestions, SuggestionManager sugManager, Integer docID) {
84  //super("AlternativeManagerThread");
85  this.requestInfo = request;
86  this.document = document;
87  this.documentUri = documentUri;
88  this.newTypes = new ArrayList<AnnotType>();
89  this.validSuggestions = validSuggestions;
90  this.sugManager = sugManager;
91  this.docID = docID;
92  }
93 
94  /**
95  * Method start the thread code execution.
96  *
97  * Consider adding locks.
98  */
99  @Override
100  public void run() {
101  // lock for read
102  while(true){
103  if(AppBean.getLockMaster().getDocumentLock(docID).lockForRead()){
104  break;
105  }
106  }
107 
108  try { // lock for read has to be unlock
110  } catch(Exception ex){
111  String msg = "Unknown exception in AlternativeManager: " + ex.getMessage();
112  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, ex);
113  } finally {
114  // unlock for read
115  AppBean.getLockMaster().getDocumentLock(docID).unlockForRead();
116  }
117 
118  }
119 
120  /**
121  * Get and process alternatives.
122  */
123  private void processAlternative() {
124  while(true){
125  if(AppBean.getLockMaster().getSuggReqLock(requestInfo.getSession().getSyncDocument().getId()).lockForChange()){
126  break;
127  }
128  }
129  try {
130  // detect source of suggestions
131  SuggestionManager.SuggestionSource suggestionSource = SuggestionManager.sourceOfSuggestions(document);
132 
133  // get new alternatives from SEC API as a raw data
134  String rawNewAlternatives = null;
135  if (suggestionSource == SuggestionManager.SuggestionSource.SEC_API) {
137  rawNewAlternatives = sugManager.getSuggestionsFromRemoteSECAPI(requestInfo, document, documentUri, true, validSuggestions);
138  } else {
139  rawNewAlternatives = sugManager.getSuggestionsFromSECAPI(requestInfo, document, documentUri, true, validSuggestions);
140  }
141  }
142 
143  if (rawNewAlternatives != null) { // if alternatives are available
144  ArrayList<Suggestion> alternativesCreatedFor = new ArrayList<Suggestion>();
145 
146  // lock document for suggestion change
147  sugManager.lockDocForChange(docID);
148 
149  try { // lock for change has to be unlock
150  // transform raw data to alternatives
152  ArrayList<Alternative> newAlternatives = st.translateAlternativeFromSecApi(requestInfo, rawNewAlternatives, newTypes, validSuggestions);
153 
154  if (newAlternatives != null && !newAlternatives.isEmpty()) {
155  if (!SuggestionManager.persistTypes(newTypes)) {
156  // delete all alternatives for actual document
158 
159  // update types
160  if (newTypes != null) {
161  Iterator<AnnotType> newTypesUpdateIt = newTypes.iterator();
162  while (newTypesUpdateIt.hasNext()) {
163  AnnotType currentNewType = newTypesUpdateIt.next();
164 
165  Iterator<Alternative> newAlternativesIt = newAlternatives.iterator();
166  while (newAlternativesIt.hasNext()) {
167  Alternative currentAlternative = newAlternativesIt.next();
168  if (currentAlternative.getAnnotType().getUri().equals(currentNewType.getUri())) {
169  currentAlternative.setAnnotType(currentNewType);
170  }
171  }
172  }
173  }
174 
175  // if alternatives should be automatically activated, collect suggestions
176  if (requestInfo.getSession().getAutoActivateAlternatives()) {
177  Iterator<Alternative> newAlternativesIt = newAlternatives.iterator();
178  while (newAlternativesIt.hasNext()) {
179  Alternative currentAlternative = newAlternativesIt.next();
180  if (!alternativesCreatedFor.contains(currentAlternative.getAlternativeOfSuggestion())) {
181  alternativesCreatedFor.add(currentAlternative.getAlternativeOfSuggestion());
182  }
183  }
184  }
185 
186  // persist data
187  persistAlternatives(newAlternatives);
188  Iterator<EditorSession> sessIt = AppBean.getSessions().iterator();
189  while (sessIt.hasNext()) {
190  EditorSession sess = sessIt.next();
191  String typesStr = SuggestionManager.printTypes(requestInfo, sess, newTypes);
192  sess.addMessageTS(typesStr);
193  }
194  } else {
196  String msg = "Persisting of types of annotations failed.";
197  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg);
198  }
199  }
200  }
201  } catch (Exception ex) {
202  String msg = "Unknown exception in AlternativeManager: " + ex.getMessage();
203  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, ex);
204  }
205 
206  // unlock document for suggestions change
207  sugManager.unlockDocForChange(docID);
208 
209  // if alternatives should be automatically activated, activate them
210  if (requestInfo.getSession().getAutoActivateAlternatives()) {
211  Iterator<Suggestion> newAltIt = alternativesCreatedFor.iterator();
212  while (newAltIt.hasNext()) {
213  Suggestion sug = newAltIt.next();
215  }
216  String result = sugManager.printSuggestionsDiff(requestInfo.getSession(), new ArrayList<Suggestion>(), new ArrayList<AnnotType>());
217  requestInfo.getSession().addMessageTS(result);
218  requestInfo.getSession().notifyComet();
219  }
220 
221  } // if alternatives are available
222  } finally {
223  AppBean.getLockMaster().getSuggReqLock(requestInfo.getSession().getSyncDocument().getId()).unlockForChange();
224  }
225  } // processAlternative()
226 
227  /**
228  * Top level function to select alternatives for refused suggestion and activate it.
229  * This function is called, when user refuse some suggestion.
230  *
231  * @param request Informations about client request
232  * @param sug Refused suggestion.
233  */
234  public static void activateAlternatives(RequestInfo request, Suggestion sug) {
235  // id of top level alternativeOf
236  int topAlternativeOfId;
237  Suggestion alternativeOf = sug.getAlternativeOfSuggestion();
238 
239  // determine, if refused suggestion if alternative of another suggestion (false) or not (true)
240  boolean suggIsAlternativeOfAnotherSuggestion = true;
241  if (alternativeOf == null) {
242  topAlternativeOfId = sug.getId();
243  suggIsAlternativeOfAnotherSuggestion = false;
244  } else {
245  topAlternativeOfId = alternativeOf.getId();
246  }
247 
248  // get all possible alternatives
249  List<Alternative> alternativeList = getAlternatives(topAlternativeOfId);
250 
251  // no alternatives => no action here
252  ArrayList<Alternative> alternativeToPersist = new ArrayList<Alternative>();
253  if (alternativeList.isEmpty()) {
254  return;
255  }
256 
257  if (alternativeList.size() == 1 || suggIsAlternativeOfAnotherSuggestion) {
258  // only on alternative exist or there are not any suggestion based on refused suggestion
259  alternativeToPersist.add(alternativeList.get(0));
260  } else {
261  // persist batch of alternatives as suggestions
262  for (int i = 0; i < Constants.MAX_COUNT_OF_ALTERNATIVES_IN_BATCH && i < alternativeList.size(); i++) {
263  alternativeToPersist.add(alternativeList.get(i));
264  }
265  }
266 
267  ArrayList<Alternative> open = new ArrayList<Alternative>(alternativeToPersist);
268  ArrayList<Alternative> closed = new ArrayList<Alternative>();
269 
270  while(!open.isEmpty()){
271  Alternative tmpAlt = open.get(0);
272  ArrayList<Alternative> tmpList = new ArrayList<Alternative>();
273 
274  //Search for all links within alternative attributes
275  Iterator<AlternativeAttribute> attIt = tmpAlt.getAttributes().iterator();
276  while(attIt.hasNext()){
277  AlternativeAttribute tmpAtt = attIt.next();
278  if(tmpAtt.getUri() != null && !tmpAtt.getUri().isEmpty()){
279  //Search for nested alternative
280  Alternative a = null;
281 
282  if(tmpAtt.getSimpleType().equalsIgnoreCase("NestedSuggestion")){
283  a = tmpAtt.getNestedAlternative();
284  }
285  else if(tmpAtt.getSimpleType().equalsIgnoreCase("SuggestionLink")){
286  a = tmpAtt.getLinkedAlternative();
287  }
288 
289  if(a != null){
290  a.setTmpId(tmpAtt.getUri());
291  //Check whether this alternative is not already in open or closed list
292  if(!open.contains(a) && !closed.contains(a)){
293  tmpList.add(a);
294  }
295  }
296  else{
298  String msg = "Alternative attribute with name: "
299  + tmpAtt.getName()
300  + "does not contain reference to linked/nested alternative.";
301  Logger.getLogger(AlternativeManager.class.getName()).log(Level.WARNING, msg);
302  }
303  }
304  }
305  }
306  closed.add(tmpAlt);
307  open.remove(tmpAlt);
308  open.addAll(tmpList);
309  }
310 
311  // transform all selected alternatives to suggestion and delete alternatives from DB
312  ArrayList<Suggestion> sugAlternativeToPersist = alternativesToSuggestions(closed);
313  setAsUsed(closed);
314 
315  /* Map all suggestions that have tmpId (they are linked or nested ) */
316  HashMap<String, Suggestion> sugsMap = new HashMap<String, Suggestion>();
317  Iterator<Suggestion> tmpSugIt = sugAlternativeToPersist.iterator();
318  while(tmpSugIt.hasNext()){
319  Suggestion s = tmpSugIt.next();
320  if(s.getTmpId() != null && !s.getTmpId().isEmpty()){
321  sugsMap.put(s.getTmpId(), s);
322  }
323  }
324 
325  /* Iterate through all attributes of all suggestions to connect links */
326  tmpSugIt = sugAlternativeToPersist.iterator();
327  while(tmpSugIt.hasNext()){
328  Suggestion s = tmpSugIt.next();
329 
330  Iterator<SugBaseAttribute> sbAttIt = s.getAttributes().iterator();
331  while(sbAttIt.hasNext()){
332  SugBaseAttribute sbAtt = sbAttIt.next();
333  if(sbAtt.getSimpleType().equalsIgnoreCase("NestedSuggestion")){
334  sbAtt.setNestedSuggestion(sugsMap.get(sbAtt.getUri()));
335  }
336  else if(sbAtt.getSimpleType().equalsIgnoreCase("SuggestionLink")){
337  sbAtt.setLinkedSuggestion(sugsMap.get(sbAtt.getUri()));
338  }
339  }
340  }
341 
342  // update suggestion fragments
343  for (Iterator<Suggestion> it = sugAlternativeToPersist.iterator(); it.hasNext(); ) {
344  Suggestion actualSuggestion = it.next();
345  SuggestionManager.updateSuggestion(actualSuggestion,request);
346  // check updated suggestion fragment if there is some bad fragment
347  Iterator<SuggestionFragment> fragIt = actualSuggestion.getFragments().iterator();
348  while(fragIt.hasNext()){
349  SuggestionFragment actualFragment = fragIt.next();
350  // if some fragment is bad, suggestion is removed
351  if(!actualFragment.getIsGood()){
352  it.remove();
354  String msg = "Some alternative fragment can not be recovered.";
355  Logger.getLogger(AlternativeManager.class.getName()).log(Level.WARNING, msg);
356  }
357  break;
358  }
359  }
360  }
361 
362  // persist new suggestions
363  SugPersister.persist(request, null, null, sugAlternativeToPersist, false, new ArrayList<AnnotType>());
364  } // activateAlternatives()
365 
366  /**
367  * Top level function to remove alternatives of confirmSuggs and
368  * refuse suggestions, that were alternatives of confirmSuggs.
369  *
370  * @param request Informations about client request
371  * @param confirmSuggs List of suggestions
372  */
373  public static void confirmSuggestions(RequestInfo request, ArrayList<Suggestion> confirmSuggs) {
374  // remove isFromSECAPI flag from confirmed suggestions
375  // alternative will be never assigned to these suggestions
376  clearIsFromSECAPI(confirmSuggs);
377 
378  // iterate suggestions
379  ArrayList<Alternative> alternativeToDelete = new ArrayList<Alternative>();
380  ArrayList<Suggestion> suggestionsToRefuse = new ArrayList<Suggestion>();
381  for (Iterator<Suggestion> it = confirmSuggs.iterator(); it.hasNext(); ) {
382  Suggestion sg = it.next();
383  Integer sugId = sg.getId();
384  Suggestion alternativeOfSug = sg.getAlternativeOfSuggestion();
385  Integer alternativeOfId = (alternativeOfSug != null ? alternativeOfSug.getId() : null);
386  if (alternativeOfId != null && sugId != null) {
387  // confirmed suggestion is alternative of another suggestion
388  alternativeToDelete.addAll(getAlternatives(alternativeOfId));
389  suggestionsToRefuse.addAll(getOtherSuggestions(alternativeOfId, sugId));
390  } else if (sugId != null) {
391  // confirmed suggestion is not alternative of another suggestion
392  alternativeToDelete.addAll(getAlternatives(sugId));
393  }
394  }
395 
396  // set alternatives as used
397  if (!alternativeToDelete.isEmpty()) {
398  setAsUsed(alternativeToDelete);
399  }
400 
401  // refuse suggestions
402  refuseSuggestions(request, suggestionsToRefuse);
403  } // confirmSuggestions()
404 
405  /**
406  * Refuse suggestionsToRefuse list.
407  *
408  * @param request Informations about client request
409  * @param suggestionsToRefuse List of suggestions
410  */
411  private static void refuseSuggestions(RequestInfo request, ArrayList<Suggestion> suggestionsToRefuse) {
412  if (request.getSession() == null || request.getSession().getDefaultGroup() == null) {
414  String msg = "Missing default group in refusing process.";
415  Logger.getLogger(AlternativeManager.class.getName()).log(Level.WARNING, msg);
416  }
417  return; // it is not possible to do it without valid user group
418  }
419  Integer groupId = request.getSession().getDefaultGroup().getId();
420  for (Iterator<Suggestion> it = suggestionsToRefuse.iterator(); it.hasNext(); ) {
421  SuggestionManager.updateSuggNegativeFeedback(request, groupId, it.next().getId(), true);
422  }
423  }
424 
425  /**
426  * Persist function for alternatives
427  *
428  * @param alternatives Alternatives to persist
429  */
430  private void persistAlternatives(ArrayList<Alternative> alternatives) {
431  EntityManager em = AppBean.getPersistenceManager().getEM();
432  EntityTransaction transaction = em.getTransaction();
433  // updateTypes
434  try {
435  transaction.begin();
436  // for each alternative
437  for (Iterator<Alternative> itAlt = alternatives.iterator(); itAlt.hasNext();) {
438  Alternative alt = itAlt.next();
439  // persist alternative
440  em.merge(alt);
441  // persist attributes
442  for (Iterator<AlternativeAttribute> itAttr = alt.getAttributes().iterator(); itAttr.hasNext(); ) {
443  AlternativeAttribute atr = itAttr.next();
444  em.merge(atr);
445  }
446  // persist fragments
447  for (Iterator itFra = alt.getFragments().iterator(); itFra.hasNext(); ) {
448  AlternativeFragment fra = (AlternativeFragment) itFra.next();
449  em.merge(fra);
450  }
451  }
452  em.flush();
453  transaction.commit();
454  } catch (Exception e) {
455  transaction.rollback();
457  String msg = "Exception during the persisting of data.";
458  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, e);
459  }
460  } finally {
461  em.close();
462  }
463  } // persistAlternatives()
464 
465 
466  /**
467  * Determine, if on fragment overlap some fragments from suggestion
468  *
469  * @param sugFragments Suggestion fragments
470  * @param newFragStart Start offset of reference fragment
471  * @param newFragEnd End offset of reference fragment
472  * @return Determine, if on fragment overlap some fragments from suggestion
473  */
474  public static boolean overlappingFragment(ArrayList<SuggestionFragment> sugFragments, int newFragStart, int newFragEnd) {
475  Iterator<SuggestionFragment> sugFragmentsIt = sugFragments.iterator();
476  while(sugFragmentsIt.hasNext()){
477  SuggestionFragment actualSuggFragment = sugFragmentsIt.next();
478 
479  // Skip null fragments
480  if(actualSuggFragment == null){
481  continue;
482  }
483 
484  // get position of current suggestion fragment content in linearized document
485  int sugFragStart = actualSuggFragment.getOffset().intValue();
486  int sugFragEnd = sugFragStart + actualSuggFragment.getLength().intValue();
487 
488  if(newFragStart <= sugFragStart && newFragEnd >= sugFragStart){
489  // suggestion fragment starts in reference fragment
490  return true;
491  }else if(newFragStart <= sugFragEnd && newFragEnd >= sugFragEnd){
492  // suggestion fragment ends in reference fragment
493  return true;
494  }
495  }
496  return false;
497  } // overlappingFragment()
498 
499  /**
500  * Transform all selected alternatives to suggestion
501  *
502  * @param alternatives List of alternatives
503  * @return List of suggestions
504  */
505  private static ArrayList<Suggestion> alternativesToSuggestions(ArrayList<Alternative> alternatives) {
506  ArrayList<Suggestion> sugAlternativeToPersist = new ArrayList<Suggestion>();
507 
508  for (Iterator<Alternative> altIt = alternatives.iterator(); altIt.hasNext(); ) {
509  Alternative alt = altIt.next();
510  sugAlternativeToPersist.add(new Suggestion(alt));
511  }
512 
513  return sugAlternativeToPersist;
514  }
515 
516  /**
517  * Delete all alternatives for actual document.
518  */
520  Integer documentId = requestInfo.getSession().getSyncDocument().getId();
521 
522  // get alternatives for document from database
523  Object[] params = {"sourceDocumentId",documentId};
524  @SuppressWarnings("unchecked")
525  List<Alternative> suggestionList = AppBean.getPersistenceManager().queryDB("Alternative.findBySourceDocumentID",params);
526 
527  // delete alternatives from db
528  if (suggestionList != null && !suggestionList.isEmpty()) {
529  deleteAlternatives(suggestionList);
530  }
531  }
532 
533  /**
534  * Sets alternatives as used
535  *
536  * @param alternatives Alternatives which should be set as used
537  */
538  private static void setAsUsed(List<Alternative> alternatives) {
539  EntityManager em = AppBean.getPersistenceManager().getEM();
540  EntityTransaction transaction = em.getTransaction();
541 
542  try {
543  transaction.begin();
544  Iterator<Alternative> altIt = alternatives.iterator();
545  while (altIt.hasNext()) {
546  Alternative alt = altIt.next();
547  Object[] params = {"id",alt.getId()};
548  @SuppressWarnings("unchecked")
549  List<Alternative> alternativeList = AppBean.getPersistenceManager().queryDB("Alternative.findById", params);
550  if (alternativeList == null || alternativeList.isEmpty()) {
552  String msg = "Error during the setting of alternative usages (alternative was not found).";
553  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg);
554  }
555  continue;
556  }
557  Alternative a = alternativeList.get(0);
558  a.setUsed(true);
559  em.merge(a);
560  }
561  em.flush();
562  transaction.commit();
563  } catch (Exception e) {
564  transaction.rollback();
566  String msg = "Exception during the setting of alternative usages.";
567  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, e);
568  }
569  } finally {
570  em.close();
571  }
572  } // setAsUsed()
573 
574  /**
575  * Delete alternatives from DB
576  *
577  * @param alternativeToPersist Alternatives which should be deleted
578  */
579  private static void deleteAlternatives(List<Alternative> alternativeToPersist) {
580  EntityManager em = AppBean.getPersistenceManager().getEM();
581  EntityTransaction transaction = em.getTransaction();
582 
583  try {
584  transaction.begin();
585  for (Iterator<Alternative> altIt = alternativeToPersist.iterator(); altIt.hasNext(); ) {
586  Integer altId = altIt.next().getId();
587  // remove attributes
588  Query q = em.createNamedQuery("AlternativeAttribute.deleteByAltId");
589  q.setParameter("altId", altId);
590  q.executeUpdate();
591  // remove fragments
592  q = em.createNamedQuery("AlternativeFragment.deleteByAltId");
593  q.setParameter("altId", altId);
594  q.executeUpdate();
595  // remove alternative
596  q = em.createNamedQuery("Alternative.deleteById");
597  q.setParameter("id", altId);
598  q.executeUpdate();
599  }
600  em.flush();
601  transaction.commit();
602  } catch (Exception e) {
603  transaction.rollback();
605  String msg = "Exception during the deleting of data.";
606  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, e);
607  }
608  } finally {
609  em.close();
610  }
611  }
612 
613  /**
614  * Set isFromSECAPI flag of suggestion to false.
615  *
616  * @param confirmSuggs List of suggestions.
617  */
618  private static void clearIsFromSECAPI(ArrayList<Suggestion> confirmSuggs) {
619  EntityManager em = AppBean.getPersistenceManager().getEM();
620  EntityTransaction transaction = em.getTransaction();
621 
622  try {
623  transaction.begin();
624  for (Iterator<Suggestion> sugIt = confirmSuggs.iterator(); sugIt.hasNext(); ) {
625  Suggestion sug = sugIt.next();
626  // get id of suggestion
627  Integer sugId;
628  Suggestion alternativeOf = sug.getAlternativeOfSuggestion();
629  if (alternativeOf == null) {
630  sugId = sug.getId();
631  } else {
632  sugId = alternativeOf.getId();
633  }
634  // set isFromSECAPI flag to false
635  Query q = em.createNamedQuery("Suggestion.clearIsFromSECAPI");
636  q.setParameter("id", sugId);
637  q.executeUpdate();
638  }
639  em.flush();
640  transaction.commit();
641  } catch (Exception e) {
642  transaction.rollback();
644  String msg = "Exception during the updating of data.";
645  Logger.getLogger(AlternativeManager.class.getName()).log(Level.SEVERE, msg, e);
646  }
647  } finally {
648  em.close();
649  }
650  } // clearIsFromSECAPI()
651 
652  /**
653  * Method loads alternative specified by alternativeOf from the database.
654  *
655  * @param alternativeOfId AlternativeOf id.
656  * @return list of querried alternatives
657  */
658  private static List<Alternative> getAlternatives(int alternativeOfId) {
659  Integer id = alternativeOfId;
660  Object[] params = {"alternativeOf",id.toString()};
661  @SuppressWarnings("unchecked")
662  List<Alternative> alternativeList = AppBean.getPersistenceManager().queryDB("Alternative.findByAlternativeOf",params);
663  if (alternativeList == null) {
664  alternativeList = new ArrayList<Alternative>();
665  }
666  return alternativeList;
667  }
668 
669  /**
670  * Method loads alternative specified by alternativeOf from the database.
671  *
672  * @param alternativeOfId AlternativeOf id.
673  * @return list of querried alternatives
674  */
675  public static List<Suggestion> getOtherSuggestions(int alternativeOfId) {
676  Integer id = alternativeOfId;
677  Object[] params = {"alternativeOf",id.toString()};
678  @SuppressWarnings("unchecked")
679  List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB("Suggestion.findByAlternativeOf",params);
680  if (suggestionList == null) {
681  suggestionList = new ArrayList<Suggestion>();
682  }
683  return suggestionList;
684  }
685 
686  /**
687  * Method loads alternative specified by alternativeOf from the database.
688  *
689  * @param alternativeOfId AlternativeOf id.
690  * @param notThisSugId All alternatives except alternative suggestion with this id
691  * @return list of querried alternatives
692  */
693  private static List<Suggestion> getOtherSuggestions(int alternativeOfId, int notThisSugId) {
694  Integer id = alternativeOfId;
695  Object[] params = {"alternativeOf",id.toString(), "notThisSugId", (Integer) notThisSugId};
696  @SuppressWarnings("unchecked")
697  List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB("Suggestion.findByAlternativeOfAndNotSugg",params);
698  if (suggestionList == null) {
699  suggestionList = new ArrayList<Suggestion>();
700  }
701  return suggestionList;
702  }
703 } // public class AlternativeManager
Singleton for storing global variables.
Definition: AppBean.java:47
Interface for call of SEC API as external program (deamon)
Methods for translating output from SEC API to the Suggestion objects.
static void confirmSuggestions(RequestInfo request, ArrayList< Suggestion > confirmSuggs)
Class provides offerining of suggestions with usage of local knowledge repository.
Static class which persists suggestion data to the database.
Class representing type of annotation.
Definition: AnnotType.java:58
AlternativeManager(RequestInfo request, String document, String documentUri, ArrayList< Suggestion > validSuggestions, SuggestionManager sugManager, Integer docID)
static boolean overlappingFragment(ArrayList< SuggestionFragment > sugFragments, int newFragStart, int newFragEnd)
static ArrayList< Suggestion > alternativesToSuggestions(ArrayList< Alternative > alternatives)
Processed informations about client request.
Class representing suggestion of annotation.
Definition: Suggestion.java:87
static void refuseSuggestions(RequestInfo request, ArrayList< Suggestion > suggestionsToRefuse)
static List< Suggestion > getOtherSuggestions(int alternativeOfId, int notThisSugId)
Informations about client session.