Skip to main content
summaryrefslogtreecommitdiffstats
blob: a85e8bf8c0d4e830934a51de891d536f95de3b9b (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.artifact;

import java.util.Collection;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.EditState;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.orcs.core.ds.ArtifactData;
import org.eclipse.osee.orcs.core.internal.attribute.Attribute;
import org.eclipse.osee.orcs.core.internal.attribute.AttributeFactory;
import org.eclipse.osee.orcs.core.internal.attribute.AttributeManagerImpl;
import org.eclipse.osee.orcs.core.internal.relation.HasRelationContainer;
import org.eclipse.osee.orcs.core.internal.relation.RelationContainer;
import org.eclipse.osee.orcs.data.ArtifactWriteable;

public class ArtifactImpl extends AttributeManagerImpl implements ArtifactWriteable, HasRelationContainer, ArtifactVisitable {

   private final RelationContainer relationContainer;
   private EditState objectEditState;
   private ArtifactData artifactData;
   private final ValueProvider<Branch, ArtifactData> branchProvider;
   private final ValueProvider<ArtifactType, ArtifactData> artifactTypeProvider;

   public ArtifactImpl(ArtifactData artifactData, AttributeFactory attributeFactory, RelationContainer relationContainer, ValueProvider<Branch, ArtifactData> branchProvider, ValueProvider<ArtifactType, ArtifactData> artifactTypeProvider) {
      super(attributeFactory);
      this.artifactData = artifactData;
      this.artifactTypeProvider = artifactTypeProvider;
      this.branchProvider = branchProvider;
      this.relationContainer = relationContainer;
      this.objectEditState = EditState.NO_CHANGE;
   }

   @Override
   public RelationContainer getRelationContainer() {
      return relationContainer;
   }

   @Override
   public ArtifactData getOrcsData() {
      return artifactData;
   }

   @Override
   public void setOrcsData(ArtifactData data) {
      this.artifactData = data;
      objectEditState = EditState.NO_CHANGE;
      branchProvider.setOrcsData(data);
      artifactTypeProvider.setOrcsData(data);
   }

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

   @Override
   public int getLocalId() {
      return getOrcsData().getLocalId();
   }

   @Override
   public String getGuid() {
      return getOrcsData().getGuid();
   }

   @Override
   public String getHumanReadableId() {
      return getOrcsData().getHumanReadableId();
   }

   @Override
   public int getTransactionId() {
      return getOrcsData().getVersion().getTransactionId();
   }

   @Override
   public Branch getBranch() throws OseeCoreException {
      return branchProvider.get();
   }

   @Override
   public ArtifactType getArtifactType() throws OseeCoreException {
      return artifactTypeProvider.get();
   }

   @Override
   public void setName(String name) throws OseeCoreException {
      setSoleAttributeFromString(CoreAttributeTypes.Name, name);
   }

   @Override
   public void setArtifactType(IArtifactType artifactType) throws OseeCoreException {
      if (!getArtifactType().equals(artifactType)) {
         getOrcsData().setTypeUuid(artifactType.getGuid());

         objectEditState = EditState.ARTIFACT_TYPE_MODIFIED;
         if (getOrcsData().getVersion().isInStorage()) {
            //            lastValidModType = modType;
            getOrcsData().setModType(ModificationType.MODIFIED);
         }
      }
   }

   @Override
   public boolean isOfType(IArtifactType... otherTypes) throws OseeCoreException {
      return getArtifactType().inheritsFrom(otherTypes);
   }

   @Override
   public boolean isDirty() {
      return areAttributesDirty() || hasDirtyRelations() || hasDirtyArtifactType() || isReplaceWithVersion();
   }

   private boolean isReplaceWithVersion() {
      return getModificationType() == ModificationType.REPLACED_WITH_VERSION;
   }

   private boolean hasDirtyArtifactType() {
      return objectEditState.isArtifactTypeChange();
   }

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

   @Override
   public boolean isAttributeTypeValid(IAttributeType attributeType) throws OseeCoreException {
      return getArtifactType().isValidAttributeType(attributeType, getBranch());
   }

   @Override
   public Collection<? extends IAttributeType> getValidAttributeTypes() throws OseeCoreException {
      return getArtifactType().getAttributeTypes(getBranch());
   }

   @Override
   public String getExceptionString() {
      try {
         return String.format("artifact type [%s] guid[%s] on branch[%s]", getArtifactType(), getGuid(), getBranch());
      } catch (OseeCoreException ex) {
         return Lib.exceptionToString(ex);
      }
   }

   public boolean hasDirtyRelations() {
      //TX_TODO: Implement this
      return false;
   }

   @Override
   public void accept(ArtifactVisitor visitor) throws OseeCoreException {
      visitor.visit(this);
      for (Attribute<?> attribute : getAllAttributes()) {
         visitor.visit(attribute);
      }
      // TX_TODO loop through relations

   }

   @Override
   public void delete() throws OseeCoreException {
      getOrcsData().setModType(ModificationType.DELETED);
      deleteAttributesByArtifact();
      //TX_TODO Delete artifact and relation stuff
      //      public static void deleteArtifact(SkynetTransaction transaction, boolean overrideDeleteCheck, final Artifact... artifacts) throws OseeCoreException {
      //         deleteArtifactCollection(transaction, overrideDeleteCheck, Arrays.asList(artifacts));
      //      }
      //
      //      public static void deleteArtifactCollection(SkynetTransaction transaction, boolean overrideDeleteCheck, final Collection<Artifact> artifacts) throws OseeCoreException {
      //         if (artifacts.isEmpty()) {
      //            return;
      //         }
      //
      //         if (!overrideDeleteCheck) {
      //            performDeleteChecks(artifacts);
      //         }
      //
      //         bulkLoadRelatives(artifacts);
      //
      //         boolean reorderRelations = true;
      //         for (Artifact artifact : artifacts) {
      //            deleteTrace(artifact, transaction, reorderRelations);
      //         }
      //      }
      //      private static void deleteTrace(Artifact artifact, SkynetTransaction transaction, boolean reorderRelations) throws OseeCoreException {
      //         if (!artifact.isDeleted()) {
      //            // This must be done first since the the actual deletion of an
      //            // artifact clears out the link manager
      //            for (Artifact childArtifact : artifact.getChildren()) {
      //               deleteTrace(childArtifact, transaction, false);
      //            }
      //            try {
      //               // calling deCache here creates a race condition when the handleRelationModifiedEvent listeners fire - RS
      //               //          ArtifactCache.deCache(artifact);
      //               artifact.internalSetDeleted();
      //               RelationManager.deleteRelationsAll(artifact, reorderRelations, transaction);
      //               if (transaction != null) {
      //                  artifact.persist(transaction);
      //               }
      //            } catch (OseeCoreException ex) {
      //               artifact.resetToPreviousModType();
      //               throw ex;
      //            }
      //         }
      //      }
   }
}

Back to the top