blob: f7a2a74432d6b5beb8fe5f64e08fa8e14c20ffed (
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
|
/*******************************************************************************
* 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.orcs.core.internal.console;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import org.eclipse.osee.console.admin.Console;
import org.eclipse.osee.console.admin.ConsoleCommand;
import org.eclipse.osee.console.admin.ConsoleParameters;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.HexUtil;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.OrcsTypes;
import org.eclipse.osee.orcs.data.AttributeTypes;
/**
* @author Angel Avila
*/
public class PurgeAttributeTypeCommand implements ConsoleCommand {
private OrcsApi orcsApi;
public void setOrcsApi(OrcsApi orcsApi) {
this.orcsApi = orcsApi;
}
public OrcsApi getOrcsApi() {
return orcsApi;
}
@Override
public String getName() {
return "purge_attribute_type";
}
@Override
public String getDescription() {
return "Purges attribute type instances from datastore";
}
@Override
public String getUsage() {
return "[force=<TRUE|FALSE>] types=<ATTRIBUTE_TYPE_UUID,...>";
}
@Override
public Callable<?> createCallable(final Console console, final ConsoleParameters params) {
final OrcsTypes orcsTypes = orcsApi.getOrcsTypes();
return new Callable<Void>() {
@Override
public Void call() throws Exception {
boolean forcePurge = params.getBoolean("force");
String[] typesToPurge = params.getArray("types");
console.writeln();
Set<IAttributeType> types = getTypes(typesToPurge);
boolean found = !types.isEmpty();
if (found) {
console.writeln(!forcePurge ? String.format("Attribute Types: [%s]", types) : String.format(
"Purging attribute types: [%s]", types));
if (forcePurge && found) {
orcsTypes.purgeAttributesByAttributeType(types).call();
}
console.writeln((found && !forcePurge) ? "To >DELETE Attribute DATA!< add \"force=TRUE\" to confirm." : "Operation finished.");
} else {
console.writeln("No types found. Aborting...");
}
return null;
}
private Set<IAttributeType> getTypes(String[] typesToPurge) throws OseeCoreException {
AttributeTypes attributeTypes = orcsTypes.getAttributeTypes();
Set<IAttributeType> toReturn = new HashSet<IAttributeType>();
for (String uuid : typesToPurge) {
try {
Long typeId = -1L;
if (Strings.isNumeric(uuid)) {
typeId = Long.valueOf(uuid);
} else {
typeId = HexUtil.toLong(uuid);
}
IAttributeType type = attributeTypes.getByUuid(typeId);
console.writeln("Type [%s] found. Guid: [0x%X]", type.getName(), type.getGuid());
toReturn.add(type);
} catch (OseeArgumentException ex) {
console.writeln("Type [0x%X] NOT found.", uuid);
console.writeln(ex);
}
}
return toReturn;
}
};
}
}
|