Skip to main content
summaryrefslogtreecommitdiffstats
blob: 286e0b8dc900161100572b39fe220b2a2253a0b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.server.admin.search;

import java.util.Set;
import java.util.logging.Level;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.operation.OperationLogger;
import org.eclipse.osee.framework.database.core.JoinUtility;
import org.eclipse.osee.framework.database.core.TagQueueJoinQuery;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.search.engine.TagListenerAdapter;
import org.eclipse.osee.framework.server.admin.internal.Activator;

/**
 * @author Roberto E. Escobar
 */
public class TagItemOperation extends AbstractOperation {
   private final Set<Long> gammas;
   private TagListener tagListener = null;

   public TagItemOperation(OperationLogger logger, Set<Long> gammas) {
      super("Tag Individual Items", Activator.PLUGIN_ID, logger);
      this.gammas = gammas;
   }

   private final class TagListener extends TagListenerAdapter {
      private int joinQuery;
      private boolean isProcessing;

      public TagListener() {
         this.isProcessing = true;
         this.joinQuery = -1;
      }

      @Override
      public void onTagQueryIdSubmit(int queryId) {
         joinQuery = queryId;
      }

      public boolean isProcessing() {
         return isProcessing;
      }

      @Override
      public void onAttributeTagComplete(int queryId, long gammaId, int totalTags, long processingTime) {
         if (queryId == joinQuery) {
            logf("GammaId: [%d] Tags: [%d] Processed In: [%d] ms", gammaId, totalTags, processingTime);
         }
      }

      @Override
      synchronized public void onTagQueryIdTagComplete(int queryId, long waitTime, long processingTime) {
         if (queryId == joinQuery) {
            this.isProcessing = false;
            this.notify();
         }
      }

      @Override
      public void onAttributeAddTagEvent(int queryId, long gammaId, String word, long codedTag) {
         if (queryId == joinQuery) {
            logf("QueryId: [%d] GammaId: [%d] Word: [%s] Tag: [%d]", queryId, gammaId, word, codedTag);
         }
      }

   }

   @Override
   protected void doWork(IProgressMonitor monitor) throws OseeCoreException {
      tagListener = null;
      final Set<Long> toTag = gammas;
      if (!toTag.isEmpty()) {
         TagQueueJoinQuery joinQuery = JoinUtility.createTagQueueJoinQuery();
         for (Long item : toTag) {
            joinQuery.add(item);
         }
         joinQuery.store();

         tagListener = new TagListener();
         Activator.getSearchTagger().tagByQueueQueryId(tagListener, joinQuery.getQueryId());
         synchronized (tagListener) {
            try {
               tagListener.wait();
            } catch (InterruptedException ex) {
               OseeLog.log(Activator.class, Level.SEVERE, ex);
            }
         }
         if (tagListener.isProcessing()) {
            joinQuery.delete();
         }

      } else {
         log("No Items to Tag.");
      }
   }
}

Back to the top