diff options
Diffstat (limited to 'plugins')
11 files changed, 95 insertions, 56 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectAndCopyDirtyDataTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyDataTest.java index 7ee75789de7..3321eb83534 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectAndCopyDirtyDataTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyDataTest.java @@ -10,90 +10,77 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.transaction.handler; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.ArtifactTransactionData; import org.eclipse.osee.orcs.core.ds.AttributeData; -import org.eclipse.osee.orcs.core.ds.DataFactory; import org.eclipse.osee.orcs.core.internal.artifact.Artifact; import org.eclipse.osee.orcs.core.internal.attribute.Attribute; -import org.eclipse.osee.orcs.core.internal.transaction.handler.CollectAndCopyDirtyData; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; /** - * Test Case for {@link CollectAndCopyDirtyData} + * Test Case for {@link CollectDirtyData} * * @author Roberto E. Escobar */ -public class CollectAndCopyDirtyDataTest { +public class CollectDirtyDataTest { // @formatter:off - @Mock DataFactory dataFactory; - @Mock Artifact artifact; - @Mock Attribute<?> attribute; - - @Mock ArtifactData artSourceData; - @Mock AttributeData attrSourceData; - @Mock ArtifactData artCopyData; - @Mock AttributeData attrCopyData; + @Mock private Artifact artifact; + @Mock private Attribute<?> attribute; + + @Mock private ArtifactData artifactData; + @Mock private AttributeData attributeData; + // @formatter:on private List<ArtifactTransactionData> data; - private CollectAndCopyDirtyData handler; + private CollectDirtyData handler; @Before public void init() { MockitoAnnotations.initMocks(this); data = new ArrayList<ArtifactTransactionData>(); - handler = new CollectAndCopyDirtyData(dataFactory, data); + handler = new CollectDirtyData(data); - when(artifact.getOrcsData()).thenReturn(artSourceData); - when(attribute.getOrcsData()).thenReturn(attrSourceData); + when(artifact.getOrcsData()).thenReturn(artifactData); + when(attribute.getOrcsData()).thenReturn(attributeData); } @Test - public void testDontCollectNoneDirtyArtifact() throws OseeCoreException { + public void testDontCollectNoneDirtyArtifact() { when(artifact.isDirty()).thenReturn(false); + handler.visit(artifact); - verify(dataFactory, times(0)).clone(artSourceData); Assert.assertEquals(0, data.size()); when(attribute.isDirty()).thenReturn(false); handler.visit(attribute); - verify(dataFactory, times(0)).clone(attrSourceData); Assert.assertEquals(0, data.size()); } @Test - public void testVisitAndCollectDirtyArtifact() throws OseeCoreException { + public void testVisitAndCollectDirtyArtifact() { when(artifact.isDirty()).thenReturn(true); when(attribute.isDirty()).thenReturn(true); - when(dataFactory.clone(artSourceData)).thenReturn(artCopyData); - when(dataFactory.clone(attrSourceData)).thenReturn(attrCopyData); handler.visit(artifact); handler.visit(attribute); - verify(dataFactory).clone(artSourceData); - verify(dataFactory).clone(attrSourceData); - Assert.assertEquals(1, data.size()); ArtifactTransactionData txData = data.iterator().next(); - Assert.assertEquals(artCopyData, txData.getArtifactData()); - Assert.assertEquals(attrCopyData, txData.getAttributeData().get(0)); + Assert.assertEquals(artifactData, txData.getArtifactData()); + Assert.assertEquals(attributeData, txData.getAttributeData().get(0)); } } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java index 636d31f215c..447214d63fb 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java @@ -14,7 +14,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({CollectAndCopyDirtyDataTest.class}) +@Suite.SuiteClasses({CollectDirtyDataTest.class}) public class HandlerTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java index d3bd978e167..aaa0d1cb072 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java @@ -148,7 +148,7 @@ public class OrcsApiImpl implements OrcsApi { proxyFactory = new ArtifactProxyFactory(artifactFactory); - txUpdateFactory = new TxDataHandlerFactoryImpl(module.getDataFactory()); + txUpdateFactory = new TxDataHandlerFactoryImpl(); ArtifactBuilderFactory builderFactory = new ArtifactBuilderFactoryImpl(logger, proxyFactory, artifactFactory, attributeFactory); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectAndCopyDirtyData.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyData.java index d0b9736e93f..5c47448f4c7 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectAndCopyDirtyData.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyData.java @@ -12,47 +12,40 @@ package org.eclipse.osee.orcs.core.internal.transaction.handler; import java.util.ArrayList; import java.util.List; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.ArtifactTransactionData; import org.eclipse.osee.orcs.core.ds.ArtifactTxDataImpl; import org.eclipse.osee.orcs.core.ds.AttributeData; -import org.eclipse.osee.orcs.core.ds.DataFactory; import org.eclipse.osee.orcs.core.internal.artifact.Artifact; import org.eclipse.osee.orcs.core.internal.artifact.ArtifactVisitor; import org.eclipse.osee.orcs.core.internal.attribute.Attribute; /** - * Takes a snapshot of all the dirty internal OrcsData + * Collect all the dirty internal OrcsData * * @author Roberto E. Escobar */ -public class CollectAndCopyDirtyData implements ArtifactVisitor { - private final DataFactory dataFactory; +public class CollectDirtyData implements ArtifactVisitor { + private final List<ArtifactTransactionData> data; private ArtifactTransactionData txData; - public CollectAndCopyDirtyData(DataFactory dataFactory, List<ArtifactTransactionData> data) { - this.dataFactory = dataFactory; + public CollectDirtyData(List<ArtifactTransactionData> data) { this.data = data; } - @SuppressWarnings("unused") @Override - public void visit(Artifact artifact) throws OseeCoreException { + public void visit(Artifact artifact) { if (artifact.isDirty()) { - ArtifactData copy = dataFactory.clone(artifact.getOrcsData()); - txData = new ArtifactTxDataImpl(copy, new ArrayList<AttributeData>()); + txData = new ArtifactTxDataImpl(artifact.getOrcsData(), new ArrayList<AttributeData>()); data.add(txData); } } @Override - public void visit(Attribute<?> attribute) throws OseeCoreException { + public void visit(Attribute<?> attribute) { if (attribute.isDirty()) { - AttributeData copy = dataFactory.clone(attribute.getOrcsData()); - txData.getAttributeData().add(copy); + txData.getAttributeData().add(attribute.getOrcsData()); } } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/TxDataHandlerFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/TxDataHandlerFactoryImpl.java index b6455eee1ba..9e6b4109f74 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/TxDataHandlerFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/handler/TxDataHandlerFactoryImpl.java @@ -13,7 +13,6 @@ package org.eclipse.osee.orcs.core.internal.transaction.handler; import java.util.List; import java.util.Map; import org.eclipse.osee.orcs.core.ds.ArtifactTransactionData; -import org.eclipse.osee.orcs.core.ds.DataFactory; import org.eclipse.osee.orcs.core.ds.OrcsVisitor; import org.eclipse.osee.orcs.core.ds.OrcsVisitorAdapter; import org.eclipse.osee.orcs.core.internal.artifact.ArtifactVisitor; @@ -25,16 +24,13 @@ import org.eclipse.osee.orcs.data.ArtifactWriteable; */ public class TxDataHandlerFactoryImpl implements TxDataHandlerFactory { - private final DataFactory dataFactory; - - public TxDataHandlerFactoryImpl(DataFactory dataFactory) { + public TxDataHandlerFactoryImpl() { super(); - this.dataFactory = dataFactory; } @Override public ArtifactVisitor createOnDirtyHandler(List<ArtifactTransactionData> data) { - return new CollectAndCopyDirtyData(dataFactory, data); + return new CollectDirtyData(data); } @Override diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderTest.java index bd6ad4921f7..a50757284f8 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderTest.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderTest.java @@ -313,6 +313,8 @@ public class TxSqlBuilderTest { @Test public void testAcceptAttributeData() throws OseeCoreException { for (ModificationType modType : MODS_ITEMS_ROW) { + when(dataProxy.getData()).thenReturn(new Object[] {ATTR_VALUE, ATTR_URI}); + builder.accept(tx, txData); attrData.setModType(modType); @@ -321,7 +323,7 @@ public class TxSqlBuilderTest { verifyEmpty(allExcept(SqlOrderEnum.TXS_DETAIL, SqlOrderEnum.TXS, SqlOrderEnum.ATTRIBUTES)); // @formatter:off - verifyRow(SqlOrderEnum.ATTRIBUTES, ITEM_ID, TYPE_ID, NEXT_GAMMA_ID, ATTR_ARTIFACT_ID, ATTR_VALUE, ATTR_URI); + verifyRow(SqlOrderEnum.ATTRIBUTES, ITEM_ID, TYPE_ID, NEXT_GAMMA_ID, ATTR_ARTIFACT_ID, ATTR_VALUE, ATTR_URI); verifyRow(SqlOrderEnum.TXS, EXPECTED_TX_ID, NEXT_GAMMA_ID, modType.getValue(), TxChange.CURRENT.getValue(), EXPECTED_BRANCH_ID); verifyQuery(SqlOrderEnum.ATTRIBUTES); // @formatter:on @@ -333,6 +335,11 @@ public class TxSqlBuilderTest { assertEquals(ATTR_URI, dao.getUri()); assertEquals(ATTR_VALUE, dao.getValue()); + when(dataProxy.getData()).thenReturn(new Object[] {"aValue", "aURI"}); + + builder.updateAfterBinaryStorePersist(); + verifyRow(SqlOrderEnum.ATTRIBUTES, ITEM_ID, TYPE_ID, NEXT_GAMMA_ID, ATTR_ARTIFACT_ID, "aValue", "aURI"); + reset(attrData); } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TransactionWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TransactionWriter.java index 3823e8abc07..f61c5ba56c7 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TransactionWriter.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TransactionWriter.java @@ -123,6 +123,8 @@ public class TransactionWriter { for (DaoToSql dao : getBinaryStores()) { dao.persist(); } + sqlBuilder.updateAfterBinaryStorePersist(); + int branchId = tx.getBranch().getId(); List<Object[]> txNotCurrentData = new ArrayList<Object[]>(); for (Entry<SqlOrderEnum, ArtifactJoinQuery> entry : sqlBuilder.getTxNotCurrents()) { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilder.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilder.java index 3cc213d640f..dddf45a0ccf 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilder.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilder.java @@ -35,4 +35,6 @@ public interface TxSqlBuilder { List<DaoToSql> getBinaryStores(); + void updateAfterBinaryStorePersist() throws OseeCoreException; + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderImpl.java index f0a384f99d5..65ca82a75ed 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/TxSqlBuilderImpl.java @@ -144,6 +144,18 @@ public class TxSqlBuilderImpl implements OrcsVisitor, TxSqlBuilder { } @Override + public void updateAfterBinaryStorePersist() throws OseeCoreException { + List<Object[]> insertData = getInsertData(SqlOrderEnum.ATTRIBUTES); + for (int index = 0; index < binaryStores.size() && index < insertData.size(); index++) { + DaoToSql dao = binaryStores.get(index); + Object[] rowData = insertData.get(index); + int end = rowData.length; + rowData[end - 2] = dao.getValue(); + rowData[end - 1] = dao.getUri(); + } + } + + @Override public void visit(RelationData data) throws OseeCoreException { if (!isNewAndDeleted(data)) { boolean isRowAllowed = isGammaCreationAllowed(data); diff --git a/plugins/org.eclipse.osee.orcs.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.test/META-INF/MANIFEST.MF index 9dd936d3fd7..71c8ed7c138 100644 --- a/plugins/org.eclipse.osee.orcs.test/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.orcs.test/META-INF/MANIFEST.MF @@ -30,4 +30,5 @@ Require-Bundle: org.junit, org.eclipse.osee.event.osgi, org.eclipse.osee.logger, org.eclipse.osee.framework.database, - org.eclipse.osee.framework.core.model + org.eclipse.osee.framework.core.model, + com.google.guava;bundle-version="[11.0.0,15.0.0)" 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 29d01a4dbd5..77eb415aae0 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 @@ -33,6 +33,7 @@ import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.ReadableBranch; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.orcs.ApplicationContext; import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.OrcsBranch; @@ -42,12 +43,16 @@ import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.transaction.OrcsTransaction; import org.eclipse.osee.orcs.transaction.TransactionFactory; +import org.junit.Assert; 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; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; /** * @author Roberto E. Escobar @@ -81,6 +86,40 @@ public class OrcsTransactionTest { } @Test + public void testWritingUriAttribute() throws OseeCoreException { + final String requirementText = "The engine torque shall be directly controllable through the engine control unit"; + + OrcsTransaction transaction = + txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "Create plain text requirement"); + + ArtifactWriteable torqueRequirement = + transaction.createArtifact(CoreArtifactTypes.SoftwareRequirementPlainText, "Engine Torque Control"); + torqueRequirement.createAttribute(CoreAttributeTypes.PlainTextContent, requirementText); + + String artifactId = torqueRequirement.getGuid(); + transaction.commit(); + + ResultSet<ArtifactReadable> results = + query.fromBranch(CoreBranches.COMMON).andIsOfType(CoreArtifactTypes.SoftwareRequirementPlainText).getResults(); + + Optional<ArtifactReadable> item = Iterables.tryFind(results, new Predicate<ArtifactReadable>() { + @Override + public boolean apply(ArtifactReadable artifact) { + String data = ""; + try { + data = artifact.getSoleAttributeAsString(CoreAttributeTypes.PlainTextContent, ""); + } catch (OseeCoreException ex) { + Assert.fail(Lib.exceptionToString(ex)); + } + return requirementText.equals(data); + } + }); + + assertTrue(item.isPresent()); + assertEquals(artifactId, item.get().getGuid()); + } + + @Test public void testCreateArtifact() throws OseeCoreException { String comment = "Test Artifact Write"; String expectedName = "Create A Folder"; |