3987 |
17 Nov 10 |
gregory |
1 |
/** |
3987 |
17 Nov 10 |
gregory |
2 |
* |
3987 |
17 Nov 10 |
gregory |
3 |
*/ |
3987 |
17 Nov 10 |
gregory |
4 |
package greg; |
3987 |
17 Nov 10 |
gregory |
5 |
|
3987 |
17 Nov 10 |
gregory |
6 |
import java.util.List; |
3987 |
17 Nov 10 |
gregory |
7 |
import org.proteios.action.ProteiosAction; |
3987 |
17 Nov 10 |
gregory |
8 |
import org.proteios.action.job.ListJobs; |
3987 |
17 Nov 10 |
gregory |
9 |
import org.proteios.core.DbControl; |
3987 |
17 Nov 10 |
gregory |
10 |
import org.proteios.core.File; |
3987 |
17 Nov 10 |
gregory |
11 |
import org.proteios.core.FileParameterType; |
3987 |
17 Nov 10 |
gregory |
12 |
import org.proteios.core.ItemFactory; |
3987 |
17 Nov 10 |
gregory |
13 |
import org.proteios.core.Job; |
3987 |
17 Nov 10 |
gregory |
14 |
import org.proteios.core.PluginDefinition; |
3987 |
17 Nov 10 |
gregory |
15 |
import org.proteios.core.StringParameterType; |
3987 |
17 Nov 10 |
gregory |
16 |
import org.proteios.gui.form.FormFactory; |
3987 |
17 Nov 10 |
gregory |
17 |
import se.lu.thep.waf.ActionException; |
3987 |
17 Nov 10 |
gregory |
18 |
import se.lu.thep.waf.constraints.InvalidParameterValue; |
3987 |
17 Nov 10 |
gregory |
19 |
|
3987 |
17 Nov 10 |
gregory |
20 |
/** |
3987 |
17 Nov 10 |
gregory |
* Creates an ImportXFile job for each file id |
3987 |
17 Nov 10 |
gregory |
22 |
* |
3987 |
17 Nov 10 |
gregory |
* @author gregory |
3987 |
17 Nov 10 |
gregory |
24 |
*/ |
3987 |
17 Nov 10 |
gregory |
25 |
public class CreateXFileImportJob |
3987 |
17 Nov 10 |
gregory |
26 |
extends ProteiosAction<CreateXFileImportJob> |
3987 |
17 Nov 10 |
gregory |
27 |
{ |
3987 |
17 Nov 10 |
gregory |
28 |
@Override |
3987 |
17 Nov 10 |
gregory |
29 |
protected void runMe() |
3987 |
17 Nov 10 |
gregory |
30 |
throws ActionException, InvalidParameterValue |
3987 |
17 Nov 10 |
gregory |
31 |
{ |
3987 |
17 Nov 10 |
gregory |
32 |
/* |
3987 |
17 Nov 10 |
gregory |
* Get a valid list of file ids |
3987 |
17 Nov 10 |
gregory |
34 |
*/ |
3987 |
17 Nov 10 |
gregory |
35 |
List<Integer> files = getValidIntegerList(FormFactory.VID); |
3987 |
17 Nov 10 |
gregory |
36 |
/* |
3987 |
17 Nov 10 |
gregory |
* Get a valid prefix |
3987 |
17 Nov 10 |
gregory |
38 |
*/ |
3987 |
17 Nov 10 |
gregory |
39 |
String prefix = getValidString(ImportXFileForm.VPREFIX); |
3987 |
17 Nov 10 |
gregory |
40 |
/* |
3987 |
17 Nov 10 |
gregory |
* Get the plugin to execute by getting it's PluginDefinition. Make sure |
3987 |
17 Nov 10 |
gregory |
* the plugin is installed first. |
3987 |
17 Nov 10 |
gregory |
43 |
*/ |
3987 |
17 Nov 10 |
gregory |
44 |
DbControl dc = newDbControl(); |
3987 |
17 Nov 10 |
gregory |
45 |
PluginDefinition plugin = PluginDefinition.getByClassName(dc, |
3987 |
17 Nov 10 |
gregory |
46 |
ImportXFile.class.getName()); |
3987 |
17 Nov 10 |
gregory |
47 |
/* |
3987 |
17 Nov 10 |
gregory |
* Get the files |
3987 |
17 Nov 10 |
gregory |
49 |
*/ |
3987 |
17 Nov 10 |
gregory |
50 |
ItemFactory factory = new ItemFactory(dc); |
3987 |
17 Nov 10 |
gregory |
51 |
int jobCount = 0; |
3987 |
17 Nov 10 |
gregory |
52 |
for (Integer fileId : files) |
3987 |
17 Nov 10 |
gregory |
53 |
{ |
3987 |
17 Nov 10 |
gregory |
54 |
Job job = factory.createJob(plugin, null); |
3987 |
17 Nov 10 |
gregory |
55 |
job.setName(plugin.getName()); |
3987 |
17 Nov 10 |
gregory |
// Tell the job which file to work with |
3987 |
17 Nov 10 |
gregory |
57 |
File file = factory.getById(File.class, fileId); |
3987 |
17 Nov 10 |
gregory |
58 |
job |
3987 |
17 Nov 10 |
gregory |
59 |
.setDescription("Import of " + file.getName() + " [" + fileId + "]"); |
3987 |
17 Nov 10 |
gregory |
// Tell the job which file to work with |
3987 |
17 Nov 10 |
gregory |
61 |
FileParameterType fileParam = new FileParameterType(); |
3987 |
17 Nov 10 |
gregory |
62 |
job.setParameterValue(ImportXFile.FILEPARAM, fileParam, file); |
3987 |
17 Nov 10 |
gregory |
// Tell the job which prefix to add |
3987 |
17 Nov 10 |
gregory |
64 |
StringParameterType prefixParam = new StringParameterType(); |
3987 |
17 Nov 10 |
gregory |
65 |
job.setParameterValue(ImportXFile.PREFIXPARAM, prefixParam, prefix); |
3987 |
17 Nov 10 |
gregory |
66 |
// |
3987 |
17 Nov 10 |
gregory |
67 |
dc.saveItem(job); |
3987 |
17 Nov 10 |
gregory |
68 |
jobCount++; |
3987 |
17 Nov 10 |
gregory |
69 |
} |
3987 |
17 Nov 10 |
gregory |
70 |
dc.commit(); |
3987 |
17 Nov 10 |
gregory |
71 |
setMessage(jobCount + " jobs created"); |
3987 |
17 Nov 10 |
gregory |
72 |
setForwardTo(ListJobs.class); |
3987 |
17 Nov 10 |
gregory |
73 |
} |
3987 |
17 Nov 10 |
gregory |
74 |
} |