blob: a95753248b9fd9f37bab097b1707ac02118bda3c (
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*******************************************************************************
* Copyright (c) 2004, 2007 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.skynet.core.event;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.model.event.DefaultBasicGuidArtifact;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
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.Change;
import org.eclipse.osee.framework.skynet.core.event.model.TransactionChange;
import org.eclipse.osee.framework.skynet.core.event.model.TransactionEvent;
import org.eclipse.osee.framework.skynet.core.event.model.TransactionEventType;
import org.eclipse.osee.framework.skynet.core.internal.Activator;
import org.eclipse.osee.framework.skynet.core.revision.ChangeManager;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
/**
* @author Roberto E. Escobar
*/
public final class PurgeTransactionEventUtil {
private PurgeTransactionEventUtil() {
//Utility Class
}
public static TransactionEvent createPurgeTransactionEvent(Collection<TransactionRecord> purgedTransactions) {
TransactionEvent transactionEvent = new TransactionEvent();
transactionEvent.setEventType(TransactionEventType.Purged);
List<TransactionChange> txChanges = transactionEvent.getTransactions();
for (TransactionRecord txRecord : purgedTransactions) {
try {
Branch branch = BranchManager.getBranch(txRecord.getBranchId());
TransactionChange transChange = new TransactionChange();
transChange.setTransactionId(txRecord.getId());
transChange.setBranchGuid(branch.getGuid());
Collection<Change> changes = new ArrayList<Change>();
IOperation operation = ChangeManager.comparedToPreviousTx(txRecord, changes);
Operations.executeWorkAndCheckStatus(operation);
Collection<DefaultBasicGuidArtifact> eventArts = transChange.getArtifacts();
for (Change change : changes) {
Artifact art = change.getChangeArtifact();
eventArts.add(art.getBasicGuidArtifact());
}
txChanges.add(transChange);
} catch (Exception ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
}
return transactionEvent;
}
public static void handleRemotePurgeTransactionEvent(TransactionEvent transEvent) {
if (transEvent.getEventType() == TransactionEventType.Purged) {
Set<Artifact> artifactsInCache = new HashSet<Artifact>();
for (TransactionChange transChange : transEvent.getTransactions()) {
try {
TransactionManager.deCache(transChange.getTransactionId());
} catch (OseeCoreException ex1) {
OseeLog.log(Activator.class, Level.SEVERE, ex1);
}
for (DefaultBasicGuidArtifact guidArt : transChange.getArtifacts()) {
try {
Artifact artifact = ArtifactCache.getActive(guidArt);
if (artifact != null) {
artifactsInCache.add(artifact);
}
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
}
}
// This will kick the artifacts reloaded event which should be handled by Applications/UIs
if (!artifactsInCache.isEmpty()) {
try {
ArtifactQuery.reloadArtifacts(artifactsInCache);
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
}
}
}
}
|