Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7559414c0d1299d78006a3e7180558c82e0428a5 (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
/*******************************************************************************
 * Copyright (c) 2013 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.internal.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.ats.api.IAtsConfigObject;
import org.eclipse.osee.ats.api.IAtsObject;
import org.eclipse.osee.ats.core.client.search.AtsArtifactQuery;
import org.eclipse.osee.ats.core.config.AtsConfigCache;
import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

/**
 * @author Donald G. Dunne
 */
public class AtsArtifactConfigCache extends AtsConfigCache {

   public List<Artifact> getArtifacts(Collection<? extends IAtsObject> atsObjects) throws OseeCoreException {
      List<Artifact> artifacts = new LinkedList<Artifact>();
      List<Long> uuids = new ArrayList<Long>();
      for (IAtsObject atsObject : atsObjects) {
         Artifact artifact = getArtifact(atsObject);
         if (artifact != null) {
            artifacts.add(artifact);
         } else {
            uuids.add(atsObject.getUuid());
         }
      }
      artifacts.addAll(AtsArtifactQuery.getArtifactListFromIds(uuids));
      return artifacts;
   }

   public <A extends IAtsConfigObject> Collection<A> getConfigObjects(Collection<? extends Artifact> artifacts, Class<A> clazz) {
      List<A> objects = new ArrayList<A>();
      for (Artifact art : artifacts) {
         objects.addAll(getByTag(art.getGuid(), clazz));
      }
      return objects;
   }

   public Artifact getArtifact(IAtsObject atsObject) throws OseeCoreException {
      Conditions.checkNotNull(atsObject, "atsConfigObject");
      Artifact artifact = (Artifact) atsObject.getStoreObject();
      if (artifact == null) {
         try {
            artifact = AtsArtifactQuery.getArtifactFromId(atsObject.getUuid());
         } catch (ArtifactDoesNotExist ex) {
            // do nothing
         }
      }
      return artifact;
   }

}

Back to the top