Skip to main content
summaryrefslogtreecommitdiffstats
blob: 887efa58ab2454d97c7a5b2ec12a1de17f701187 (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
/*******************************************************************************
 * 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.core.client.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.ats.api.data.AtsRelationTypes;
import org.eclipse.osee.ats.core.client.action.ActionArtifact;
import org.eclipse.osee.ats.core.client.internal.Activator;
import org.eclipse.osee.ats.core.client.internal.AtsClientService;
import org.eclipse.osee.ats.core.client.review.AtsReviewCache;
import org.eclipse.osee.ats.core.client.task.AbstractTaskableArtifact;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.client.util.AtsTaskCache;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.ui.skynet.util.DbConnectionUtility;

/**
 * @author Donald G. Dunne
 */
public class AtsBulkLoad {

   private static AtomicBoolean atsTypeDataLoadedStarted = new AtomicBoolean(false);

   public static List<IOperation> getConfigLoadingOperations() {
      List<IOperation> ops = new ArrayList<>();
      if (atsTypeDataLoadedStarted.compareAndSet(false, true) && DbConnectionUtility.isVersionSupported()) {
         IOperation op = new AbstractOperation("Re-load ATS Config", Activator.PLUGIN_ID) {
            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               AtsClientService.get().reloadAllCaches();
            }
         };
         ops.add(op);
      } else {
         ops.add(Operations.createNoOpOperation("ATS Bulk Loading"));
      }
      return ops;
   }

   public static void reloadConfig(boolean pend) throws OseeCoreException {
      if (pend) {
         AtsClientService.get().reloadAllCaches();
      } else {
         AtsClientService.get().invalidateAllCaches();
      }
   }

   public static Set<Artifact> bulkLoadArtifacts(Collection<? extends Artifact> artifacts) throws OseeCoreException {
      List<Artifact> actions = new ArrayList<>();
      List<Artifact> teams = new ArrayList<>();
      for (Artifact art : artifacts) {
         if (art instanceof ActionArtifact) {
            actions.add(art);
         } else if (art instanceof TeamWorkFlowArtifact) {
            teams.add(art);
         }
      }
      Set<Artifact> arts =
         RelationManager.getRelatedArtifacts(actions, 3, AtsRelationTypes.TeamWfToTask_Task,
            AtsRelationTypes.TeamWorkflowToReview_Review, AtsRelationTypes.ActionToWorkflow_Action);
      arts.addAll(RelationManager.getRelatedArtifacts(teams, 4, AtsRelationTypes.TeamWfToTask_Task,
         AtsRelationTypes.ActionToWorkflow_WorkFlow, AtsRelationTypes.TeamWorkflowToReview_Review));
      arts.addAll(artifacts);
      for (Artifact art : arts) {
         if (art instanceof AbstractTaskableArtifact) {
            AtsTaskCache.getTaskArtifacts((AbstractTaskableArtifact) art);
         }
         if (art instanceof TeamWorkFlowArtifact) {
            AtsReviewCache.getReviewArtifacts((TeamWorkFlowArtifact) art);
         }
      }
      return arts;
   }
}

Back to the top