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
|
/*******************************************************************************
* 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.blam.operation;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.core.util.Conditions;
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.Attribute;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
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.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
/**
* @author Megumi Telles
*/
public class DeleteInvalidAttributeTypesFromBranch extends AbstractBlam {
private static final String ARTIFACT_IDS_WIDGET_NAME = "List of Artifact GUIDs (comma separated)";
private static final String DESCRIPTION =
"Provide list of artifact GUIDs that contain an invalid attribute type to delete from the selected branch";
public DeleteInvalidAttributeTypesFromBranch() {
super(null, DESCRIPTION, BlamUiSource.FILE);
}
@Override
public String getName() {
return "Delete Invalid Attribute Types From Branch";
}
@Override
public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws OseeCoreException {
Branch branch = variableMap.getBranch("Branch");
List<AttributeType> attributeTypes = variableMap.getAttributeTypes("Attribute Type");
String input = variableMap.getString(ARTIFACT_IDS_WIDGET_NAME);
Conditions.checkNotNullOrEmpty(input, ARTIFACT_IDS_WIDGET_NAME);
List<String> inputGuids = Arrays.asList(input.split("[,\\s]+"));
List<Artifact> arts = ArtifactQuery.getArtifactListFromIds(inputGuids, branch);
if (arts != null && !arts.isEmpty()) {
SkynetTransaction transaction =
TransactionManager.createTransaction(branch, "BLAM: Delete invalid attribute type");
for (AttributeType attrType : attributeTypes) {
deleteInvalidAttributeType(arts, attrType, transaction);
}
transaction.execute();
}
}
private void deleteInvalidAttributeType(List<Artifact> artifacts, AttributeType attrType, SkynetTransaction transaction) throws OseeCoreException {
for (Artifact art : artifacts) {
if (!art.isAttributeTypeValid(attrType)) {
delete(art, attrType);
art.persist(transaction);
} else {
logf("Artifact [%s] attribute type [%s] is valid - did not delete\n", art, attrType);
}
}
}
private void delete(Artifact art, AttributeType attrType) throws OseeCoreException {
List<Attribute<?>> attrs = art.getAttributes(false);
for (Attribute<?> attr : attrs) {
if (attr.isOfType(attrType)) {
attr.delete();
logf("Artifact [%s] attribute type [%s] deleted: [%s]\n", art, attrType, attr);
}
}
}
@Override
public String getXWidgetsXml() throws OseeCoreException {
return getXWidgetsXmlFromUiFile(getClass().getSimpleName(), Activator.PLUGIN_ID);
}
@Override
public Collection<String> getCategories() {
return Arrays.asList("Admin");
}
}
|