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
|
/*******************************************************************************
* Copyright (c) 2013 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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.operation.OperationLogger;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.skynet.widgets.IXWidgetInputAddable;
/**
* Typically used to parse GUIDs copied from another application via text-clipboard. Operation extracts input from
* <code>guidData</code> argument and attempts to find artifacts referenced by GUIDs on argument branch. The result list
* of artifacts is then passed to IXWidgetInputAddable-type widget.
*
* @author Karol M. Wilk
*/
public class StringGuidsToArtifactListOperation extends AbstractOperation {
private final String rawGuidsData;
private final IOseeBranch branch;
private final IXWidgetInputAddable widget;
public final static String splitRegex = "\\s+";
private final static String taskName = "Mapping GUIDs to Artifacts...";
private final static String subTaskName = "Retrieving Artifacts from cache and/or database...";
/**
* @param guidData string data of form <code>GUID1\\s+GUID2\\s+...GUIDN\\s+</code> separated by <code>\\s+</code>
* @param branch on which the artifacts live on
* @param widget accepting input by implementing <code>IXWidgetInputAddable</code> interface
*/
public StringGuidsToArtifactListOperation(OperationLogger logger, String guidData, IOseeBranch branch, IXWidgetInputAddable widget) {
super(taskName, Activator.PLUGIN_ID, logger);
this.rawGuidsData = guidData;
this.branch = branch;
this.widget = widget;
}
@Override
protected void doWork(IProgressMonitor monitor) throws Exception {
if (Strings.isValid(rawGuidsData) && branch != null && widget != null) {
//Arbitrary number accounting for querying the cache and db retrieval
int costOfArtifactRetrieval = 5;
String[] guids = this.rawGuidsData.split(splitRegex);
monitor.beginTask(taskName, guids.length + costOfArtifactRetrieval);
List<String> validGuids = new ArrayList<>(guids.length);
final Collection<Object> artifacts = new ArrayList<>(guids.length); //widget accepts Collection<Object>
for (int guidIndex = 0; !monitor.isCanceled() && guidIndex < guids.length; guidIndex++) {
if (GUID.isValid(guids[guidIndex])) {
validGuids.add(guids[guidIndex]);
}
monitor.worked(guidIndex + 1);
}
try {
//written to minimize calls to db VS individuals gets (+cost of overhead)
if (!monitor.isCanceled()) {
monitor.subTask(subTaskName);
monitor.beginTask(subTaskName, costOfArtifactRetrieval);
artifacts.addAll(ArtifactQuery.getArtifactListFromIds(validGuids, this.branch));
monitor.done();
monitor.worked(costOfArtifactRetrieval);
}
} catch (Exception ex) {
getLogger().log(ex);
}
monitor.done();
widget.addToInput(artifacts);
} else {
getLogger().logf("Problem with arguments for this operation: %s",
Strings.buildStatment(Arrays.asList(new String[] {"rawGuidsData", "branch", "widget"})), " or ");
monitor.setCanceled(true);
monitor.done();
}
}
}
|