Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Avila2015-08-12 00:36:41 +0000
committerAngel Avila2015-09-12 01:00:09 +0000
commit37c7112b8c3e5c3621197205a5a61066977b9896 (patch)
treecb4deda81b1dc36d23ba73cf04c3a1b6f04b1f99 /plugins
parenta4e4963bb44cf7b77e5091b88233c7ba8c796cf9 (diff)
downloadorg.eclipse.osee-37c7112b8c3e5c3621197205a5a61066977b9896.tar.gz
org.eclipse.osee-37c7112b8c3e5c3621197205a5a61066977b9896.tar.xz
org.eclipse.osee-37c7112b8c3e5c3621197205a5a61066977b9896.zip
feature[ats_ATS197755]: Provide REST endpoint for UI Count
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java2
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java171
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TypeCountWriter.java147
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeDataLoader.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java10
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionUtil.java51
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java113
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/TransactionEndpoint.java1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java36
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/TransactionEndpointImpl.java122
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsApi.java1
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/CompareResults.java (renamed from plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/CompareResults.java)2
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java16
19 files changed, 549 insertions, 145 deletions
diff --git a/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF
index 4d55a5bdfe..e2f7c08600 100644
--- a/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF
@@ -31,9 +31,11 @@ Import-Package: com.google.gson;version="2.1.0",
org.eclipse.osee.framework.core.data,
org.eclipse.osee.framework.core.enums,
org.eclipse.osee.framework.core.exception,
+ org.eclipse.osee.framework.core.model.change,
org.eclipse.osee.framework.core.util,
org.eclipse.osee.framework.jdk.core.type,
org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.framework.jdk.core.util.io.xml,
org.eclipse.osee.jaxrs,
org.eclipse.osee.jaxrs.mvc,
org.eclipse.osee.jdbc,
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
index f3d5cfa95d..471fedd293 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
@@ -28,6 +28,7 @@ import org.eclipse.osee.ats.rest.internal.config.InsertionEndpointImpl;
import org.eclipse.osee.ats.rest.internal.config.InsertionResource;
import org.eclipse.osee.ats.rest.internal.config.ProgramEndpointImpl;
import org.eclipse.osee.ats.rest.internal.config.ProgramResource;
+import org.eclipse.osee.ats.rest.internal.config.ReportResource;
import org.eclipse.osee.ats.rest.internal.config.TeamResource;
import org.eclipse.osee.ats.rest.internal.config.UserResource;
import org.eclipse.osee.ats.rest.internal.config.VersionResource;
@@ -108,6 +109,7 @@ public class AtsApplication extends Application {
// UIs
singletons.add(new ActionUiResource(atsServer, logger));
+ singletons.add(new ReportResource(orcsApi, atsServer));
}
public void stop() {
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java
new file mode 100644
index 0000000000..cb16940533
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.ats.rest.internal.config;
+
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.WordTemplateContent;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+import org.eclipse.osee.ats.impl.IAtsServer;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.core.model.change.ChangeItem;
+import org.eclipse.osee.framework.core.model.change.ChangeType;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.data.ArtifactTypes;
+import org.eclipse.osee.orcs.data.AttributeTypes;
+import org.eclipse.osee.orcs.data.TransactionReadable;
+import org.eclipse.osee.orcs.search.TransactionQuery;
+import org.eclipse.osee.orcs.transaction.CompareResults;
+
+/**
+ * @author Angel Avila
+ */
+@Path("typeCount")
+public class ReportResource {
+
+ private final OrcsApi orcsApi;
+ private final IAtsServer atsServer;
+
+ public ReportResource(OrcsApi orcsApi, IAtsServer atsServer) {
+ this.orcsApi = orcsApi;
+ this.atsServer = atsServer;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response getTypeCount(@QueryParam("branchUuid") long branchUuid, @QueryParam("artTypes") List<Long> artTypes, @QueryParam("attrTypes") List<Long> attrTypes) throws OseeCoreException {
+ List<ChangeItem> changes = getChanges(branchUuid);
+ Set<Long> newArts = new HashSet<Long>();
+ Set<Long> modArts = new HashSet<Long>();
+ Set<Long> deletedArts = new HashSet<Long>();
+
+ Map<Integer, Pair<ChangeItem, Set<ChangeItem>>> artToChanges =
+ new HashMap<Integer, Pair<ChangeItem, Set<ChangeItem>>>();
+
+ buildArtIdToChangeMap(changes, artToChanges);
+ buildLists(artToChanges, newArts, modArts, deletedArts);
+
+ final TypeCountWriter writer = new TypeCountWriter(orcsApi);
+ final String fileName = String.format("Type_Count_Report_%s", System.currentTimeMillis());
+
+ StreamingOutput streamingOutput = new StreamingOutput() {
+
+ @Override
+ public void write(OutputStream outputStream) throws WebApplicationException, IOException {
+ writer.write(branchUuid, newArts, modArts, deletedArts, artTypes, attrTypes, outputStream);
+ outputStream.flush();
+ }
+ };
+ String contentDisposition =
+ String.format("attachment; filename=\"%s.xml\"; creation-date=\"%s\"", fileName, new Date());
+ return Response.ok(streamingOutput).header("Content-Disposition", contentDisposition).type("application/xml").build();
+ }
+
+ private void buildArtIdToChangeMap(List<ChangeItem> changes, Map<Integer, Pair<ChangeItem, Set<ChangeItem>>> artToChanges) {
+ for (ChangeItem change : changes) {
+ int artId = change.getArtId();
+ ChangeType changeType = change.getChangeType();
+ if (changeType.isArtifactChange()) {
+ if (!artToChanges.containsKey(artId)) {
+ artToChanges.put(artId, new Pair<>(change, new HashSet<ChangeItem>()));
+ } else {
+ // This entry was added by an attribute change for this art so the changeType hasn't been set
+ Pair<ChangeItem, Set<ChangeItem>> pair = artToChanges.get(artId);
+ pair.setFirst(change);
+ }
+ } else if (changeType.isAttributeChange()) {
+ if (!artToChanges.containsKey(artId)) {
+ Set<ChangeItem> changeSet = new HashSet<ChangeItem>();
+ changeSet.add(change);
+ artToChanges.put(artId, new Pair<>(null, changeSet));
+ } else {
+ Pair<ChangeItem, Set<ChangeItem>> pair = artToChanges.get(artId);
+ Set<ChangeItem> changeSet = pair.getSecond();
+ changeSet.add(change);
+ }
+ }
+
+ }
+ }
+
+ private void buildLists(Map<Integer, Pair<ChangeItem, Set<ChangeItem>>> artToChanges, Set<Long> newArts, Set<Long> modArts, Set<Long> deletedArts) {
+ AttributeTypes attributeTypes = orcsApi.getOrcsTypes().getAttributeTypes();
+ ArtifactTypes artifactTypes = orcsApi.getOrcsTypes().getArtifactTypes();
+
+ for (Integer artId : artToChanges.keySet()) {
+ Pair<ChangeItem, Set<ChangeItem>> pair = artToChanges.get(artId);
+ ChangeItem artChange = pair.getFirst();
+ ModificationType modType = artChange.getNetChange().getModType();
+
+ if (modType.equals(ModificationType.NEW)) {
+ newArts.add((long) artId);
+ } else if (modType.equals(ModificationType.DELETED)) {
+ deletedArts.add((long) artId);
+ } else if (modType.equals(ModificationType.MODIFIED) && isCountable(artChange, pair.getSecond(),
+ attributeTypes, artifactTypes)) {
+ modArts.add((long) artId);
+ }
+ }
+
+ }
+
+ private boolean isCountable(ChangeItem artChange, Set<ChangeItem> attrChanges, AttributeTypes attributeTypes, ArtifactTypes artTypes) {
+ boolean toReturn = false;
+
+ // Was a synthetic artifact change added by AddArtifactChangeDataCallable
+ for (ChangeItem change : attrChanges) {
+ IAttributeType attrType = attributeTypes.getByUuid(change.getItemTypeId());
+ if (attrType.matches(WordTemplateContent)) {
+ toReturn = true;
+ break;
+ }
+ }
+
+ return toReturn;
+ }
+
+ private List<ChangeItem> getChanges(long branchUuid) {
+ TransactionQuery transactionQuery2 = orcsApi.getQueryFactory().transactionQuery();
+ TransactionQuery transactionQuery3 = orcsApi.getQueryFactory().transactionQuery();
+ IOseeBranch branchReadable =
+ orcsApi.getQueryFactory().branchQuery().andUuids(branchUuid).getResults().getExactlyOne();
+
+ IOseeBranch parentBranch = atsServer.getBranchService().getParentBranch(branchReadable);
+
+ TransactionReadable startTx = transactionQuery2.andIsHead(branchReadable).getResults().getExactlyOne();
+ Integer start = startTx.getLocalId();
+
+ TransactionReadable endTx = transactionQuery3.andIsHead(parentBranch).getResults().getExactlyOne();
+ Integer end = endTx.getLocalId();
+
+ CompareResults results = orcsApi.getTransactionFactory().compareTxs(start, end);
+
+ return results.getChanges();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TypeCountWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TypeCountWriter.java
new file mode 100644
index 0000000000..185dcc57ea
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TypeCountWriter.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.ats.rest.internal.config;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.util.io.xml.ExcelXmlWriter;
+import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+
+/**
+ * @author Angel Avila
+ */
+public class TypeCountWriter {
+
+ private final OrcsApi orcsApi;
+
+ public TypeCountWriter(OrcsApi orcsApi) {
+ this.orcsApi = orcsApi;
+ }
+
+ public void write(long branchUuid, Set<Long> newArts, Set<Long> modifiedArts, Set<Long> deletedArts, List<Long> artTypes, List<Long> attrTypes, OutputStream outputStream) {
+ try {
+ Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
+ ExcelXmlWriter sheetWriter = new ExcelXmlWriter(writer);
+
+ List<IAttributeType> attributes = getAttrTypes(attrTypes);
+ String[] headers = getHeaders(attributes);
+ int columns = headers.length;
+ sheetWriter.startSheet("Type Count Report", headers.length);
+ sheetWriter.writeRow((Object[]) headers);
+
+ List<IArtifactType> artifactTypes = getTypes(artTypes);
+
+ if (!newArts.isEmpty()) {
+ ResultSet<ArtifactReadable> newArtifacts =
+ orcsApi.getQueryFactory().fromBranch(branchUuid).andTypeEquals(artifactTypes).andUuids(newArts).getResults();
+ for (ArtifactReadable art : newArtifacts) {
+ String[] row = new String[columns];
+ int index = 0;
+
+ row[index++] = art.getName();
+ row[index++] = "NEW";
+ row[index++] = art.getArtifactType().toString();
+ for (IAttributeType type : attributes) {
+ row[index++] = art.getAttributeValues(type).toString();
+ }
+
+ sheetWriter.writeRow((Object[]) row);
+ }
+ }
+
+ if (!modifiedArts.isEmpty()) {
+ ResultSet<ArtifactReadable> modifiedArtifacts =
+ orcsApi.getQueryFactory().fromBranch(branchUuid).andTypeEquals(artifactTypes).andUuids(modifiedArts).getResults();
+ for (ArtifactReadable art : modifiedArtifacts) {
+ String[] row = new String[columns];
+ int index = 0;
+
+ row[index++] = art.getName();
+ row[index++] = "MODIFIED";
+ row[index++] = art.getArtifactType().toString();
+ for (IAttributeType type : attributes) {
+ row[index++] = art.getAttributeValues(type).toString();
+ }
+ sheetWriter.writeRow((Object[]) row);
+ }
+ }
+
+ if (!deletedArts.isEmpty()) {
+ ResultSet<ArtifactReadable> deletedArtifacts =
+ orcsApi.getQueryFactory().fromBranch(branchUuid).andTypeEquals(artifactTypes).andUuids(deletedArts).getResults();
+ for (ArtifactReadable art : deletedArtifacts) {
+ String[] row = new String[columns];
+ int index = 0;
+
+ row[index++] = art.getName();
+ row[index++] = "DELETED";
+ row[index++] = art.getArtifactType().toString();
+ for (IAttributeType type : attributes) {
+ row[index++] = art.getAttributeValues(type).toString();
+ }
+ sheetWriter.writeRow((Object[]) row);
+ }
+ }
+
+ sheetWriter.endSheet();
+ sheetWriter.endWorkbook();
+ } catch (Exception ex) {
+ throw new OseeCoreException(ex);
+ }
+ }
+
+ private List<IArtifactType> getTypes(List<Long> typeIds) {
+ List<IArtifactType> toReturn = new ArrayList<IArtifactType>();
+
+ Collection<? extends IArtifactType> allTypes = orcsApi.getOrcsTypes().getArtifactTypes().getAll();
+ for (IArtifactType type : allTypes) {
+ if (typeIds.contains(type.getGuid())) {
+ toReturn.add(type);
+ }
+ }
+ return toReturn;
+ }
+
+ private List<IAttributeType> getAttrTypes(List<Long> typeIds) {
+ List<IAttributeType> toReturn = new ArrayList<IAttributeType>();
+
+ Collection<? extends IAttributeType> allTypes = orcsApi.getOrcsTypes().getAttributeTypes().getAll();
+ for (IAttributeType type : allTypes) {
+ if (typeIds.contains(type.getGuid())) {
+ toReturn.add(type);
+ }
+ }
+ return toReturn;
+ }
+
+ private String[] getHeaders(List<IAttributeType> types) {
+ orcsApi.getOrcsTypes().getArtifactTypes().getAll();
+ String[] toReturn = new String[types.size() + 3];
+ int index = 0;
+ toReturn[index++] = "Name";
+ toReturn[index++] = "Mod Type";
+ toReturn[index++] = "Art Type";
+ for (IAttributeType type : types) {
+ toReturn[index++] = type.getName();
+ }
+ return toReturn;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF
index 2f5906f4c8..9d9da95276 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF
@@ -88,7 +88,8 @@ Import-Package: com.google.common.collect;version="15.0.0",
org.eclipse.osee.jdbc,
org.eclipse.osee.orcs.rest.client,
org.eclipse.osee.orcs.rest.model,
- org.eclipse.osee.orcs.rest.model.search.artifact
+ org.eclipse.osee.orcs.rest.model.search.artifact,
+ org.eclipse.osee.orcs.transaction
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/*.xml
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeDataLoader.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeDataLoader.java
index 92e8c7392b..1d63334987 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeDataLoader.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeDataLoader.java
@@ -46,8 +46,8 @@ import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil;
import org.eclipse.osee.framework.skynet.core.relation.RelationTypeManager;
import org.eclipse.osee.jaxrs.client.JaxRsExceptions;
import org.eclipse.osee.orcs.rest.client.OseeClient;
-import org.eclipse.osee.orcs.rest.model.CompareResults;
import org.eclipse.osee.orcs.rest.model.TransactionEndpoint;
+import org.eclipse.osee.orcs.transaction.CompareResults;
/**
* @author Jeff C. Phillips
@@ -198,8 +198,8 @@ public class ChangeDataLoader extends AbstractOperation {
switch (item.getChangeType()) {
case ARTIFACT_CHANGE:
change =
- new ArtifactChange(startTxBranch, itemGammaId, itemId, txDelta, netModType, isHistorical,
- changeArtifact, artifactDelta);
+ new ArtifactChange(startTxBranch, itemGammaId, itemId, txDelta, netModType, isHistorical,
+ changeArtifact, artifactDelta);
break;
case ATTRIBUTE_CHANGE:
String isValue = item.getCurrentVersion().getValue();
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
index c86129fce2..2a8ab5147c 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
@@ -19,9 +19,11 @@ import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.OrcsBranch;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.internal.search.QueryModule;
import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.junit.Before;
import org.junit.Rule;
@@ -31,7 +33,7 @@ import org.mockito.Mock;
/**
* Test Case for {@link TransactionFactoryImpl}
- *
+ *
* @author Roberto E. Escobar
*/
public class TransactionFactoryImplTest {
@@ -45,7 +47,9 @@ public class TransactionFactoryImplTest {
@Mock private TxDataManager txDataManager;
@Mock private TxCallableFactory txCallableFactory;
@Mock private QueryModule query;
-
+ @Mock private QueryFactory queryFactory;
+ @Mock private OrcsBranch orcsBranch;
+
@Mock private ArtifactReadable expectedAuthor;
@Mock private TxData txData;
// @formatter:on
@@ -56,7 +60,7 @@ public class TransactionFactoryImplTest {
@Before
public void init() {
initMocks(this);
- factory = new TransactionFactoryImpl(session, txDataManager, txCallableFactory, query);
+ factory = new TransactionFactoryImpl(session, txDataManager, txCallableFactory, query, queryFactory, orcsBranch);
}
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 f6652927b4..5cafe273e9 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
@@ -257,6 +257,7 @@ public class OrcsApiImpl implements OrcsApi {
@Override
protected final FutureTask<ArtifactReadable> createLoaderTask() {
Callable<ArtifactReadable> callable = new Callable<ArtifactReadable>() {
+ @SuppressWarnings("unchecked")
@Override
public ArtifactReadable call() throws Exception {
return getQueryFactory().fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
@@ -274,7 +275,8 @@ public class OrcsApiImpl implements OrcsApi {
@Override
public TransactionFactory getTransactionFactory() {
OrcsSession session = getSession();
- return new TransactionFactoryImpl(session, txDataManager, txCallableFactory, queryModule);
+ return new TransactionFactoryImpl(session, txDataManager, txCallableFactory, queryModule, getQueryFactory(),
+ getBranchOps());
}
@Override
@@ -343,5 +345,4 @@ public class OrcsApiImpl implements OrcsApi {
public ScriptEngine getScriptEngine() {
return manager.getEngineByName(ScriptEngines.ORCS_SCRIPT_ENGINE_ID);
}
-
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionUtil.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionUtil.java
new file mode 100644
index 0000000000..78c2055143
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionUtil.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.transaction;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Angel Avila
+ */
+public class OrcsTransactionUtil {
+
+ public static List<Integer> asIntegerList(String rawValue) {
+ List<Integer> toReturn;
+ if (Strings.isValid(rawValue)) {
+ String[] entries = rawValue.split(",");
+ toReturn = new ArrayList<Integer>();
+ for (String entry : entries) {
+ Integer value = Integer.parseInt(entry.trim());
+ toReturn.add(value);
+ }
+ } else {
+ toReturn = Collections.emptyList();
+ }
+ return toReturn;
+ }
+
+ public static <T> T executeCallable(Callable<T> callable) {
+ try {
+ return callable.call();
+ } catch (Exception ex) {
+ if (ex instanceof OseeCoreException) {
+ throw (OseeCoreException) ex;
+ } else {
+ throw new OseeCoreException(ex);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
index 1462f58a36..52a46317cc 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
@@ -11,18 +11,32 @@
package org.eclipse.osee.orcs.core.internal.transaction;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.concurrent.Callable;
import org.eclipse.osee.executor.admin.CancellableCallable;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.ITransaction;
import org.eclipse.osee.framework.core.data.TokenFactory;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.model.change.ChangeItem;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.util.Compare;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.orcs.OrcsBranch;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.internal.search.QueryModule;
import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.data.TransactionReadable;
+import org.eclipse.osee.orcs.search.QueryFactory;
+import org.eclipse.osee.orcs.transaction.CompareResults;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.eclipse.osee.orcs.transaction.TransactionFactory;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Sets.SetView;
/**
* @author Roberto E. Escobar
@@ -33,13 +47,17 @@ public class TransactionFactoryImpl implements TransactionFactory {
private final TxDataManager txDataManager;
private final TxCallableFactory txCallableFactory;
private final QueryModule query;
+ private final QueryFactory queryFactory;
+ private final OrcsBranch orcsBranch;
- public TransactionFactoryImpl(OrcsSession session, TxDataManager txDataManager, TxCallableFactory txCallableFactory, QueryModule query) {
+ public TransactionFactoryImpl(OrcsSession session, TxDataManager txDataManager, TxCallableFactory txCallableFactory, QueryModule query, QueryFactory queryFactory, OrcsBranch orcsBranch) {
super();
this.session = session;
this.txDataManager = txDataManager;
this.txCallableFactory = txCallableFactory;
this.query = query;
+ this.queryFactory = queryFactory;
+ this.orcsBranch = orcsBranch;
}
@Override
@@ -70,4 +88,97 @@ public class TransactionFactoryImpl implements TransactionFactory {
public Callable<Void> setTransactionComment(ITransaction transaction, String comment) {
return txCallableFactory.setTransactionComment(session, transaction, comment);
}
+
+ @Override
+ public CompareResults compareTxs(int txId1, int txId2) {
+ TransactionReadable sourceTx = getTxById(txId1);
+ TransactionReadable destinationTx = getTxById(txId2);
+ Callable<List<ChangeItem>> callable = orcsBranch.compareBranch(sourceTx, destinationTx);
+ List<ChangeItem> changes = OrcsTransactionUtil.executeCallable(callable);
+
+ CompareResults data = new CompareResults();
+ data.setChanges(changes);
+ return data;
+ }
+
+ @Override
+ public boolean replaceWithBaselineTxVersion(String userId, long branchId, int txId, int artId, String comment) {
+ boolean introduced = false;
+ ArtifactReadable userReadable =
+ queryFactory.fromBranch(CoreBranches.COMMON).andGuid(userId).getResults().getOneOrNull();
+ ArtifactReadable baselineArtifact =
+ queryFactory.fromBranch(branchId).fromTransaction(txId).andUuid(artId).getResults().getOneOrNull();
+
+ if (userReadable != null && baselineArtifact != null) {
+ TransactionBuilder tx = createTransaction(branchId, userReadable, comment);
+ ArtifactReadable destination =
+ queryFactory.fromBranch(branchId).includeDeletedArtifacts().andUuid(artId).getResults().getOneOrNull();
+ tx.replaceWithVersion(baselineArtifact, destination);
+ tx.commit();
+ introduced = true;
+ } else {
+ throw new OseeCoreException("%s Error - The user and baseline artifact were not found.", comment);
+ }
+
+ return introduced;
+ }
+
+ @Override
+ public boolean purgeTxs(String txIds) {
+ boolean modified = false;
+ List<Integer> txsToDelete = OrcsTransactionUtil.asIntegerList(txIds);
+ if (!txsToDelete.isEmpty()) {
+ ResultSet<TransactionReadable> results = queryFactory.transactionQuery().andTxIds(txsToDelete).getResults();
+ if (!results.isEmpty()) {
+ checkAllTxsFound("Purge Transaction", txsToDelete, results);
+ List<TransactionReadable> list = Lists.newArrayList(results);
+ Callable<?> op = purgeTransaction(list);
+ OrcsTransactionUtil.executeCallable(op);
+ modified = true;
+ }
+ }
+ return modified;
+ }
+
+ @Override
+ public boolean setTxComment(int txId, String comment) {
+ TransactionReadable tx = getTxById(txId);
+ boolean modified = false;
+ if (Compare.isDifferent(tx.getComment(), comment)) {
+ setTransactionComment(tx, comment);
+ modified = true;
+ }
+ return modified;
+ }
+
+ @Override
+ public ResultSet<TransactionReadable> getAllTxs() {
+ return queryFactory.transactionQuery().getResults();
+ }
+
+ @Override
+ public TransactionReadable getTx(int txId) {
+ return getTxById(txId);
+ }
+
+ @Override
+ public TransactionReadable getTxById(int txId) {
+ ResultSet<TransactionReadable> results = queryFactory.transactionQuery().andTxId(txId).getResults();
+ return results.getExactlyOne();
+ }
+
+ private void checkAllTxsFound(String opName, List<Integer> txIds, ResultSet<TransactionReadable> result) {
+ if (txIds.size() != result.size()) {
+ Set<Integer> found = new HashSet<Integer>();
+ for (TransactionReadable tx : result) {
+ found.add(tx.getGuid());
+ }
+ SetView<Integer> difference = Sets.difference(Sets.newHashSet(txIds), found);
+ if (!difference.isEmpty()) {
+ throw new OseeCoreException(
+ "%s Error - The following transactions from %s were not found - txs %s - Please remove them from the request and try again.",
+ opName, txIds, difference);
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
index 7230bd6771..f5c5f2943e 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
@@ -19,5 +19,6 @@ Import-Package: javax.annotation.security;version="1.2.0",
org.eclipse.osee.framework.core.util,
org.eclipse.osee.framework.jdk.core.type,
org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.orcs.transaction,
org.eclipse.osee.orcs.writer.model.config,
org.eclipse.osee.orcs.writer.model.reader
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java
index 95778d5cf1..b4410e2a03 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java
+++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java
@@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.orcs.transaction.CompareResults;
/**
* @author Roberto E. Escobar
@@ -38,7 +39,7 @@ public interface BranchEndpoint {
/**
* Perform a branch query based on query parameter input
- *
+ *
* @param branchUuids comma separated list of branch uuids
* @param branchTypes comma separated list of {@link org.eclipse.osee.framework.core.enums.BranchType BranchType}
* @param branchStates comma separated list of {@link org.eclipse.osee.framework.core.enums.BranchState BranchState}
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/TransactionEndpoint.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/TransactionEndpoint.java
index 12fd7ef6f0..d5a0afe4e0 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/TransactionEndpoint.java
+++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/TransactionEndpoint.java
@@ -19,6 +19,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.eclipse.osee.orcs.transaction.CompareResults;
/**
* @author Roberto E. Escobar
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
index c7c97a5f7a..0d05441708 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
@@ -62,13 +62,13 @@ import org.eclipse.osee.orcs.rest.model.BranchEndpoint;
import org.eclipse.osee.orcs.rest.model.BranchExportOptions;
import org.eclipse.osee.orcs.rest.model.BranchImportOptions;
import org.eclipse.osee.orcs.rest.model.BranchQueryData;
-import org.eclipse.osee.orcs.rest.model.CompareResults;
import org.eclipse.osee.orcs.rest.model.NewBranch;
import org.eclipse.osee.orcs.rest.model.NewTransaction;
import org.eclipse.osee.orcs.rest.model.Transaction;
import org.eclipse.osee.orcs.search.BranchQuery;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.search.TransactionQuery;
+import org.eclipse.osee.orcs.transaction.CompareResults;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.eclipse.osee.orcs.transaction.TransactionFactory;
import com.google.common.collect.Lists;
@@ -131,9 +131,9 @@ public class BranchEndpointImpl implements BranchEndpoint {
private BranchReadable getBranchById(long branchUuid) {
ResultSet<BranchReadable> results = newBranchQuery().andUuids(branchUuid)//
- .includeArchived()//
- .includeDeleted()//
- .getResults();
+ .includeArchived()//
+ .includeDeleted()//
+ .getResults();
return results.getExactlyOne();
}
@@ -149,9 +149,9 @@ public class BranchEndpointImpl implements BranchEndpoint {
@Override
public List<Branch> getBranches() {
ResultSet<BranchReadable> results = newBranchQuery()//
- .includeArchived()//
- .includeDeleted()//
- .getResults();
+ .includeArchived()//
+ .includeDeleted()//
+ .getResults();
return asBranches(results);
}
@@ -212,20 +212,20 @@ public class BranchEndpointImpl implements BranchEndpoint {
@Override
public List<Branch> getBaselineBranches() {
ResultSet<BranchReadable> results = newBranchQuery()//
- .includeArchived(false) //
- .includeDeleted(false) //
- .andIsOfType(BranchType.BASELINE)//
- .getResults();
+ .includeArchived(false) //
+ .includeDeleted(false) //
+ .andIsOfType(BranchType.BASELINE)//
+ .getResults();
return asBranches(results);
}
@Override
public List<Branch> getWorkingBranches() {
ResultSet<BranchReadable> results = newBranchQuery()//
- .includeArchived(false) //
- .includeDeleted(false) //
- .andIsOfType(BranchType.WORKING)//
- .getResults();
+ .includeArchived(false) //
+ .includeDeleted(false) //
+ .andIsOfType(BranchType.WORKING)//
+ .getResults();
return asBranches(results);
}
@@ -504,9 +504,9 @@ public class BranchEndpointImpl implements BranchEndpoint {
private List<IOseeBranch> getExportImportBranches(Collection<Long> branchUids) {
ResultSet<IOseeBranch> resultsAsId = newBranchQuery().andUuids(branchUids) //
- .includeArchived()//
- .includeDeleted()//
- .getResultsAsId();
+ .includeArchived()//
+ .includeDeleted()//
+ .getResultsAsId();
return Lists.newLinkedList(resultsAsId);
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
index f8192a7054..d6605fce14 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
@@ -60,7 +60,7 @@ public class OrcsApplication extends Application {
resources.add(new BranchEndpointImpl(orcsApi, resourceManager));
resources.add(new OrcsWriterEndpointImpl(orcsApi));
- resources.add(new TransactionEndpointImpl(orcsApi));
+ resources.add(new TransactionEndpointImpl(orcsApi));
resources.add(new TypesEndpointImpl(orcsApi));
resources.add(new IndexerEndpointImpl(orcsApi));
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/TransactionEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/TransactionEndpointImpl.java
index 7230ef6415..68624b14ea 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/TransactionEndpointImpl.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/TransactionEndpointImpl.java
@@ -10,38 +10,16 @@
*******************************************************************************/
package org.eclipse.osee.orcs.rest.internal;
-import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asIntegerList;
import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asResponse;
-import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransaction;
-import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransactions;
-import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.executeCallable;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Callable;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
-import org.eclipse.osee.framework.core.enums.CoreBranches;
-import org.eclipse.osee.framework.core.model.change.ChangeItem;
-import org.eclipse.osee.framework.jdk.core.type.ResultSet;
-import org.eclipse.osee.framework.jdk.core.util.Compare;
-import org.eclipse.osee.jaxrs.OseeWebApplicationException;
import org.eclipse.osee.orcs.OrcsApi;
-import org.eclipse.osee.orcs.OrcsBranch;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.TransactionReadable;
-import org.eclipse.osee.orcs.rest.model.CompareResults;
import org.eclipse.osee.orcs.rest.model.Transaction;
import org.eclipse.osee.orcs.rest.model.TransactionEndpoint;
-import org.eclipse.osee.orcs.search.QueryFactory;
-import org.eclipse.osee.orcs.search.TransactionQuery;
-import org.eclipse.osee.orcs.transaction.TransactionBuilder;
-import org.eclipse.osee.orcs.transaction.TransactionFactory;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.collect.Sets.SetView;
+import org.eclipse.osee.orcs.transaction.CompareResults;
/**
* @author Roberto E. Escobar
@@ -60,118 +38,36 @@ public class TransactionEndpointImpl implements TransactionEndpoint {
protected void setUriInfo(UriInfo uriInfo) {
this.uriInfo = uriInfo;
}
-
- private TransactionQuery newTxQuery() {
- return orcsApi.getQueryFactory().transactionQuery();
- }
-
- private OrcsBranch getBranchOps() {
- return orcsApi.getBranchOps();
- }
-
- private TransactionFactory newTxFactory() {
- return orcsApi.getTransactionFactory();
- }
-
- private QueryFactory newQueryFactory() {
- return orcsApi.getQueryFactory();
- }
-
- private TransactionReadable getTxById(int txId) {
- ResultSet<TransactionReadable> results = newTxQuery().andTxId(txId).getResults();
- return results.getExactlyOne();
- }
-
@Override
public List<Transaction> getAllTxs() {
- ResultSet<TransactionReadable> results = newTxQuery().getResults();
- return asTransactions(results);
+ return OrcsRestUtil.asTransactions(orcsApi.getTransactionFactory().getAllTxs());
}
@Override
public Transaction getTx(int txId) {
- TransactionReadable tx = getTxById(txId);
- return asTransaction(tx);
+ TransactionReadable tx = orcsApi.getTransactionFactory().getTxById(txId);
+ return OrcsRestUtil.asTransaction(tx);
}
@Override
public CompareResults compareTxs(int txId1, int txId2) {
- TransactionReadable sourceTx = getTxById(txId1);
- TransactionReadable destinationTx = getTxById(txId2);
- Callable<List<ChangeItem>> callable = getBranchOps().compareBranch(sourceTx, destinationTx);
- List<ChangeItem> changes = executeCallable(callable);
-
- CompareResults data = new CompareResults();
- data.setChanges(changes);
- return data;
+ return orcsApi.getTransactionFactory().compareTxs(txId1, txId2);
}
@Override
public Response setTxComment(int txId, String comment) {
- TransactionReadable tx = getTxById(txId);
- boolean modified = false;
- if (Compare.isDifferent(tx.getComment(), comment)) {
- TransactionFactory txFactory = newTxFactory();
- txFactory.setTransactionComment(tx, comment);
- modified = true;
- }
- return asResponse(modified);
+ return OrcsRestUtil.asResponse(orcsApi.getTransactionFactory().setTxComment(txId, comment));
}
@Override
public Response purgeTxs(String txIds) {
- boolean modified = false;
- List<Integer> txsToDelete = asIntegerList(txIds);
- if (!txsToDelete.isEmpty()) {
- ResultSet<TransactionReadable> results = newTxQuery().andTxIds(txsToDelete).getResults();
- if (!results.isEmpty()) {
- checkAllTxsFound("Purge Transaction", txsToDelete, results);
- List<TransactionReadable> list = Lists.newArrayList(results);
- Callable<?> op = newTxFactory().purgeTransaction(list);
- executeCallable(op);
- modified = true;
- }
- }
- return asResponse(modified);
+ return asResponse(orcsApi.getTransactionFactory().purgeTxs(txIds));
}
@Override
public Response replaceWithBaselineTxVersion(String userId, long branchId, int txId, int artId, String comment) {
- boolean introduced = false;
- ArtifactReadable userReadable =
- newQueryFactory().fromBranch(CoreBranches.COMMON).andGuid(userId).getResults().getOneOrNull();
- ArtifactReadable baselineArtifact =
- newQueryFactory().fromBranch(branchId).fromTransaction(txId).andUuid(artId).getResults().getOneOrNull();
-
- if (userReadable != null && baselineArtifact != null) {
- TransactionBuilder tx = newTxFactory().createTransaction(branchId, userReadable, comment);
- ArtifactReadable destination =
- newQueryFactory().fromBranch(branchId).includeDeletedArtifacts().andUuid(artId).getResults().getOneOrNull();
- tx.replaceWithVersion(baselineArtifact, destination);
- tx.commit();
- introduced = true;
- } else {
- throw new OseeWebApplicationException(Status.BAD_REQUEST,
- "%s Error - The user and baseline artifact were not found.", comment);
- }
-
- return asResponse(introduced);
- }
-
- private void checkAllTxsFound(String opName, List<Integer> txIds, ResultSet<TransactionReadable> result) {
- if (txIds.size() != result.size()) {
- Set<Integer> found = new HashSet<Integer>();
- for (TransactionReadable tx : result) {
- found.add(tx.getGuid());
- }
- SetView<Integer> difference = Sets.difference(Sets.newHashSet(txIds), found);
- if (!difference.isEmpty()) {
- throw new OseeWebApplicationException(
- Status.BAD_REQUEST,
- "%s Error - The following transactions from %s were not found - txs %s - Please remove them from the request and try again.",
- opName, txIds, difference);
- }
- }
+ return OrcsRestUtil.asResponse(orcsApi.getTransactionFactory().replaceWithBaselineTxVersion(userId, branchId,
+ txId, artId, comment));
}
}
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsApi.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsApi.java
index 8a88a6173d..a96781b56e 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsApi.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsApi.java
@@ -36,5 +36,4 @@ public interface OrcsApi {
OrcsTypes getOrcsTypes();
ScriptEngine getScriptEngine();
-
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/CompareResults.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/CompareResults.java
index 35cf58e649..a5fd002c4c 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/CompareResults.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/CompareResults.java
@@ -8,7 +8,7 @@
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
-package org.eclipse.osee.orcs.rest.model;
+package org.eclipse.osee.orcs.transaction;
import java.util.Collections;
import java.util.List;
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
index c3bab3a49c..a6ec319051 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
@@ -15,7 +15,9 @@ import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.ITransaction;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.data.TransactionReadable;
/**
* @author Roberto E. Escobar
@@ -29,4 +31,18 @@ public interface TransactionFactory {
Callable<Integer> purgeTransaction(Collection<? extends ITransaction> transactions);
Callable<Void> setTransactionComment(ITransaction transaction, String comment);
+
+ CompareResults compareTxs(int txId1, int txId2);
+
+ ResultSet<TransactionReadable> getAllTxs();
+
+ TransactionReadable getTx(int txId);
+
+ TransactionReadable getTxById(int txId);
+
+ boolean setTxComment(int txId, String comment);
+
+ boolean replaceWithBaselineTxVersion(String userId, long branchId, int txId, int artId, String comment);
+
+ boolean purgeTxs(String txIds);
}

Back to the top