Skip to main content
summaryrefslogtreecommitdiffstats
blob: 07609a39ad4cd5e2f175e095a2197af6addb7728 (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
/*******************************************************************************
 * Copyright (c) 2009 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.framework.core.message;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity;
import org.eclipse.osee.framework.core.enums.StorageState;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.core.services.IOseeCachingService;

/**
 * @author Roberto E. Escobar
 */
public class RelationTypeCacheUpdateResponse {

   private final List<RelationTypeRow> rows;

   public RelationTypeCacheUpdateResponse(List<RelationTypeRow> rows) {
      this.rows = rows;
   }

   public List<RelationTypeRow> getRelationTypeRows() {
      return rows;
   }

   public static final class RelationTypeRow {
      private final int id;
      private final String name;
      private final long guid;
      private StorageState storageState;

      private final String sideAName;
      private final String sideBName;
      private final int artifactTypeSideA;
      private final int artifactTypeSideB;
      private final RelationTypeMultiplicity multiplicity;
      private final String defaultOrderTypeGuid;

      public RelationTypeRow(int id, String name, long guid, StorageState storageState, String sideAName, String sideBName, int artifactTypeSideA, int artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) {
         super();
         this.id = id;
         this.name = name;
         this.guid = guid;
         this.storageState = storageState;
         this.sideAName = sideAName;
         this.sideBName = sideBName;
         this.artifactTypeSideA = artifactTypeSideA;
         this.artifactTypeSideB = artifactTypeSideB;
         this.multiplicity = multiplicity;
         this.defaultOrderTypeGuid = defaultOrderTypeGuid;
      }

      public int getArtifactTypeSideA() {
         return artifactTypeSideA;
      }

      public int getArtifactTypeSideB() {
         return artifactTypeSideB;
      }

      public int getId() {
         return id;
      }

      public String getName() {
         return name;
      }

      public long getGuid() {
         return guid;
      }

      public StorageState getStorageState() {
         return storageState;
      }

      public void setStorageState(StorageState storageState) {
         this.storageState = storageState;
      }

      public String getSideBName() {
         return sideBName;
      }

      public String getSideAName() {
         return sideAName;
      }

      public String getDefaultOrderTypeGuid() {
         return defaultOrderTypeGuid;
      }

      public RelationTypeMultiplicity getMultiplicity() {
         return multiplicity;
      }

      public String[] toArray() {
         return new String[] {
            String.valueOf(getId()),
            String.valueOf(getGuid()),
            getName(),
            getStorageState().name(),
            getSideAName(),
            getSideBName(),
            String.valueOf(getArtifactTypeSideA()),
            String.valueOf(getArtifactTypeSideB()),
            getMultiplicity().name(),
            getDefaultOrderTypeGuid()};
      }

      public static RelationTypeRow fromArray(String[] data) {
         int index = 0;

         int id = Integer.valueOf(data[index++]);
         long guid = Long.valueOf(data[index++]);
         String name = data[index++];
         StorageState storageState = StorageState.valueOf(data[index++]);

         String sideAName = data[index++];
         String sideBName = data[index++];
         int artifactTypeSideA = Integer.valueOf(data[index++]);
         int artifactTypeSideB = Integer.valueOf(data[index++]);
         RelationTypeMultiplicity multiplicity = RelationTypeMultiplicity.valueOf(data[index++]);
         String defaultOrderTypeGuid = data[index++];

         return new RelationTypeRow(id, name, guid, storageState, sideAName, sideBName, artifactTypeSideA,
            artifactTypeSideB, multiplicity, defaultOrderTypeGuid);
      }
   }

   public static RelationTypeCacheUpdateResponse fromCache(IOseeCachingService caching) throws OseeCoreException {
      Collection<RelationType> relationTypes = caching.getRelationTypeCache().getAll();
      ArtifactTypeCache artifactTypeCache = caching.getArtifactTypeCache();

      List<RelationTypeRow> rows = new ArrayList<RelationTypeRow>();
      for (RelationType item : relationTypes) {
         int artifactTypeSideA = artifactTypeCache.get(item.getArtifactTypeSideA()).getId();
         int artifactTypeSideB = artifactTypeCache.get(item.getArtifactTypeSideB()).getId();

         rows.add(new RelationTypeRow(item.getId(), item.getName(), item.getGuid(), item.getStorageState(),
            item.getSideAName(), item.getSideBName(), artifactTypeSideA, artifactTypeSideB, item.getMultiplicity(),
            item.getDefaultOrderTypeGuid()));
      }
      return new RelationTypeCacheUpdateResponse(rows);
   }
}

Back to the top