Skip to main content
summaryrefslogtreecommitdiffstats
blob: ad39c2689cf278f2d0f4dd7f62f6da15396f13b8 (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
/*******************************************************************************
 * 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.orcs.core.internal.relation;

import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.enums.RelationSide;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.core.ds.HasOrcsData;
import org.eclipse.osee.orcs.core.ds.RelationData;
import org.eclipse.osee.orcs.core.internal.util.OrcsWriteable;
import org.eclipse.osee.orcs.data.RelationTypes;

/**
 * @author Roberto E. Escobar
 */
public class Relation implements HasOrcsData<RelationData>, OrcsWriteable {

   private final RelationTypes relationTypes;

   private RelationData relationData;
   private boolean isDirty;

   public Relation(RelationTypes relationTypes, RelationData relationData) {
      super();
      this.relationTypes = relationTypes;
      this.relationData = relationData;
   }

   @Override
   public RelationData getOrcsData() {
      return relationData;
   }

   @Override
   public void setOrcsData(RelationData data) {
      this.relationData = data;
   }

   public IRelationType getRelationType() throws OseeCoreException {
      return relationTypes.getByUuid(getOrcsData().getTypeUuid());
   }

   public ModificationType getModificationType() {
      return getOrcsData().getModType();
   }

   @Override
   public boolean isDeleted() {
      return getModificationType().isDeleted();
   }

   @Override
   public void delete() {
      markAsChanged(ModificationType.DELETED);
   }

   @Override
   public boolean isDirty() {
      return isDirty;
   }

   public void clearDirty() {
      setDirtyFlag(false);
   }

   public void setDirty() {
      setDirtyFlag(true);
   }

   private void setDirtyFlag(boolean dirty) {
      this.isDirty = dirty;
   }

   public String getRationale() {
      return getOrcsData().getRationale();
   }

   public boolean isOfType(IRelationType oseeType) throws OseeCoreException {
      return getRelationType().equals(oseeType);
   }

   public void setRationale(String rationale) {
      String toSet = rationale;
      if (toSet == null) {
         toSet = "";
      }
      if (!toSet.equals(getOrcsData().getRationale())) {
         getOrcsData().setRationale(rationale);
         markAsChanged(ModificationType.MODIFIED);
      }
   }

   protected void markAsChanged(ModificationType modificationType) {
      ModificationType modType = computeModType(getOrcsData().getModType(), modificationType);
      getOrcsData().setModType(modType);
      setDirty();
   }

   private ModificationType computeModType(ModificationType original, ModificationType newModType) {
      ModificationType toReturn = original;
      if (original != ModificationType.DELETED || original != ModificationType.ARTIFACT_DELETED) {
         toReturn = newModType;
      }
      return toReturn;
   }

   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((relationData == null) ? 0 : relationData.hashCode());
      return result;
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (obj == null) {
         return false;
      }
      if (getClass() != obj.getClass()) {
         return false;
      }
      Relation other = (Relation) obj;
      if (relationData == null) {
         if (other.relationData != null) {
            return false;
         }
      } else if (!relationData.equals(other.relationData)) {
         return false;
      }
      return true;
   }

   public Integer getLocalIdForSide(RelationSide side) {
      return getOrcsData().getArtIdOn(side);
   }

   @Override
   public boolean isDeleteAllowed() {
      return !isDeleted();
   }

   @Override
   public void unDelete() {
      getOrcsData().setModType(ModificationType.UNDELETED);
   }

   @Override
   public String toString() {
      return "Relation [relationData=" + relationData + ", isDirty=" + isDirty + "]";
   }

}

Back to the top