diff options
author | Branden Phillips | 2021-03-24 21:52:15 +0000 |
---|---|---|
committer | Ryan T. Baldwin | 2021-03-24 21:52:15 +0000 |
commit | bb4581365c3247543654432c7d9343c9ee28004c (patch) | |
tree | 29c184b2e5afcf36538702f712d9e4a711f22b0c /plugins/org.eclipse.osee.framework.skynet.core | |
parent | 41a62d7e59b103a7a46667f9b16020cc905aeaa0 (diff) | |
download | org.eclipse.osee-bb4581365c3247543654432c7d9343c9ee28004c.tar.gz org.eclipse.osee-bb4581365c3247543654432c7d9343c9ee28004c.tar.xz org.eclipse.osee-bb4581365c3247543654432c7d9343c9ee28004c.zip |
feature[ATS288813]: Change Resource History to load through REST API
Change-Id: I8f3e86755c7adace80c35671cc959b20bb4c9d77
Signed-off-by: Branden Phillips <branden.w.phillips@boeing.com>
Diffstat (limited to 'plugins/org.eclipse.osee.framework.skynet.core')
10 files changed, 244 insertions, 929 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChangeBuilder.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChangeBuilder.java deleted file mode 100644 index db56410a337..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChangeBuilder.java +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************* - * Copyright (c) 2004, 2007 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.change; - -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; - -/** - * @author Jeff C. Phillips - */ -public class ArtifactChangeBuilder extends ChangeBuilder { - - public ArtifactChangeBuilder(BranchId branch, ArtifactTypeId artifactType, GammaId sourceGamma, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, boolean isHistorical) { - super(branch, artifactType, sourceGamma, artId, txDelta, modType, isHistorical); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeBuilder.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeBuilder.java deleted file mode 100644 index 501ad22fe6b..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -/********************************************************************* - * Copyright (c) 2004, 2007 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.change; - -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.AttributeTypeToken; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; - -/** - * @author Jeff C. Phillips - */ -public final class AttributeChangeBuilder extends ChangeBuilder { - private final String isValue; - private String wasValue; - private final int attrId; - private final AttributeTypeToken attributeType; - private final ModificationType artModType; - private final String isUri; - private String wasUri; - - public AttributeChangeBuilder(BranchId branch, ArtifactTypeId artifactType, GammaId sourceGamma, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, boolean isHistorical, String isValue, String wasValue, int attrId, AttributeTypeToken attributeType, ModificationType artModType, String isUri, String wasUri) { - super(branch, artifactType, sourceGamma, artId, txDelta, modType, isHistorical); - this.isValue = isValue; - this.wasValue = wasValue; - this.attrId = attrId; - this.attributeType = attributeType; - this.artModType = artModType; - this.isUri = isUri; - this.wasUri = wasUri; - } - - public ModificationType getArtModType() { - return artModType; - } - - public void setWasValue(String wasValue) { - this.wasValue = wasValue; - } - - public String getIsValue() { - return isValue; - } - - public String getWasValue() { - return wasValue; - } - - public int getAttrId() { - return attrId; - } - - public AttributeTypeToken getAttributeType() { - return attributeType; - } - - public String getIsUri() { - return isUri; - } - - public String getWasUri() { - return wasUri; - } - - public void setWasUri(String wasUri) { - this.wasUri = wasUri; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeBuilder.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeBuilder.java deleted file mode 100644 index 2b36f08fb71..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -/********************************************************************* - * Copyright (c) 2004, 2007 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.change; - -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; - -/** - * @author Jeff C. Phillips - */ -public abstract class ChangeBuilder { - private final GammaId sourceGamma; - private final ArtifactId artId; - private final TransactionDelta txDelta; - private ModificationType modType; - private final BranchId branch; - private final ArtifactTypeId artifactType; - private final boolean isHistorical; - - public ChangeBuilder(BranchId branch, ArtifactTypeId artifactType, GammaId sourceGamma, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, boolean isHistorical) { - this.sourceGamma = sourceGamma; - this.artId = artId; - this.txDelta = txDelta; - this.modType = modType; - this.branch = branch; - this.artifactType = artifactType; - this.isHistorical = isHistorical; - } - - public GammaId getSourceGamma() { - return sourceGamma; - } - - public ArtifactId getArtId() { - return artId; - } - - public TransactionDelta getTxDelta() { - return txDelta; - } - - public ModificationType getModType() { - return modType; - } - - public void setModType(ModificationType modType) { - this.modType = modType; - } - - public BranchId getBranch() { - return branch; - } - - public ArtifactTypeId getArtifactType() { - return artifactType; - } - - public boolean isHistorical() { - return isHistorical; - } - -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChangeBuilder.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChangeBuilder.java deleted file mode 100644 index 942c4e5010c..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChangeBuilder.java +++ /dev/null @@ -1,56 +0,0 @@ -/********************************************************************* - * Copyright (c) 2004, 2007 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.change; - -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.data.RelationTypeToken; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; - -/** - * @author Jeff C. Phillips - */ -public class RelationChangeBuilder extends ChangeBuilder { - private final ArtifactId bArtId; - private final int relLinkId; - private final String rationale; - private final RelationTypeToken relationType; - - public RelationChangeBuilder(BranchId branch, ArtifactTypeId artifactType, GammaId sourceGamma, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, ArtifactId bArtId, int relLinkId, String rationale, RelationTypeToken relationType, boolean isHistorical) { - super(branch, artifactType, sourceGamma, artId, txDelta, modType, isHistorical); - this.bArtId = bArtId; - this.relLinkId = relLinkId; - this.rationale = rationale; - this.relationType = relationType; - } - - public ArtifactId getbArtId() { - return bArtId; - } - - public int getRelLinkId() { - return relLinkId; - } - - public String getRationale() { - return rationale; - } - - public RelationTypeToken getRelationType() { - return relationType; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java index 1bff8a889f6..bb1005a0390 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java @@ -62,18 +62,27 @@ public final class ChangeManager { } /** - * Acquires changes for a particular artifact + * Gets all artifact, attribute, and relation changes for the given artifact */ public static Collection<Change> getChangesPerArtifact(Artifact artifact, IProgressMonitor monitor) { - return revsionChangeLoader.getChangesPerArtifact(artifact, monitor); + return revsionChangeLoader.getChangesPerArtifact(artifact, monitor, ChangeType.Artifact, ChangeType.Attribute, + ChangeType.Relation); } + /** + * Gets all requested change types for the given artifact + */ public static Collection<Change> getChangesPerArtifact(Artifact artifact, IProgressMonitor monitor, ChangeType... loadChangeTypes) { return revsionChangeLoader.getChangesPerArtifact(artifact, monitor, loadChangeTypes); } + /** + * Gets the artifact, attribute, and relation changes for the specified number of transactions related to the given + * artifact + */ public static Collection<? extends Change> getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor) { - return revsionChangeLoader.getChangesPerArtifact(artifact, numberTransactionsToShow, monitor); + return revsionChangeLoader.getChangesPerArtifact(artifact, numberTransactionsToShow, monitor, ChangeType.Artifact, + ChangeType.Attribute, ChangeType.Relation); } /** @@ -154,8 +163,7 @@ public final class ChangeManager { public static HashCollection<Artifact, BranchId> getModifingBranches(Collection<Artifact> artifacts) { HashCollection<Artifact, BranchId> branchMap = new HashCollection<>(); try (Id4JoinQuery joinQuery = JoinUtility.createId4JoinQuery()) { - CompositeKeyHashMap<Integer, BranchId, Artifact> artifactMap = - new CompositeKeyHashMap<>(); + CompositeKeyHashMap<Integer, BranchId, Artifact> artifactMap = new CompositeKeyHashMap<>(); for (Artifact artifact : artifacts) { artifactMap.put(artifact.getArtId(), artifact.getBranch(), artifact); // for each combination of artifact and all working branches in its hierarchy diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java index d8aa54babae..9db05034e16 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java @@ -17,249 +17,313 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.osee.framework.core.OrcsTokenService; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.AttributeId; +import org.eclipse.osee.framework.core.data.AttributeTypeToken; import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.GammaId; import org.eclipse.osee.framework.core.data.RelationId; -import org.eclipse.osee.framework.core.data.TransactionId; +import org.eclipse.osee.framework.core.data.RelationTypeToken; import org.eclipse.osee.framework.core.data.TransactionToken; import org.eclipse.osee.framework.core.enums.DeletionFlag; -import org.eclipse.osee.framework.core.model.TransactionRecord; +import org.eclipse.osee.framework.core.enums.ModificationType; +import org.eclipse.osee.framework.core.model.TransactionDelta; +import org.eclipse.osee.framework.core.model.change.ChangeItem; +import org.eclipse.osee.framework.core.model.change.ChangeItemUtil; import org.eclipse.osee.framework.core.model.change.ChangeType; -import org.eclipse.osee.framework.core.sql.OseeSql; +import org.eclipse.osee.framework.core.model.change.ChangeVersion; import org.eclipse.osee.framework.core.util.OsgiUtil; import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; import org.eclipse.osee.framework.jdk.core.type.HashCollectionSet; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.ArtifactLoader; -import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; import org.eclipse.osee.framework.skynet.core.change.ArtifactChange; -import org.eclipse.osee.framework.skynet.core.change.ArtifactChangeBuilder; import org.eclipse.osee.framework.skynet.core.change.ArtifactDelta; import org.eclipse.osee.framework.skynet.core.change.AttributeChange; -import org.eclipse.osee.framework.skynet.core.change.AttributeChangeBuilder; import org.eclipse.osee.framework.skynet.core.change.Change; -import org.eclipse.osee.framework.skynet.core.change.ChangeBuilder; import org.eclipse.osee.framework.skynet.core.change.RelationChange; -import org.eclipse.osee.framework.skynet.core.change.RelationChangeBuilder; import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; -import org.eclipse.osee.framework.skynet.core.revision.acquirer.ArtifactChangeAcquirer; -import org.eclipse.osee.framework.skynet.core.revision.acquirer.AttributeChangeAcquirer; -import org.eclipse.osee.framework.skynet.core.revision.acquirer.RelationChangeAcquirer; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionIdComparator; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; -import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; -import org.eclipse.osee.jdbc.JdbcStatement; +import org.eclipse.osee.orcs.rest.client.OseeClient; +import org.eclipse.osee.orcs.rest.model.TransactionEndpoint; /** - * Acquires changes for either branches or transactions. + * Acquires changes for a single given artifact. See LoadArtifactHistory for the server-side loading of this data. * * @author Jeff C. Phillips + * @author Branden w. Phillips */ public final class RevisionChangeLoader { private final OrcsTokenService tokenService; + private final List<ChangeType> loadChangeTypes = new ArrayList<>(); protected RevisionChangeLoader() { this.tokenService = OsgiUtil.getService(ArtifactLoader.class, OrcsTokenService.class); } /** - * @return Returns artifact, relation and attribute changes from a specific artifact + * @return Returns all given changes from a specified artifact */ - public Collection<Change> getChangesPerArtifact(Artifact artifact, IProgressMonitor monitor) { - return getChangesPerArtifact(artifact, monitor, ChangeType.Artifact, ChangeType.Attribute, ChangeType.Relation); + public Collection<Change> getChangesPerArtifact(Artifact artifact, IProgressMonitor monitor, ChangeType... loadChangeTypes) { + this.loadChangeTypes.clear(); + for (ChangeType changeType : loadChangeTypes) { + this.loadChangeTypes.add(changeType); + } + + return getChangesPerArtifact(artifact, -1, monitor); } /** - * @return Returns artifact, relation and attribute changes from a specific artifact + * @return Returns limited amount of changes from a specified artifact */ - public Collection<Change> getChangesPerArtifact(Artifact artifact, IProgressMonitor monitor, ChangeType... loadChangeTypes) { - BranchId branch = artifact.getBranch(); - Set<TransactionToken> transactionIds = new LinkedHashSet<>(); - boolean recurseThroughBranchHierarchy = true; - loadBranchTransactions(branch, artifact, transactionIds, TransactionManager.getHeadTransaction(branch), - recurseThroughBranchHierarchy); - - Collection<Change> changes = new ArrayList<>(); - - for (TransactionToken transactionId : transactionIds) { - loadChanges(null, transactionId, monitor, artifact, changes, loadChangeTypes); + public Collection<Change> getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor, ChangeType... loadChangeTypes) { + this.loadChangeTypes.clear(); + for (ChangeType changeType : loadChangeTypes) { + this.loadChangeTypes.add(changeType); } - return changes; - } - public Collection<? extends Change> getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor) { - BranchId branch = artifact.getBranch(); - Set<TransactionToken> transactionIds = new LinkedHashSet<>(); - boolean recurseThroughBranchHierarchy = true; - loadBranchTransactions(branch, artifact, transactionIds, TransactionManager.getHeadTransaction(branch), - recurseThroughBranchHierarchy); - - Collection<Change> changes = new ArrayList<>(); - List<TransactionToken> sortedTransIds = new ArrayList<>(); - sortedTransIds.addAll(transactionIds); - Collections.sort(sortedTransIds, new TransactionIdComparator()); - Collections.reverse(sortedTransIds); - - int count = 0; - for (TransactionToken transactionId : sortedTransIds) { - loadChanges(null, transactionId, monitor, artifact, changes, ChangeType.Artifact, ChangeType.Attribute, - ChangeType.Relation); - count++; - if (count >= numberTransactionsToShow) { - break; - } - } - return changes; + return getChangesPerArtifact(artifact, numberTransactionsToShow, monitor); } - private void loadBranchTransactions(BranchId branch, Artifact artifact, Set<TransactionToken> transactionIds, TransactionId transactionId, boolean recurseThroughBranchHierarchy) { - loadTransactions(branch, artifact, transactionId, transactionIds); - - if (recurseThroughBranchHierarchy) { - BranchId parentBranch = BranchManager.getParentBranch(branch); - TransactionRecord baseTx = BranchManager.getBaseTransaction(branch); - - if (!BranchManager.isParentSystemRoot(branch)) { - loadBranchTransactions(parentBranch, artifact, transactionIds, baseTx, recurseThroughBranchHierarchy); - } - } - } + /** + * Gets the list of ChangeItems for the specified artifact on the branch, if necessary it will trim down the + * transactions. Pre-Loads the artifacts from the found artifact ids and transactions, and then creates the + * collection of changes to return + */ + private Collection<Change> getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor) { + Collection<Change> changes = new ArrayList<>(); - private void loadTransactions(BranchId branch, Artifact artifact, TransactionId transactionId, Set<TransactionToken> transactionIds) { - JdbcStatement chStmt = ConnectionHandler.getStatement(); + OseeClient client = ServiceUtil.getOseeClient(); + TransactionEndpoint txEndpoint = client.getTransactionEndpoint(); try { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.LOAD_REVISION_HISTORY_TRANSACTION_ATTR), artifact, branch, - transactionId); - - while (chStmt.next()) { - transactionIds.add(TransactionToken.valueOf(chStmt.getLong("transaction_id"), branch)); - } - - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.LOAD_REVISION_HISTORY_TRANSACTION_REL), artifact, artifact, - branch, transactionId); - - while (chStmt.next()) { - transactionIds.add(TransactionToken.valueOf(chStmt.getLong("transaction_id"), branch)); + List<ChangeItem> changeItems = txEndpoint.getArtifactHistory(artifact, artifact.getBranch()); + if (!changeItems.isEmpty()) { + if (numberTransactionsToShow > 0) { + changeItems = trimTransactions(changeItems, numberTransactionsToShow); + } + CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap = getBulkLoadedArtifacts(changeItems); + changes = getChanges(changeItems, loadedMap, numberTransactionsToShow); } - } finally { - chStmt.close(); + } catch (Exception ex) { + throw OseeCoreException.wrap(ex); } + + return changes; } /** - * Not Part of Change Report Acquires artifact, relation and attribute changes from a source branch since its - * creation. + * This method loops through changes and only keeps those that are within the amount of transactions asked to be + * loaded. */ - private void loadChanges(BranchId sourceBranch, TransactionToken transactionId, IProgressMonitor monitor, Artifact specificArtifact, Collection<Change> changes, ChangeType... loadChangeTypes) { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - monitor.beginTask("Find Changes", 100); - - Set<ArtifactId> artIds = new HashSet<>(); - Set<ArtifactId> newAndDeletedArtifactIds = new HashSet<>(); - boolean isHistorical = sourceBranch == null; - - ArrayList<ChangeBuilder> changeBuilders = new ArrayList<>(); - for (ChangeType changeType : loadChangeTypes) { - if (changeType.isArtifactChange()) { - ArtifactChangeAcquirer artifactChangeAcquirer = new ArtifactChangeAcquirer(sourceBranch, transactionId, - monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds); - changeBuilders = artifactChangeAcquirer.acquireChanges(); - } else if (changeType.isAttributeChange()) { - AttributeChangeAcquirer attributeChangeAcquirer = new AttributeChangeAcquirer(sourceBranch, transactionId, - monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds, tokenService); - changeBuilders = attributeChangeAcquirer.acquireChanges(); - } else if (changeType.isRelationChange()) { - RelationChangeAcquirer relationChangeAcquirer = new RelationChangeAcquirer(sourceBranch, transactionId, - monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds, tokenService); - - changeBuilders = relationChangeAcquirer.acquireChanges(); + private List<ChangeItem> trimTransactions(List<ChangeItem> changeItems, int numberTransactionsToShow) { + List<ChangeItem> changeItemsToReturn = new ArrayList<>(); + Collections.reverse(changeItems); + Set<TransactionToken> txSet = new HashSet<>(); + + for (ChangeItem item : changeItems) { + TransactionToken txToken = item.getCurrentVersion().getTransactionToken(); + if (!txSet.contains(txToken)) { + if (txSet.size() == numberTransactionsToShow) { + break; + } + txSet.add(txToken); } + changeItemsToReturn.add(0, item); } - monitor.subTask("Loading Artifacts from the Database"); - - BranchId branch = isHistorical ? transactionId.getBranch() : sourceBranch; - - Collection<Change> changesLoaded = getChanges(branch, isHistorical, changeBuilders); - changes.addAll(changesLoaded); - - monitor.done(); + return changeItemsToReturn; } - private CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> getBulkLoadedArtifacts(BranchId branch, boolean isHistorical, List<ChangeBuilder> changeBuilders) { - HashCollectionSet<TransactionToken, ArtifactId> loadMap = new HashCollectionSet<>(HashSet::new); - for (ChangeBuilder builder : changeBuilders) { - TransactionToken endTx = builder.getTxDelta().getEndTx(); - loadMap.put(endTx, builder.getArtId()); - if (builder instanceof RelationChangeBuilder) { - RelationChangeBuilder relBuilder = (RelationChangeBuilder) builder; - loadMap.put(endTx, relBuilder.getbArtId()); + /** + * Loads the artifacts for the given change items. + */ + private CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> getBulkLoadedArtifacts(List<ChangeItem> changeItems) { + CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap = new CompositeKeyHashMap<>(); + HashCollectionSet<TransactionToken, ArtifactId> txToArtIdMap = new HashCollectionSet<>(); + + /** + * Loops through each change item and extracts the transaction tokens and artifact ids that will need to be loaded + */ + for (ChangeItem item : changeItems) { + txToArtIdMap.put(item.getCurrentVersion().getTransactionToken(), item.getArtId()); + if (item.getChangeType().isRelationChange()) { + txToArtIdMap.put(item.getCurrentVersion().getTransactionToken(), item.getArtIdB()); } } - CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap = new CompositeKeyHashMap<>(); - - for (Entry<TransactionToken, Set<ArtifactId>> entry : loadMap.entrySet()) { - Collection<Artifact> artifacts; - if (isHistorical) { - artifacts = ArtifactQuery.getHistoricalArtifactListFromIds(entry.getValue(), entry.getKey(), - DeletionFlag.INCLUDE_DELETED); + /** + * First we grab the most recent transaction token because the top entry should be the most current version of the + * artifact. Then it loops through each transaction/artifactid combination and either loads the current version, + * or historical versions. Finally loading those found artifacts into the map + */ + TransactionToken lastTx = changeItems.get(changeItems.size() - 1).getCurrentVersion().getTransactionToken(); + for (Entry<TransactionToken, Set<ArtifactId>> entry : txToArtIdMap.entrySet()) { + TransactionToken txToken = entry.getKey(); + List<Artifact> artifacts; + if (txToken.equals(lastTx)) { + artifacts = + ArtifactQuery.getArtifactListFrom(entry.getValue(), txToken.getBranch(), DeletionFlag.INCLUDE_DELETED); } else { - artifacts = ArtifactQuery.getArtifactListFrom(entry.getValue(), branch); + artifacts = + ArtifactQuery.getHistoricalArtifactListFromIds(entry.getValue(), txToken, DeletionFlag.INCLUDE_DELETED); } - for (Artifact artifact : artifacts) { - loadedMap.put(entry.getKey(), artifact, artifact); + for (Artifact art : artifacts) { + loadedMap.put(txToken, ArtifactId.valueOf(art.getId()), art); } } + return loadedMap; } - private Collection<Change> getChanges(BranchId branch, boolean isHistorical, List<ChangeBuilder> changeBuilders) { - CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap = - getBulkLoadedArtifacts(branch, isHistorical, changeBuilders); - + /** + * This method is what loops through the given ChangeItems and creates a collection of changes. This will only + * process/add in changes that were previously set in the loadChangeTypes array. + */ + private Collection<Change> getChanges(Collection<ChangeItem> changeItems, CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap, int numberTransactionsToShow) { Collection<Change> changes = new ArrayList<>(); - for (ChangeBuilder builder : changeBuilders) { - Change toReturn = null; - Artifact changeArtifact = loadedMap.get(builder.getTxDelta().getEndTx(), builder.getArtId()); - + List<TransactionToken> modifiedTxs = new ArrayList<>(); + + for (ChangeItem changeItem : changeItems) { + ChangeVersion currentVersion = changeItem.getCurrentVersion(); + TransactionToken currentTx = currentVersion.getTransactionToken(); + ArtifactId changeArtId = changeItem.getArtId(); + BranchId currentBranch = currentTx.getBranch(); + GammaId currentGammaId = currentVersion.getGammaId(); + ModificationType modType = currentVersion.getModType(); + ChangeVersion startVersion = changeItem.getBaselineVersion(); + Artifact baselineArtifact; + TransactionToken startTx; + if (startVersion.isValid()) { + startTx = startVersion.getTransactionToken(); + baselineArtifact = loadedMap.get(startTx, changeArtId); + } else { + startTx = currentTx; + baselineArtifact = Artifact.SENTINEL; + } + TransactionDelta txDelta = new TransactionDelta(startTx, currentTx); + Artifact changeArtifact = loadedMap.get(currentVersion.getTransactionToken(), changeArtId); if (changeArtifact != null) { - ArtifactDelta delta = new ArtifactDelta(builder.getTxDelta(), changeArtifact, null); - if (builder instanceof ArtifactChangeBuilder) { - toReturn = new ArtifactChange(branch, builder.getSourceGamma(), builder.getArtId(), builder.getTxDelta(), - builder.getModType(), "", "", isHistorical, changeArtifact, delta); - } else if (builder instanceof AttributeChangeBuilder) { - AttributeChangeBuilder attrBuilder = (AttributeChangeBuilder) builder; - toReturn = new AttributeChange(branch, attrBuilder.getSourceGamma(), attrBuilder.getArtId(), - attrBuilder.getTxDelta(), attrBuilder.getModType(), attrBuilder.getIsValue(), attrBuilder.getIsUri(), - attrBuilder.getWasValue(), attrBuilder.getWasUri(), AttributeId.valueOf(attrBuilder.getAttrId()), - attrBuilder.getAttributeType(), attrBuilder.getArtModType(), isHistorical, changeArtifact, delta); - } else if (builder instanceof RelationChangeBuilder) { - RelationChangeBuilder relBuilder = (RelationChangeBuilder) builder; - Artifact bArtifact = loadedMap.get(builder.getTxDelta().getEndTx(), relBuilder.getbArtId()); - toReturn = new RelationChange(branch, builder.getSourceGamma(), builder.getArtId(), builder.getTxDelta(), - builder.getModType(), relBuilder.getbArtId(), - RelationId.valueOf(Long.valueOf(relBuilder.getRelLinkId())), relBuilder.getRationale(), "", - relBuilder.getRelationType(), isHistorical, changeArtifact, delta, bArtifact); + ArtifactDelta artDelta = new ArtifactDelta(txDelta, baselineArtifact, changeArtifact); + boolean isHistorical = changeArtifact.isHistorical(); + + ChangeType changeType = changeItem.getChangeType(); + if (changeType.isArtifactChange() && loadChangeTypes.contains(changeType)) { + ArtifactChange artChange = new ArtifactChange(currentBranch, currentGammaId, changeArtId, txDelta, + modType, "", "", isHistorical, changeArtifact, artDelta); + changes.add(artChange); + + /** + * This if statement calculates if the artifact ChangeItem contains an applicability change<br/> + * 1. isApplicabilityCopy<br/> + * 2. The start/current version applicabilites aren't the same, AND either the start version is valid or + * it is a modification type of new. This handles modified applicabilites, or the artifact being brought + * onto a branch<br/> + * 3. The modification type is a deleted type and the start version is valid. This handles when the + * artifact is being deleted from a branch where it previously existed<br/> + */ + if (changeItem.isApplicabilityCopy() || ((startVersion.isValid() || modType.equals( + ModificationType.NEW)) && !ChangeItemUtil.areApplicabilitiesEqual(startVersion, + currentVersion)) || (ChangeItemUtil.isDeleted(currentVersion) && startVersion.isValid())) { + ArtifactChange applicChange = getApplicabilityChange(startVersion, currentVersion, currentBranch, + currentGammaId, changeArtId, txDelta, changeArtifact, artDelta); + + changes.add(applicChange); + } + if (!modifiedTxs.contains(currentTx)) { + modifiedTxs.add(currentTx); + } + } else if (changeType.isAttributeChange() && loadChangeTypes.contains(changeType)) { + if (!modifiedTxs.contains(currentTx) && loadChangeTypes.contains(ChangeType.Artifact)) { + /** + * For each transaction, this adds a modified artifact change along with the attribute changes + */ + ArtifactChange artChange = new ArtifactChange(currentBranch, GammaId.SENTINEL, changeArtId, txDelta, + ModificationType.MODIFIED, "", "", isHistorical, changeArtifact, artDelta); + changes.add(artChange); + modifiedTxs.add(currentTx); + } + + AttributeChange attrChange = getAttributeChange(changeItem, startVersion, currentVersion, currentBranch, + currentGammaId, changeArtId, txDelta, modType, changeArtifact, artDelta); + + changes.add(attrChange); + } else if (changeType.isRelationChange() && loadChangeTypes.contains(changeType)) { + if (!modifiedTxs.contains(currentTx) && loadChangeTypes.contains(ChangeType.Artifact)) { + /** + * For each transaction, this adds a modified artifact change along with the relation changes + */ + ArtifactChange artChange = new ArtifactChange(currentBranch, GammaId.SENTINEL, changeArtId, txDelta, + ModificationType.MODIFIED, "", "", true, changeArtifact, artDelta); + changes.add(artChange); + modifiedTxs.add(currentTx); + } + RelationChange relChange = getRelationChange(changeItem, loadedMap, startVersion, currentVersion, + currentBranch, currentGammaId, changeArtId, txDelta, modType, changeArtifact, artDelta); + + changes.add(relChange); } } else { - toReturn = new ArtifactChange(branch, builder.getSourceGamma(), builder.getArtId(), builder.getTxDelta(), - builder.getModType(), "", "", isHistorical, Artifact.SENTINEL, null); + /** + * If there was an issue finding an artifact when loading, this adds in a basic artifact change + */ + ArtifactChange change = new ArtifactChange(currentBranch, currentGammaId, changeArtId, txDelta, modType, "", + "", true, Artifact.SENTINEL, null); + changes.add(change); } - changes.add(toReturn); } + return changes; } + /** + * This method is used to get the applicability change, which is a type ArtifactChange. Uses the applicability token + * name for the was/is values. If the modtype is deleted, we do not include the isValue name, it becomes blank since + * it should no longer exist + */ + private ArtifactChange getApplicabilityChange(ChangeVersion startVersion, ChangeVersion currentVersion, BranchId branchId, GammaId gammaId, ArtifactId artId, TransactionDelta txDelta, Artifact artifact, ArtifactDelta artDelta) { + String wasValue = ""; + String isValue = ""; + if (startVersion.isValid()) { + wasValue = startVersion.getApplicabilityToken().getName(); + } + if (currentVersion.isValid() && !ChangeItemUtil.isDeleted(currentVersion)) { + isValue = currentVersion.getApplicabilityToken().getName(); + } + ArtifactChange applicChange = new ArtifactChange(branchId, gammaId, artId, txDelta, + ModificationType.APPLICABILITY, isValue, wasValue, artifact.isHistorical(), artifact, artDelta); + + return applicChange; + } + + private AttributeChange getAttributeChange(ChangeItem changeItem, ChangeVersion startVersion, ChangeVersion currentVersion, BranchId branchId, GammaId gammaId, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, Artifact artifact, ArtifactDelta artDelta) { + String isValue = currentVersion.getValue(); + String isUri = currentVersion.getUri(); + String wasValue = startVersion.getValue(); + String wasUri = startVersion.getUri(); + AttributeId attrId = AttributeId.valueOf(changeItem.getItemId().getId()); + AttributeTypeToken typeToken = tokenService.getAttributeType(changeItem.getItemTypeId().getId()); + + AttributeChange attrChange = new AttributeChange(branchId, gammaId, artId, txDelta, modType, isValue, isUri, + wasValue, wasUri, attrId, typeToken, modType, artifact.isHistorical(), artifact, artDelta); + + return attrChange; + } + + private RelationChange getRelationChange(ChangeItem changeItem, CompositeKeyHashMap<TransactionToken, ArtifactId, Artifact> loadedMap, ChangeVersion startVersion, ChangeVersion currentVersion, BranchId branchId, GammaId gammaId, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, Artifact artifact, ArtifactDelta artDelta) { + RelationId relationId = RelationId.valueOf(changeItem.getItemId().getId()); + String value = currentVersion.getValue(); + RelationTypeToken relationType = tokenService.getRelationType(changeItem.getItemTypeId().getId()); + Artifact artifactB = loadedMap.get(currentVersion.getTransactionToken(), changeItem.getArtIdB()); + + RelationChange relChange = new RelationChange(branchId, gammaId, artId, txDelta, modType, changeItem.getArtIdB(), + relationId, value, "", relationType, artifact.isHistorical(), artifact, artDelta, artifactB); + + return relChange; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java deleted file mode 100644 index 5294a85b1e5..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java +++ /dev/null @@ -1,106 +0,0 @@ -/********************************************************************* - * Copyright (c) 2010 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.revision.acquirer; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.OrcsTokenService; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.data.TransactionToken; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; -import org.eclipse.osee.framework.core.sql.OseeSql; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.change.ArtifactChangeBuilder; -import org.eclipse.osee.framework.skynet.core.change.ChangeBuilder; -import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; -import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; -import org.eclipse.osee.jdbc.JdbcStatement; - -/** - * @author Jeff C. Phillips - */ -public class ArtifactChangeAcquirer extends ChangeAcquirer { - - private static OrcsTokenService tokenService; - - public ArtifactChangeAcquirer(BranchId sourceBranch, TransactionToken transactionId, IProgressMonitor monitor, Artifact specificArtifact, Set<ArtifactId> artIds, ArrayList<ChangeBuilder> changeBuilders, Set<ArtifactId> newAndDeletedArtifactIds) { - super(sourceBranch, transactionId, monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds); - ArtifactChangeAcquirer.tokenService = ServiceUtil.getOrcsTokenService(); - } - - @Override - public ArrayList<ChangeBuilder> acquireChanges() { - Map<ArtifactId, ArtifactChangeBuilder> artifactChangeBuilders = new HashMap<>(); - boolean hasBranch = getSourceBranch() != null; - TransactionToken fromTransactionId; - TransactionToken toTransactionId; - - if (getMonitor() != null) { - getMonitor().subTask("Gathering New or Deleted Artifacts"); - } - JdbcStatement chStmt = ConnectionHandler.getStatement(); - try { - - if (hasBranch) { //Changes per a branch - fromTransactionId = getSourceBaseTransaction(); - toTransactionId = TransactionManager.getHeadTransaction(getSourceBranch()); - - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_BRANCH_ARTIFACT), getSourceBranch(), - fromTransactionId); - } else { //Changes per a transaction - toTransactionId = getTransaction(); - - if (getSpecificArtifact() != null) { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_ARTIFACT_FOR_SPECIFIC_ARTIFACT), - toTransactionId.getBranch(), toTransactionId, getSpecificArtifact()); - fromTransactionId = toTransactionId; - } else { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_ARTIFACT), toTransactionId.getBranch(), - toTransactionId.getId()); - fromTransactionId = TransactionManager.getPriorTransaction(toTransactionId); - } - } - - TransactionDelta txDelta = new TransactionDelta(fromTransactionId, toTransactionId); - - while (chStmt.next()) { - ArtifactId artId = ArtifactId.valueOf(chStmt.getLong("art_id")); - ModificationType modificationType = ModificationType.valueOf(chStmt.getInt("mod_type")); - - ArtifactChangeBuilder artifactChangeBuilder = - new ArtifactChangeBuilder(getSourceBranch(), tokenService.getArtifactType(chStmt.getLong("art_type_id")), - GammaId.valueOf(chStmt.getLong("gamma_id")), artId, txDelta, modificationType, !hasBranch); - - getArtIds().add(artId); - getChangeBuilders().add(artifactChangeBuilder); - artifactChangeBuilders.put(artId, artifactChangeBuilder); - } - - if (getMonitor() != null) { - getMonitor().worked(25); - } - } finally { - chStmt.close(); - } - - return getChangeBuilders(); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java deleted file mode 100644 index 22f3b41ef92..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java +++ /dev/null @@ -1,219 +0,0 @@ -/********************************************************************* - * Copyright (c) 2010 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.revision.acquirer; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.OrcsTokenService; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.AttributeTypeToken; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.data.TransactionId; -import org.eclipse.osee.framework.core.data.TransactionToken; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; -import org.eclipse.osee.framework.core.sql.OseeSql; -import org.eclipse.osee.framework.jdk.core.type.Id; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.change.ArtifactChangeBuilder; -import org.eclipse.osee.framework.skynet.core.change.AttributeChangeBuilder; -import org.eclipse.osee.framework.skynet.core.change.ChangeBuilder; -import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; -import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; -import org.eclipse.osee.framework.skynet.core.utility.Id4JoinQuery; -import org.eclipse.osee.framework.skynet.core.utility.JoinUtility; -import org.eclipse.osee.jdbc.JdbcStatement; - -/** - * @author Jeff C. Phillips - */ -public class AttributeChangeAcquirer extends ChangeAcquirer { - private final Map<Integer, ChangeBuilder> attributesWasValueCache = new HashMap<>(); - private final OrcsTokenService tokenService; - private int previousAttrId = -1; - - public AttributeChangeAcquirer(BranchId sourceBranch, TransactionToken transactionId, IProgressMonitor monitor, Artifact specificArtifact, Set<ArtifactId> artIds, ArrayList<ChangeBuilder> changeBuilders, Set<ArtifactId> newAndDeletedArtifactIds, OrcsTokenService tokenService) { - super(sourceBranch, transactionId, monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds); - this.tokenService = tokenService; - } - - @Override - public ArrayList<ChangeBuilder> acquireChanges() { - - Map<ArtifactId, ModificationType> artModTypes = new HashMap<>(); - Set<ArtifactId> modifiedArtifacts = new HashSet<>(); - JdbcStatement chStmt = ConnectionHandler.getStatement(); - boolean hasBranch = getSourceBranch() != null; - long time = System.currentTimeMillis(); - try { - if (getMonitor() != null) { - getMonitor().subTask("Gathering Attribute Changes"); - } - TransactionToken fromTransactionId; - TransactionToken toTransaction; - boolean hasSpecificArtifact = getSpecificArtifact() != null; - - for (ChangeBuilder changeBuilder : getChangeBuilders()) {// cache in map for performance look ups - artModTypes.put(changeBuilder.getArtId(), changeBuilder.getModType()); - } - //Changes per a branch - if (hasBranch) { - fromTransactionId = getSourceBaseTransaction(); - toTransaction = TransactionManager.getHeadTransaction(getSourceBranch()); - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_BRANCH_ATTRIBUTE_IS), getSourceBranch(), - fromTransactionId); - - } //Changes per transaction number - else { - toTransaction = getTransaction(); - if (hasSpecificArtifact) { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_IS_FOR_SPECIFIC_ARTIFACT), - toTransaction.getBranch(), toTransaction, getSpecificArtifact()); - fromTransactionId = getTransaction(); - } else { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_IS), toTransaction.getBranch(), - toTransaction); - fromTransactionId = TransactionManager.getPriorTransaction(toTransaction); - } - } - loadIsValues(getSourceBranch(), getArtIds(), getChangeBuilders(), getNewAndDeletedArtifactIds(), getMonitor(), - attributesWasValueCache, artModTypes, modifiedArtifacts, chStmt, hasBranch, time, fromTransactionId, - toTransaction, hasSpecificArtifact); - loadAttributeWasValues(getSourceBranch(), getTransaction(), getArtIds(), getMonitor(), attributesWasValueCache, - hasBranch); - } finally { - chStmt.close(); - } - return getChangeBuilders(); - } - - private void loadIsValues(BranchId sourceBranch, Set<ArtifactId> artIds, ArrayList<ChangeBuilder> changeBuilders, Set<ArtifactId> newAndDeletedArtifactIds, IProgressMonitor monitor, Map<Integer, ChangeBuilder> attributesWasValueCache, Map<ArtifactId, ModificationType> artModTypes, Set<ArtifactId> modifiedArtifacts, JdbcStatement chStmt, boolean hasBranch, long time, TransactionToken fromTransactionId, TransactionToken toTransactionId, boolean hasSpecificArtifact) { - ModificationType artModType; - AttributeChangeBuilder attributeChangeBuilder; - - try { - TransactionDelta txDelta = new TransactionDelta(fromTransactionId, toTransactionId); - - while (chStmt.next()) { - int attrId = chStmt.getInt("attr_id"); - ArtifactId artId = ArtifactId.valueOf(chStmt.getLong("art_id")); - GammaId sourceGamma = GammaId.valueOf(chStmt.getLong("gamma_id")); - AttributeTypeToken attributeType = tokenService.getAttributeTypeOrCreate(chStmt.getLong("attr_type_id")); - ArtifactTypeId artifactType = ArtifactTypeId.valueOf(chStmt.getLong("art_type_id")); - String isValue = chStmt.getString("is_value"); - String isUri = chStmt.getString("uri"); - ModificationType modificationType = ModificationType.valueOf(chStmt.getInt("mod_type")); - - if (artModTypes.containsKey(artId)) { - artModType = artModTypes.get(artId); - } else { - artModType = ModificationType.MODIFIED; - } - - //This will be false iff the artifact was new and then deleted - if (!newAndDeletedArtifactIds.contains(artId)) { - // Want to add an artifact changed item once if any attribute was modified && artifact was not - // NEW or DELETED and these changes are not for a specific artifact - if (artModType == ModificationType.MODIFIED && !modifiedArtifacts.contains(artId)) { - - ArtifactChangeBuilder artifactChangeBuilder = new ArtifactChangeBuilder(sourceBranch, artifactType, - GammaId.SENTINEL, artId, txDelta, ModificationType.MODIFIED, !hasBranch); - - changeBuilders.add(artifactChangeBuilder); - modifiedArtifacts.add(artId); - } - - //ModTypes will be temporarily set to new and then revised for based on the existence of a was value - if (modificationType == ModificationType.MODIFIED && artModType != ModificationType.INTRODUCED) { - modificationType = ModificationType.NEW; - } - attributeChangeBuilder = new AttributeChangeBuilder(sourceBranch, artifactType, sourceGamma, artId, - txDelta, modificationType, !hasBranch, isValue, "", attrId, attributeType, artModType, isUri, ""); - - changeBuilders.add(attributeChangeBuilder); - attributesWasValueCache.put(attrId, attributeChangeBuilder); - artIds.add(artId); - } - } - - if (getMonitor() != null) { - monitor.worked(13); - monitor.subTask("Gathering Was values"); - } - } finally { - chStmt.close(); - } - } - - private void loadAttributeWasValues(BranchId sourceBranch, TransactionToken transactionId, Set<ArtifactId> artIds, IProgressMonitor monitor, Map<Integer, ChangeBuilder> attributesWasValueCache, boolean hasBranch) { - if (!artIds.isEmpty()) { - Id sqlParamter; // Will either be a branch uuid or transaction id - BranchId wasValueBranch; - String sql; - - if (hasBranch) { - wasValueBranch = sourceBranch; - sql = ServiceUtil.getSql(OseeSql.CHANGE_BRANCH_ATTRIBUTE_WAS); - sqlParamter = wasValueBranch; - } else { - wasValueBranch = transactionId.getBranch(); - sql = ServiceUtil.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_WAS); - sqlParamter = transactionId; - } - - try (Id4JoinQuery joinQuery = JoinUtility.createId4JoinQuery()) { - for (ArtifactId artId : artIds) { - joinQuery.add(wasValueBranch, artId, TransactionId.SENTINEL, wasValueBranch.getViewId()); - } - joinQuery.store(); - - previousAttrId = -1; - ConnectionHandler.getJdbcClient().runQuery(this::buildAttributeChange, sql, sqlParamter, - joinQuery.getQueryId()); - } - if (getMonitor() != null) { - monitor.worked(12); - } - } - } - - private void buildAttributeChange(JdbcStatement stmt) { - int attrId = stmt.getInt("attr_id"); - - if (previousAttrId != attrId) { - String wasValue = stmt.getString("was_value"); - String wasUri = stmt.getString("uri"); - if (attributesWasValueCache.containsKey( - attrId) && attributesWasValueCache.get(attrId) instanceof AttributeChangeBuilder) { - AttributeChangeBuilder changeBuilder = (AttributeChangeBuilder) attributesWasValueCache.get(attrId); - - if (changeBuilder.getArtModType() != ModificationType.NEW) { - if (changeBuilder.getModType() != ModificationType.DELETED && changeBuilder.getModType() != ModificationType.ARTIFACT_DELETED) { - changeBuilder.setModType(ModificationType.MODIFIED); - } - changeBuilder.setWasValue(wasValue); - changeBuilder.setWasUri(wasUri); - } - } - previousAttrId = attrId; - } - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ChangeAcquirer.java deleted file mode 100644 index 7ba6a48ef13..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ChangeAcquirer.java +++ /dev/null @@ -1,81 +0,0 @@ -/********************************************************************* - * Copyright (c) 2010 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.revision.acquirer; - -import java.util.ArrayList; -import java.util.Set; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.TransactionToken; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; -import org.eclipse.osee.framework.skynet.core.change.ChangeBuilder; - -/** - * @author Jeff C. Phillips - */ -public abstract class ChangeAcquirer { - private final BranchId sourceBranch; - private final TransactionToken transactionId; - private final IProgressMonitor monitor; - private final Artifact specificArtifact; - private final Set<ArtifactId> artIds; - private final ArrayList<ChangeBuilder> changeBuilders; - private final Set<ArtifactId> newAndDeletedArtifactIds; - - public ChangeAcquirer(BranchId sourceBranch, TransactionToken transactionId, IProgressMonitor monitor, Artifact specificArtifact, Set<ArtifactId> artIds, ArrayList<ChangeBuilder> changeBuilders, Set<ArtifactId> newAndDeletedArtifactIds) { - this.sourceBranch = sourceBranch; - this.transactionId = transactionId; - this.monitor = monitor; - this.specificArtifact = specificArtifact; - this.artIds = artIds; - this.changeBuilders = changeBuilders; - this.newAndDeletedArtifactIds = newAndDeletedArtifactIds; - } - - protected BranchId getSourceBranch() { - return sourceBranch; - } - - protected TransactionToken getSourceBaseTransaction() { - return BranchManager.getBaseTransaction(getSourceBranch()); - } - - protected TransactionToken getTransaction() { - return transactionId; - } - - protected IProgressMonitor getMonitor() { - return monitor; - } - - protected Artifact getSpecificArtifact() { - return specificArtifact; - } - - protected Set<ArtifactId> getArtIds() { - return artIds; - } - - protected ArrayList<ChangeBuilder> getChangeBuilders() { - return changeBuilders; - } - - protected Set<ArtifactId> getNewAndDeletedArtifactIds() { - return newAndDeletedArtifactIds; - } - - public abstract ArrayList<ChangeBuilder> acquireChanges(); -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/RelationChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/RelationChangeAcquirer.java deleted file mode 100644 index d869229e523..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/RelationChangeAcquirer.java +++ /dev/null @@ -1,104 +0,0 @@ -/********************************************************************* - * Copyright (c) 2010 Boeing - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Boeing - initial API and implementation - **********************************************************************/ - -package org.eclipse.osee.framework.skynet.core.revision.acquirer; - -import java.util.ArrayList; -import java.util.Set; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.OrcsTokenService; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.data.ArtifactTypeId; -import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.GammaId; -import org.eclipse.osee.framework.core.data.TransactionToken; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.model.TransactionDelta; -import org.eclipse.osee.framework.core.sql.OseeSql; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.change.ChangeBuilder; -import org.eclipse.osee.framework.skynet.core.change.RelationChangeBuilder; -import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; -import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; -import org.eclipse.osee.jdbc.JdbcStatement; - -/** - * @author Jeff C. Phillips - */ -public class RelationChangeAcquirer extends ChangeAcquirer { - private final OrcsTokenService tokenService; - - public RelationChangeAcquirer(BranchId sourceBranch, TransactionToken transactionId, IProgressMonitor monitor, Artifact specificArtifact, Set<ArtifactId> artIds, ArrayList<ChangeBuilder> changeBuilders, Set<ArtifactId> newAndDeletedArtifactIds, OrcsTokenService tokenService) { - super(sourceBranch, transactionId, monitor, specificArtifact, artIds, changeBuilders, newAndDeletedArtifactIds); - this.tokenService = tokenService; - } - - @Override - public ArrayList<ChangeBuilder> acquireChanges() { - JdbcStatement chStmt = ConnectionHandler.getStatement(); - TransactionToken fromTransactionId; - TransactionToken toTransactionId; - - if (getMonitor() != null) { - getMonitor().subTask("Gathering Relation Changes"); - } - try { - boolean hasBranch = getSourceBranch() != null; - - //Changes per a branch - if (hasBranch) { - fromTransactionId = getSourceBaseTransaction(); - toTransactionId = TransactionManager.getHeadTransaction(getSourceBranch()); - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_BRANCH_RELATION), getSourceBranch(), - fromTransactionId); - } else {//Changes per a transaction - toTransactionId = getTransaction(); - - if (getSpecificArtifact() != null) { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_RELATION_FOR_SPECIFIC_ARTIFACT), - toTransactionId.getBranch(), toTransactionId, getSpecificArtifact(), getSpecificArtifact()); - fromTransactionId = toTransactionId; - } else { - chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.CHANGE_TX_RELATION), toTransactionId.getBranch(), - toTransactionId.getId()); - fromTransactionId = TransactionManager.getPriorTransaction(toTransactionId); - } - } - TransactionDelta txDelta = new TransactionDelta(fromTransactionId, toTransactionId); - while (chStmt.next()) { - ArtifactId aArtId = ArtifactId.valueOf(chStmt.getLong("a_art_id")); - ArtifactId bArtId = ArtifactId.valueOf(chStmt.getLong("b_art_id")); - int relLinkId = chStmt.getInt("rel_link_id"); - - if (!getNewAndDeletedArtifactIds().contains(aArtId) && !getNewAndDeletedArtifactIds().contains(bArtId)) { - ModificationType modificationType = ModificationType.valueOf(chStmt.getInt("mod_type")); - String rationale = modificationType != ModificationType.DELETED ? chStmt.getString("rationale") : ""; - getArtIds().add(aArtId); - getArtIds().add(bArtId); - - getChangeBuilders().add(new RelationChangeBuilder(getSourceBranch(), - ArtifactTypeId.valueOf(chStmt.getLong("art_type_id")), GammaId.valueOf(chStmt.getLong("gamma_id")), - aArtId, txDelta, modificationType, ArtifactId.valueOf(bArtId), relLinkId, rationale, - tokenService.getRelationType(chStmt.getLong("rel_link_type_id")), !hasBranch)); - } - } - if (getMonitor() != null) { - getMonitor().worked(25); - } - } finally { - chStmt.close(); - } - return getChangeBuilders(); - } -}
\ No newline at end of file |