Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2013-07-15 21:06:06 +0000
committerjmisinco2013-07-15 21:06:06 +0000
commit8fa9d6a341f5913088cf91000f50f00cd7f07a6c (patch)
treecfec8fbfd3edf08db2ae108260a1a7ebc06e207d
parent098c86f896ff17ffd87f960ba8498bb6e3737d52 (diff)
downloadorg.eclipse.osee-8fa9d6a341f5913088cf91000f50f00cd7f07a6c.tar.gz
org.eclipse.osee-8fa9d6a341f5913088cf91000f50f00cd7f07a6c.tar.xz
org.eclipse.osee-8fa9d6a341f5913088cf91000f50f00cd7f07a6c.zip
bug: Fix Artifact getTransaction method
Artifact transactionId should be equals to the last attribute modified transaction id. Change-Id: Ibcda0a967fa12dc162966e8b67c1fe6b514de01b
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java62
-rw-r--r--plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java38
2 files changed, 42 insertions, 58 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java
index a74bb74f49d..cb205078dd6 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java
@@ -31,10 +31,11 @@ import org.eclipse.osee.orcs.data.ArtifactWriteable;
public class Artifact extends AttributeManagerImpl implements ArtifactWriteable, HasRelationContainer, ArtifactVisitable {
private final ArtifactTypes artifactTypeCache;
+ private final ValueProvider<Branch, ArtifactData> branchProvider;
private final RelationContainer relationContainer;
+
private EditState objectEditState;
private ArtifactData artifactData;
- private final ValueProvider<Branch, ArtifactData> branchProvider;
public Artifact(ArtifactTypes artifactTypeCache, ArtifactData artifactData, AttributeFactory attributeFactory, RelationContainer relationContainer, ValueProvider<Branch, ArtifactData> branchProvider) {
super(attributeFactory);
@@ -83,7 +84,11 @@ public class Artifact extends AttributeManagerImpl implements ArtifactWriteable,
@Override
public int getTransaction() {
- return getOrcsData().getVersion().getTransactionId();
+ int maxTransactionId = getOrcsData().getVersion().getTransactionId();
+ for (Attribute<?> attribute : getAllAttributes()) {
+ maxTransactionId = Math.max(maxTransactionId, attribute.getOrcsData().getVersion().getTransactionId());
+ }
+ return maxTransactionId;
}
@Override
@@ -105,10 +110,8 @@ public class Artifact extends AttributeManagerImpl implements ArtifactWriteable,
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);
}
}
@@ -121,7 +124,7 @@ public class Artifact extends AttributeManagerImpl implements ArtifactWriteable,
@Override
public boolean isDirty() {
- return areAttributesDirty() || hasDirtyRelations() || hasDirtyArtifactType() || isReplaceWithVersion();
+ return areAttributesDirty() || hasDirtyArtifactType() || isReplaceWithVersion();
}
private boolean isReplaceWithVersion() {
@@ -156,66 +159,17 @@ public class Artifact extends AttributeManagerImpl implements ArtifactWriteable,
}
}
- 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;
- // }
- // }
- // }
}
}
diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java
index 03d2f2adc03..c077372d69b 100644
--- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java
+++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java
@@ -41,6 +41,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
import org.junit.rules.TestRule;
/**
@@ -54,6 +55,9 @@ public class OrcsTransactionTest {
@Rule
public TestRule osgi = integrationRule(this, "osee.demo.hsql");
+ @Rule
+ public TestName testName = new TestName();
+
@OsgiService
private OrcsApi orcsApi;
@@ -180,7 +184,8 @@ public class OrcsTransactionTest {
public void testAsWritable() throws OseeCoreException {
ArtifactReadable guestUser =
orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne();
- OrcsTransaction transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "testAsWritable");
+ OrcsTransaction transaction =
+ txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
ArtifactWriteable writeable = transaction.asWriteable(guestUser);
writeable.setName("Test");
@@ -203,7 +208,7 @@ public class OrcsTransactionTest {
ArtifactReadable guestUser =
orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne();
OrcsTransaction transaction =
- txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "testAsWritableException");
+ txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
ArtifactWriteable writeable = transaction.asWriteable(guestUser);
writeable.setName("Test2");
transaction.commit();
@@ -216,11 +221,11 @@ public class OrcsTransactionTest {
@Test
public void testDeleteArtifact() throws OseeCoreException {
OrcsTransaction transaction =
- txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "testDeleteArtifact");
+ txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
ArtifactWriteable artifact = transaction.createArtifact(CoreArtifactTypes.AccessControlModel, "deleteMe");
transaction.commit();
- transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "testDeleteArtifact");
+ transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
ArtifactReadable toDelete =
orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(artifact.getGuid()).getResults().getExactlyOne();
ArtifactWriteable writeable = transaction.asWriteable(toDelete);
@@ -234,6 +239,31 @@ public class OrcsTransactionTest {
}
+ @Test
+ public void testArtifactGetTransaction() throws OseeCoreException {
+ OrcsTransaction transaction =
+ txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
+
+ String guid = transaction.createArtifact(CoreArtifactTypes.Component, "A component").getGuid();
+ int startingTx = transaction.commit().getId();
+
+ ArtifactReadable artifact =
+ orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne();
+ Assert.assertEquals(startingTx, artifact.getTransaction());
+
+ OrcsTransaction transaction2 =
+ txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName());
+
+ transaction2.asWriteable(artifact).setName("Modified - component");
+ int lastTx = transaction2.commit().getId();
+
+ Assert.assertTrue(startingTx != lastTx);
+
+ ArtifactReadable currentArtifact =
+ orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne();
+ Assert.assertEquals(lastTx, currentArtifact.getTransaction());
+ }
+
private ArtifactReadable getSystemUser() throws OseeCoreException {
return orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
}

Back to the top