Skip to main content
summaryrefslogtreecommitdiffstats
blob: fe1ce9ab5dbb3f8d5de0aef3f5a5908e3eb44e07 (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
/*******************************************************************************
 * 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;

/**
 * Donald G. Dunne
 */
import org.eclipse.osee.framework.core.data.ArtifactToken;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.RelationTypeSide;
import org.eclipse.osee.framework.core.data.RelationTypeToken;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwArtifact;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwArtifactToken;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwArtifactType;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwAttribute;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwAttributeType;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwBranch;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwRelationType;

public class OwFactory {

   public static OwArtifactType createArtifactType(IArtifactType artType) {
      String typeStr = String.format("[%s]-[%d]", artType.getName(), artType.getGuid());
      OwArtifactType type = new OwArtifactType();
      type.setUuid(artType.getGuid());
      type.setName(artType.getName());
      type.setData(typeStr);
      return type;
   }

   public static OwAttributeType createAttributeType(IAttributeType attrType) {
      String typeStr = String.format("[%s]-[%d]", attrType.getName(), attrType.getGuid());
      OwAttributeType type = new OwAttributeType();
      type.setUuid(attrType.getGuid());
      type.setName(attrType.getName());
      type.setData(typeStr);
      return type;
   }

   public static OwArtifactToken createArtifactToken(ArtifactToken token) {
      return createArtifactToken(token.getName(), token.getUuid());
   }

   public static OwArtifactToken createArtifactToken(String name, long uuid) {
      String tokenStr = String.format("[%s]-[%d]", name, uuid);
      OwArtifactToken owToken = new OwArtifactToken();
      owToken.setUuid(uuid);
      owToken.setName(name);
      owToken.setData(tokenStr);
      return owToken;
   }

   public static OwRelationType createRelationType(RelationTypeToken relType, String sideName, boolean sideA) {
      String sideData =
         String.format("[%s]-[%s]-[Side %s]-[%s]", relType.getName(), sideName, sideA ? "A" : "B", relType.getId());
      OwRelationType owType = new OwRelationType();
      owType.setUuid(relType.getId());
      owType.setName(relType.getName());
      owType.setData(sideData);
      owType.setSideA(sideA);
      return owType;
   }

   public static OwRelationType createRelationType(OrcsApi orcsApi, RelationTypeSide type) {
      String sideAName = orcsApi.getOrcsTypes().getRelationTypes().getSideAName(type);
      OwRelationType owType = OwFactory.createRelationType(type, sideAName, true);
      return owType;
   }

   public static OwArtifact createArtifact(IArtifactType artifactType, String name) {
      return createArtifact(artifactType, name, null);
   }

   public static OwArtifact createArtifact(IArtifactType artifactType, String name, Long uuid) {
      OwArtifact artifact = new OwArtifact();
      OwArtifactType owArtType = OwFactory.createArtifactType(artifactType);
      artifact.setType(owArtType);
      if (uuid == null) {
         uuid = Lib.generateArtifactIdAsInt();
      }
      artifact.setUuid(uuid);
      artifact.setName(name);
      return artifact;
   }

   public static OwAttribute createAttribute(OwArtifact artifact, IAttributeType attrType, Object... values) {
      OwAttribute attribute = new OwAttribute();
      attribute.setType(OwFactory.createAttributeType(attrType));
      for (Object obj : values) {
         attribute.getValues().add(obj);
      }
      artifact.getAttributes().add(attribute);
      return attribute;
   }

   public static OwBranch createBranchToken(IOseeBranch branch) {
      String tokenStr = String.format("[%s]-[%d]", branch.getName(), branch.getUuid());
      OwBranch owBranch = new OwBranch();
      owBranch.setData(tokenStr);
      owBranch.setName(branch.getName());
      owBranch.setUuid(branch.getUuid());
      return owBranch;
   }
}

Back to the top