Skip to main content
summaryrefslogtreecommitdiffstats
blob: 43589654040e3b59e1f85e6965a42fc562a366df (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*******************************************************************************
 * Copyright (c) 2011 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.display.presenter.mocks;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
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.IRelationType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.data.ResultSet;
import org.eclipse.osee.framework.core.data.ResultSetList;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.jdk.core.type.HashCollection;
import org.eclipse.osee.framework.jdk.core.type.Identity;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.AttributeId;
import org.eclipse.osee.orcs.data.AttributeReadable;

/**
 * @author John R. Misinco
 */
public class MockArtifact implements ArtifactReadable {

   private final Map<IRelationTypeSide, List<ArtifactReadable>> relationMap =
      new HashMap<IRelationTypeSide, List<ArtifactReadable>>();
   private final Set<RelationType> validRelationTypes = new LinkedHashSet<RelationType>();

   private final HashCollection<IAttributeType, String> attributes = new HashCollection<IAttributeType, String>();

   private final String name, guid;
   private final IArtifactType type;
   private final IOseeBranch branch;
   private ArtifactReadable parent;

   public MockArtifact(String guid, String name) {
      this(guid, name, CoreArtifactTypes.Artifact, CoreBranches.COMMON);
   }

   public MockArtifact(String guid, String name, IArtifactType type, IOseeBranch branch) {
      this.guid = guid;
      this.name = name;
      this.type = type;
      this.branch = branch;
      addAttribute(CoreAttributeTypes.Name, name);
   }

   public void setParent(ArtifactReadable parent) {
      this.parent = parent;
   }

   public void addAttribute(IAttributeType type, String value) {
      attributes.put(type, value);
   }

   @Override
   public Collection<RelationType> getValidRelationTypes() {
      return validRelationTypes;
   }

   public void addRelationType(RelationType relationType) {
      validRelationTypes.add(relationType);
   }

   public ResultSet<ArtifactReadable> getRelatedArtifacts(IRelationTypeSide side) {
      List<ArtifactReadable> data = relationMap.get(side);
      if (data == null) {
         data = Collections.emptyList();
      }
      return new ResultSetList<ArtifactReadable>(data);
   }

   public void addRelation(IRelationTypeSide relation, ArtifactReadable artifact) {
      List<ArtifactReadable> artList = relationMap.get(relation);
      if (artList == null) {
         artList = new LinkedList<ArtifactReadable>();
         relationMap.put(relation, artList);
      }
      artList.add(artifact);
      RelationType type =
         new RelationType(relation.getGuid(), relation.getName(), "sideA", "sideB", CoreArtifactTypes.Artifact,
            CoreArtifactTypes.Artifact, RelationTypeMultiplicity.MANY_TO_MANY, "");
      addRelationType(type);
   }

   @Override
   public int getLocalId() {
      return 0;
   }

   @Override
   public IOseeBranch getBranch() {
      return branch;
   }

   @Override
   public int getTransaction() {
      return 0;
   }

   @Override
   public IArtifactType getArtifactType() {
      return type;
   }

   @Override
   public Collection<IAttributeType> getExistingAttributeTypes() {
      return attributes.keySet();
   }

   @SuppressWarnings({"unchecked", "rawtypes"})
   @Override
   public <T> ResultSet<AttributeReadable<T>> getAttributes(IAttributeType attributeType) {
      Collection<String> values = attributes.getValues(attributeType);
      List<AttributeReadable<T>> toReturn = null;
      if (values != null && !values.isEmpty()) {
         toReturn = new LinkedList<AttributeReadable<T>>();
         for (String value : values) {
            AttributeReadable<T> attr = new MockAttribute(attributeType, value);
            toReturn.add(attr);
         }
      } else {
         toReturn = Collections.emptyList();
      }
      return new ResultSetList<AttributeReadable<T>>(toReturn);
   }

   @Override
   public String getSoleAttributeAsString(IAttributeType attributeType) {
      return null;
   }

   @Override
   public String getGuid() {
      return guid;
   }

   @Override
   public boolean matches(Identity<?>... identities) {
      return false;
   }

   @Override
   public String getName() {
      return name;
   }

   @Override
   public ResultSet<AttributeReadable<Object>> getAttributes() {
      List<AttributeReadable<Object>> toReturn = new ArrayList<AttributeReadable<Object>>();
      for (Entry<IAttributeType, Collection<String>> entry : attributes.entrySet()) {
         for (String value : entry.getValue()) {
            toReturn.add(new MockAttribute<Object>(entry.getKey(), value));
         }
      }
      return new ResultSetList<AttributeReadable<Object>>(toReturn);
   }

   public void clearRelations() {
      validRelationTypes.clear();
      relationMap.clear();
   }

   @Override
   public String getSoleAttributeAsString(IAttributeType attributeType, String defaultValue) {
      return null;
   }

   @Override
   public boolean isOfType(IArtifactType... otherTypes) {
      return false;
   }

   @Override
   public <T> T getSoleAttributeValue(IAttributeType attributeType) {
      return null;
   }

   @Override
   public boolean isAttributeTypeValid(IAttributeType attributeType) {
      return false;
   }

   @Override
   public int getAttributeCount(IAttributeType type) throws OseeCoreException {
      return attributes.getValues(type).size();
   }

   @Override
   public <T> List<T> getAttributeValues(IAttributeType attributeType) throws OseeCoreException {
      return null;
   }

   @Override
   public Collection<? extends IAttributeType> getValidAttributeTypes() throws OseeCoreException {
      return null;
   }

   @Override
   public boolean isDeleted() {
      return false;
   }

   @Override
   public int getAttributeCount(IAttributeType type, DeletionFlag deletionFlag) throws OseeCoreException {
      return 0;
   }

   @Override
   public ResultSet<AttributeReadable<Object>> getAttributes(DeletionFlag deletionFlag) throws OseeCoreException {
      return null;
   }

   @Override
   public <T> ResultSet<AttributeReadable<T>> getAttributes(IAttributeType attributeType, DeletionFlag deletionFlag) throws OseeCoreException {
      return null;
   }

   @Override
   public AttributeReadable<Object> getAttributeById(AttributeId attributeId) throws OseeCoreException {
      return null;
   }

   @Override
   public int getMaximumRelationAllowed(IRelationTypeSide relationTypeSide) throws OseeCoreException {
      return 0;
   }

   @Override
   public Collection<? extends IRelationType> getExistingRelationTypes() throws OseeCoreException {
      return null;
   }

   @Override
   public ArtifactReadable getParent() throws OseeCoreException {
      return null;
   }

   @Override
   public ResultSet<ArtifactReadable> getChildren() throws OseeCoreException {
      return null;
   }

   @Override
   public ResultSet<ArtifactReadable> getRelated(IRelationTypeSide relationTypeSide) throws OseeCoreException {
      return null;
   }

   @Override
   public boolean areRelated(IRelationTypeSide typeAndSide, ArtifactReadable readable) throws OseeCoreException {
      return false;
   }

   @Override
   public int getRelatedCount(IRelationTypeSide typeAndSide) throws OseeCoreException {
      return 0;
   }

   @Override
   public String getRationale(IRelationTypeSide typeAndSide, ArtifactReadable readable) throws OseeCoreException {
      return null;
   }

}

Back to the top