| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
package greg; |
|---|
| 5 |
|
|---|
| 6 |
import java.util.List; |
|---|
| 7 |
import org.proteios.action.ProteiosAction; |
|---|
| 8 |
import org.proteios.action.job.ListJobs; |
|---|
| 9 |
import org.proteios.core.DbControl; |
|---|
| 10 |
import org.proteios.core.File; |
|---|
| 11 |
import org.proteios.core.FileParameterType; |
|---|
| 12 |
import org.proteios.core.ItemFactory; |
|---|
| 13 |
import org.proteios.core.Job; |
|---|
| 14 |
import org.proteios.core.PluginDefinition; |
|---|
| 15 |
import org.proteios.core.StringParameterType; |
|---|
| 16 |
import org.proteios.gui.form.FormFactory; |
|---|
| 17 |
import se.lu.thep.waf.ActionException; |
|---|
| 18 |
import se.lu.thep.waf.constraints.InvalidParameterValue; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
public class CreateXFileImportJob |
|---|
| 26 |
extends ProteiosAction<CreateXFileImportJob> |
|---|
| 27 |
{ |
|---|
| 28 |
@Override |
|---|
| 29 |
protected void runMe() |
|---|
| 30 |
throws ActionException, InvalidParameterValue |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
List<Integer> files = getValidIntegerList(FormFactory.VID); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
String prefix = getValidString(ImportXFileForm.VPREFIX); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
DbControl dc = newDbControl(); |
|---|
| 45 |
PluginDefinition plugin = PluginDefinition.getByClassName(dc, |
|---|
| 46 |
ImportXFile.class.getName()); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
ItemFactory factory = new ItemFactory(dc); |
|---|
| 51 |
int jobCount = 0; |
|---|
| 52 |
for (Integer fileId : files) |
|---|
| 53 |
{ |
|---|
| 54 |
Job job = factory.createJob(plugin, null); |
|---|
| 55 |
job.setName(plugin.getName()); |
|---|
| 56 |
|
|---|
| 57 |
File file = factory.getById(File.class, fileId); |
|---|
| 58 |
job |
|---|
| 59 |
.setDescription("Import of " + file.getName() + " [" + fileId + "]"); |
|---|
| 60 |
|
|---|
| 61 |
FileParameterType fileParam = new FileParameterType(); |
|---|
| 62 |
job.setParameterValue(ImportXFile.FILEPARAM, fileParam, file); |
|---|
| 63 |
|
|---|
| 64 |
StringParameterType prefixParam = new StringParameterType(); |
|---|
| 65 |
job.setParameterValue(ImportXFile.PREFIXPARAM, prefixParam, prefix); |
|---|
| 66 |
|
|---|
| 67 |
dc.saveItem(job); |
|---|
| 68 |
jobCount++; |
|---|
| 69 |
} |
|---|
| 70 |
dc.commit(); |
|---|
| 71 |
setMessage(jobCount + " jobs created"); |
|---|
| 72 |
setForwardTo(ListJobs.class); |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|