Skip to main content
summaryrefslogtreecommitdiffstats
blob: 701561aa108983cc1a5f4224132e0afd10ae1a7c (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*******************************************************************************
 * 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.ats.config;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.eclipse.osee.ats.artifact.AbstractTaskableArtifact;
import org.eclipse.osee.ats.artifact.ActionableItemArtifact;
import org.eclipse.osee.ats.artifact.TaskArtifact;
import org.eclipse.osee.ats.artifact.TeamDefinitionArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.AtsArtifactTypes;
import org.eclipse.osee.ats.util.AtsRelationTypes;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.Active;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
import org.eclipse.osee.framework.skynet.core.event.filter.IEventFilter;
import org.eclipse.osee.framework.skynet.core.event.listener.IArtifactEventListener;
import org.eclipse.osee.framework.skynet.core.event.model.ArtifactEvent;
import org.eclipse.osee.framework.skynet.core.event.model.EventBasicGuidArtifact;
import org.eclipse.osee.framework.skynet.core.event.model.EventBasicGuidRelation;
import org.eclipse.osee.framework.skynet.core.event.model.EventModType;
import org.eclipse.osee.framework.skynet.core.event.model.Sender;
import org.eclipse.osee.framework.skynet.core.relation.RelationEventType;
import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkFlowDefinition;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkItemDefinition.WriteType;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkItemDefinitionFactory;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkPageDefinition;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkRuleDefinition;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkWidgetDefinition;

/**
 * Common cache storage for ATS configuration artifacts:<br>
 * TeamDefinitionArtifact<br>
 * VersionArtifact<br>
 * ActionableItemArtifact<br>
 * All other artifact types will silently not cached<br>
 * 
 * @author Donald G. Dunne
 */
public class AtsCacheManager implements IArtifactEventListener {

   private static Map<AbstractTaskableArtifact, Collection<TaskArtifact>> teamTasksCache =
      new HashMap<AbstractTaskableArtifact, Collection<TaskArtifact>>();

   public static void start() {
      new AtsCacheManager();
   }

   private AtsCacheManager() {
      OseeEventManager.addPriorityListener(this);
   }

   public static synchronized void decacheTaskArtifacts(AbstractTaskableArtifact sma) {
      teamTasksCache.remove(sma);
   }

   public static synchronized Collection<TaskArtifact> getTaskArtifacts(AbstractTaskableArtifact sma) throws OseeCoreException {
      if (!teamTasksCache.containsKey(sma)) {
         Collection<TaskArtifact> taskArtifacts =
            sma.getRelatedArtifacts(AtsRelationTypes.SmaToTask_Task, TaskArtifact.class);
         if (taskArtifacts.isEmpty()) {
            return taskArtifacts;
         }
         teamTasksCache.put(sma, taskArtifacts);
      }
      return teamTasksCache.get(sma);
   }

   public static List<Artifact> getArtifactsByName(IArtifactType artifactType, String name) throws OseeCoreException {
      AtsBulkLoad.loadConfig(true);
      return ArtifactCache.getArtifactsByName(artifactType, name);
   }

   public static ActionableItemArtifact getActionableItemByGuid(String guid) throws OseeCoreException {
      AtsBulkLoad.loadConfig(true);
      return (ActionableItemArtifact) ArtifactCache.getActive(guid, AtsUtil.getAtsBranch().getId());
   }

   public static TeamDefinitionArtifact getTeamDefinitionArtifact(String guid) throws OseeCoreException {
      AtsBulkLoad.loadConfig(true);
      return (TeamDefinitionArtifact) ArtifactCache.getActive(guid, AtsUtil.getAtsBranch().getId());
   }

   public static List<Artifact> getArtifactsByActive(IArtifactType artifactType, Active active) throws OseeCoreException {
      AtsBulkLoad.loadConfig(true);
      return AtsUtil.getActive(ArtifactCache.getArtifactsByType(artifactType), active, null);
   }

   public static Artifact getSoleArtifactByName(IArtifactType artifactType, String name) throws OseeCoreException {
      AtsBulkLoad.loadConfig(true);
      List<Artifact> arts = ArtifactCache.getArtifactsByName(artifactType, name);
      if (arts.size() == 1) {
         return arts.iterator().next();
      }
      return null;
   }

   @Override
   public void handleArtifactEvent(ArtifactEvent artifactEvent, Sender sender) {
      if (DbUtil.isDbInit()) {
         OseeEventManager.removeListener(this);
         return;
      }
      try {
         for (EventBasicGuidArtifact guidArt : artifactEvent.getArtifacts()) {
            try {
               if (guidArt.is(EventModType.Deleted, EventModType.Purged)) {
                  if (guidArt.is(CoreArtifactTypes.WorkRuleDefinition, CoreArtifactTypes.WorkPageDefinition,
                     CoreArtifactTypes.WorkFlowDefinition, CoreArtifactTypes.WorkWidgetDefinition)) {
                     WorkItemDefinitionFactory.deCache(guidArt);
                  }
                  if (guidArt.is(AtsArtifactTypes.Task) && guidArt.is(EventModType.Deleted)) {
                     Artifact artifact = ArtifactCache.getActive(guidArt);
                     if (artifact != null) {
                        teamTasksCache.remove(artifact.getParent());
                     }
                  }
                  Artifact artifact = ArtifactCache.getActive(guidArt);
                  if (artifact != null && artifact instanceof AbstractTaskableArtifact) {
                     teamTasksCache.remove(artifact);
                  }
               }
               if (guidArt.is(EventModType.Added, EventModType.Modified)) {
                  if (guidArt.is(CoreArtifactTypes.WorkRuleDefinition, CoreArtifactTypes.WorkPageDefinition,
                     CoreArtifactTypes.WorkFlowDefinition, CoreArtifactTypes.WorkWidgetDefinition)) {
                     // Must load these cause they are config artifacts
                     Artifact artifact = ArtifactQuery.getArtifactFromToken(guidArt);
                     if (artifact != null) {
                        if (guidArt.is(CoreArtifactTypes.WorkRuleDefinition)) {
                           WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update,
                              new WorkRuleDefinition(artifact), artifact);
                        } else if (artifact.isOfType(CoreArtifactTypes.WorkPageDefinition)) {
                           WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update,
                              new WorkPageDefinition(artifact), artifact);
                        } else if (artifact.isOfType(CoreArtifactTypes.WorkWidgetDefinition)) {
                           WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update,
                              new WorkWidgetDefinition(artifact), artifact);
                        } else if (artifact.isOfType(CoreArtifactTypes.WorkFlowDefinition)) {
                           WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update,
                              new WorkFlowDefinition(artifact), artifact);
                        }
                     }
                  }
                  // Only process if in cache
                  Artifact artifact = ArtifactCache.getActive(guidArt);
                  if (artifact != null && guidArt.is(EventModType.Added)) {
                     if (artifact instanceof TaskArtifact) {
                        teamTasksCache.remove(artifact.getParent());
                     }
                     if (artifact instanceof AbstractTaskableArtifact) {
                        teamTasksCache.remove(artifact);
                     }
                  }
               }
            } catch (OseeCoreException ex) {
               OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
            }
         }
         for (EventBasicGuidRelation guidRel : artifactEvent.getRelations()) {
            try {
               if (guidRel.is(AtsRelationTypes.SmaToTask_Task)) {
                  for (TaskArtifact taskArt : ArtifactCache.getActive(guidRel, TaskArtifact.class)) {
                     teamTasksCache.remove(taskArt.getParent());
                  }
                  for (Artifact artifact : ArtifactCache.getActive(guidRel)) {
                     if (artifact instanceof AbstractTaskableArtifact) {
                        teamTasksCache.remove(artifact);
                     }
                  }
               }
            } catch (OseeCoreException ex) {
               OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
            }
         }
         for (Artifact artifact : artifactEvent.getArtifactsInRelations(CoreRelationTypes.WorkItem__Child,
            RelationEventType.Added, RelationEventType.Undeleted)) {
            if (artifact.isOfType(CoreArtifactTypes.WorkRuleDefinition)) {
               WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update, new WorkRuleDefinition(
                  artifact), artifact);
            } else if (artifact.isOfType(CoreArtifactTypes.WorkPageDefinition)) {
               WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update, new WorkPageDefinition(
                  artifact), artifact);
            } else if (artifact.isOfType(CoreArtifactTypes.WorkWidgetDefinition)) {
               WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update, new WorkWidgetDefinition(
                  artifact), artifact);
            } else if (artifact.isOfType(CoreArtifactTypes.WorkFlowDefinition)) {
               WorkItemDefinitionFactory.cacheWorkItemDefinitionArtifact(WriteType.Update, new WorkFlowDefinition(
                  artifact), artifact);
            }
         }

      } catch (OseeCoreException ex) {
         OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
      }
   }

   @Override
   public List<? extends IEventFilter> getEventFilters() {
      return Arrays.asList(OseeEventManager.getCommonBranchFilter());
   }
}

Back to the top