Skip to main content
summaryrefslogtreecommitdiffstats
blob: 06fc1692401778863468ba200084d971e7042631 (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
/*******************************************************************************
 * 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.search;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist;
import org.eclipse.osee.framework.core.exception.MultipleArtifactsExist;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;

/**
 * @author John Misinco
 */
public class AtsArtifactQuery {

   public static Artifact getArtifactFromId(String guidOrAtsId) throws OseeCoreException {
      List<Artifact> artifacts = new LinkedList<Artifact>();

      if (GUID.isValid(guidOrAtsId)) {
         artifacts.add(ArtifactQuery.getArtifactFromId(guidOrAtsId, AtsUtilCore.getAtsBranch()));
      } else {
         artifacts.addAll(ArtifactQuery.getArtifactListFromAttributeValues(AtsAttributeTypes.AtsId,
            Collections.singleton(guidOrAtsId), AtsUtilCore.getAtsBranch(), 1));
      }

      if (artifacts.isEmpty()) {
         throw new ArtifactDoesNotExist("AtsArtifactQuery: No artifact found with id %s on ATS branch", guidOrAtsId);
      }
      if (artifacts.size() > 1) {
         throw new MultipleArtifactsExist("%d artifacts found with id %s", artifacts.size(), guidOrAtsId);
      }
      return artifacts.iterator().next();
   }

   public static List<Artifact> getArtifactListFromIds(Collection<String> guidsOrAtsIds) throws OseeCoreException {
      List<Artifact> toReturn = new LinkedList<Artifact>();
      List<String> guids = new LinkedList<String>();
      List<String> atsIds = new LinkedList<String>();
      for (String guidOrAtsId : guidsOrAtsIds) {
         if (GUID.isValid(guidOrAtsId)) {
            guids.add(guidOrAtsId);
         } else {
            atsIds.add(guidOrAtsId.toUpperCase());
         }
      }

      if (!guids.isEmpty()) {
         List<Artifact> fromIds = ArtifactQuery.getArtifactListFromIds(guids, AtsUtilCore.getAtsBranch());
         toReturn.addAll(fromIds);
      }

      if (!atsIds.isEmpty()) {
         List<Artifact> fromIds =
            ArtifactQuery.getArtifactListFromAttributeValues(AtsAttributeTypes.AtsId, atsIds,
               AtsUtilCore.getAtsBranch(), atsIds.size());
         toReturn.addAll(fromIds);
      }

      return toReturn;
   }

   public static Artifact getArtifactFromId(long uuid) {
      return ArtifactQuery.getArtifactFromId((int) uuid, AtsUtilCore.getAtsBranch());
   }

   public static List<Artifact> getArtifactListFromIds(List<Long> uuids) {
      List<Artifact> toReturn = new LinkedList<Artifact>();
      List<Integer> artIds = new LinkedList<Integer>();

      for (Long uuid : uuids) {
         artIds.add(uuid.intValue());
      }

      List<Artifact> fromIds = ArtifactQuery.getArtifactListFromIds(artIds, AtsUtilCore.getAtsBranch());
      toReturn.addAll(fromIds);
      return toReturn;
   }

}

Back to the top