Skip to main content
summaryrefslogtreecommitdiffstats
blob: 921d45b2a0c1cf18c204f97bdb1e8b45b67d9b1a (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
/*******************************************************************************
 * Copyright (c) 2015 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.orcs.rest.internal.writer;

import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.orcs.OrcsApi;

/**
 * @author Donald G. Dunne
 */
public class OrcsValidationHelperAdapter implements IOrcsValidationHelper {

   private final OrcsApi orcsApi;

   public OrcsValidationHelperAdapter(OrcsApi orcsApi) {
      this.orcsApi = orcsApi;
   }

   @Override
   public boolean isBranchExists(BranchId branch) {
      return orcsApi.getQueryFactory().branchQuery().andIds(branch).getResultsAsId().size() == 1;
   }

   @Override
   public boolean isUserExists(String userId) {
      return orcsApi.getQueryFactory().fromBranch(COMMON).and(CoreAttributeTypes.UserId,
         userId).getResults().getAtMostOneOrNull() != null;
   }

   @Override
   public boolean isArtifactExists(BranchId branch, long artifactUuid) {
      int matchedArtifacts = orcsApi.getQueryFactory().fromBranch(branch).andUuid(artifactUuid).getResults().size();
      return matchedArtifacts == 1;
   }

   @Override
   public boolean isArtifactTypeExist(long artifactTypeUuid) {
      return orcsApi.getOrcsTypes().getArtifactTypes().get(artifactTypeUuid) != null;
   }

   @Override
   public boolean isRelationTypeExist(long relationTypeUuid) {
      return orcsApi.getOrcsTypes().getRelationTypes().get(relationTypeUuid) != null;
   }

   @Override
   public boolean isAttributeTypeExists(long attributeTypeUuid) {
      return orcsApi.getOrcsTypes().getAttributeTypes().get(attributeTypeUuid) != null;
   }

   @Override
   public boolean isAttributeTypeExists(String attributeTypeName) {
      for (IAttributeType type : orcsApi.getOrcsTypes().getAttributeTypes().getAll()) {
         if (type.getName().equals(attributeTypeName)) {
            return true;
         }
      }
      return false;
   }

}

Back to the top