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.ui.skynet.render;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.jdk.core.type.MutableBoolean;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.jdbc.JdbcStatement;
public final class ArtifactGuis {
private static final int BRANCH_NAME_LENGTH = 50;
private ArtifactGuis() {
// this private empty constructor exists to prevent the default constructor from allowing public construction
}
private static final String OTHER_EDIT_SQL =
"select br.branch_id, att.gamma_id, att.attr_id, txs.tx_current, txs.transaction_id from osee_attribute att, osee_txs txs, osee_branch br where att.art_id = ? and att.gamma_id = txs.gamma_id and txs.branch_id = br.branch_id and txs.transaction_id <> br.baseline_transaction_id and txs.tx_current = 1 and br.branch_id <> ? and br.parent_branch_id = ? and br.branch_type = ? AND NOT EXISTS (SELECT 1 FROM osee_txs txs1 WHERE txs1.branch_id = br.branch_id AND txs1.transaction_id = br.baseline_transaction_id AND txs1.gamma_id = txs.gamma_id)";
private static final String EDIT_MESSAGE =
"%d of the %d artifacts about to be edited have already been modified on the following branches:%s\n\nDo you still wish to proceed?";
public static boolean checkOtherEdit(Collection<Artifact> artifacts) throws OseeCoreException {
Conditions.checkNotNull(artifacts, "artifacts to check");
Conditions.checkExpressionFailOnTrue(artifacts.isEmpty(), "Must have at least one artifact for checking");
int modifiedCount = 0;
Set<String> otherBranches = new HashSet<String>();
for (Artifact artifact : artifacts) {
boolean wasModified = addBranchesWhereArtifactHasBeenModified(artifact, otherBranches);
if (wasModified) {
modifiedCount++;
}
}
if (modifiedCount > 0) {
StringBuilder branchMessage = new StringBuilder();
for (String branchName : otherBranches) {
branchMessage.append("\n\t");
branchMessage.append(branchName);
}
String message = String.format(EDIT_MESSAGE, modifiedCount, artifacts.size(), branchMessage);
return confirmEdit(message);
}
return true;
}
private static boolean confirmEdit(final String message) {
final MutableBoolean editAllowed = new MutableBoolean(false);
Displays.pendInDisplayThread(new Runnable() {
@Override
public void run() {
editAllowed.setValue(MessageDialog.openConfirm(Displays.getActiveShell(), "Confirm Edit", message));
}
});
return editAllowed.getValue();
}
/**
* Returns non-archived sibling branches that this artifact's attributes have been edited on
*/
private static boolean addBranchesWhereArtifactHasBeenModified(Artifact artifact, Set<String> otherBranches) throws OseeCoreException {
boolean wasModified = false;
// Can only be on other branches if it has already been saved
if (artifact.isInDb()) {
JdbcStatement chStmt = ConnectionHandler.getStatement();
try {
Branch branch = artifact.getFullBranch();
chStmt.runPreparedQuery(OTHER_EDIT_SQL, artifact.getArtId(), branch.getUuid(),
branch.getParentBranch().getUuid(), BranchType.WORKING.getValue());
while (chStmt.next()) {
int modifiedAttrId = chStmt.getInt("attr_id");
long modifiedGammaId = chStmt.getInt("gamma_id");
long modifiedOnBranchId = chStmt.getLong("branch_id");
Attribute<?> attribute = artifact.getAttributeById(modifiedAttrId, false);
if (attribute == null || attribute.getGammaId() != modifiedGammaId) {
otherBranches.add(BranchManager.getBranch(modifiedOnBranchId).getShortName(BRANCH_NAME_LENGTH));
wasModified = true;
}
}
} finally {
chStmt.close();
}
}
return wasModified;
}
}
|