blob: 9229ebda2cc3f8d5600c94ec2b99ec826f264a12 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright (c) 2012 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.framework.ui.skynet.blam.operation;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.IntroduceArtifactOperation;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.change.Change;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
/**
* @author Jeff C. Phillips
* @author Wilik Karol
*/
public class ReplaceArtifactWithBaselineOperation extends AbstractOperation {
private final Collection<Change> changeReportChanges;
private final Collection<Artifact> artifacts;
public ReplaceArtifactWithBaselineOperation(Collection<Change> changeReportChanges, Collection<Artifact> artifacts) {
super("Replace Artifact With Baseline Operation", Activator.PLUGIN_ID);
this.changeReportChanges = changeReportChanges;
this.artifacts = artifacts;
}
@Override
protected void doWork(IProgressMonitor monitor) throws Exception {
if (!monitor.isCanceled() && Conditions.notNull(changeReportChanges, artifacts)) {
monitor.beginTask("Reverting artifact(s)", artifacts.size());
if (!artifacts.isEmpty()) {
Artifact firstArtifact = artifacts.iterator().next();
IOseeBranch branch = firstArtifact.getBranch();
SkynetTransaction transaction =
TransactionManager.createTransaction(branch, ReplaceArtifactWithBaselineOperation.class.getSimpleName());
TransactionRecord txRecord = firstArtifact.getFullBranch().getBaseTransaction();
for (Artifact artifact : artifacts) {
monitor.subTask("Reverting: " + artifact.getName());
monitor.worked(1);
Artifact sourceArtifact =
ArtifactQuery.checkHistoricalArtifactFromId(artifact.getArtId(), txRecord,
DeletionFlag.INCLUDE_DELETED);
if (sourceArtifact != null) {
transaction.addArtifact(new IntroduceArtifactOperation(branch).introduce(sourceArtifact));
} else {
artifact.delete();
transaction.addArtifact(artifact);
}
monitor.done();
}
monitor.subTask(String.format("Persisting %s artifact(s)", artifacts.size()));
transaction.execute();
persistAndReloadArtifacts();
}
monitor.done();
}
}
private void persistAndReloadArtifacts() throws OseeCoreException {
for (Artifact artifact : artifacts) {
artifact.reloadAttributesAndRelations();
}
}
}
|