| 1 | package de.uka.ipd.sdq.cip.workflow.jobs; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | |
| 5 | import org.eclipse.core.runtime.IProgressMonitor; |
| 6 | import org.eclipse.emf.common.util.URI; |
| 7 | |
| 8 | import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration; |
| 9 | import de.uka.ipd.sdq.cip.configuration.QVTConfigurationHelper; |
| 10 | import de.uka.ipd.sdq.cip.configuration.Transformation; |
| 11 | import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob; |
| 12 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
| 13 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
| 14 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
| 15 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
| 16 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ModelLocation; |
| 17 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvto.QVTOTransformationJobConfiguration; |
| 18 | |
| 19 | /** |
| 20 | * @author Thomas Schuischel |
| 21 | * |
| 22 | */ |
| 23 | public class QVTOConfigurationJob implements |
| 24 | IBlackboardInteractingJob<MDSDBlackboard> { |
| 25 | |
| 26 | private CompletionConfiguration completionConfiguration = null; |
| 27 | private Transformation transformation = null; |
| 28 | private QVTOTransformationJobConfiguration jobConfiguration = null; |
| 29 | private MDSDBlackboard blackboard = null; |
| 30 | |
| 31 | public QVTOConfigurationJob(QVTOTransformationJobConfiguration jobConfiguration, |
| 32 | CompletionConfiguration completionConfiguration, Transformation transformation) { |
| 33 | |
| 34 | this.jobConfiguration = jobConfiguration; |
| 35 | this.transformation = transformation; |
| 36 | this.completionConfiguration = completionConfiguration; |
| 37 | |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void execute(IProgressMonitor monitor) throws JobFailedException, |
| 42 | UserCanceledException { |
| 43 | |
| 44 | assert (completionConfiguration != null); |
| 45 | assert (transformation != null); |
| 46 | assert (jobConfiguration != null); |
| 47 | |
| 48 | // get the models to work with |
| 49 | ModelLocation[] modelLocations = QVTConfigurationHelper. |
| 50 | getModelsFromBlackboard(blackboard, completionConfiguration.getInputPartitionName()); |
| 51 | |
| 52 | // if an optional model is configured, add this to the model location list |
| 53 | if(transformation.getOptionalModelFileURI() != null && |
| 54 | !transformation.getOptionalModelFileURI().equals("")){ |
| 55 | |
| 56 | // build the location for the optional model |
| 57 | URI optionalModelURI = URI.createURI(transformation.getOptionalModelFileURI()); |
| 58 | //ModelLocation optionalModel = new ModelLocation(configuration.getInputPartitionName(), optionalModelURI); |
| 59 | ModelLocation optionalModel = QVTConfigurationHelper.loadResourceToInputPartition(blackboard, completionConfiguration.getInputPartitionName(), optionalModelURI); |
| 60 | |
| 61 | // build the new location array with an additional entry |
| 62 | ModelLocation[] tempModelLocations = new ModelLocation[modelLocations.length + 1]; |
| 63 | for(int i = 0; i < modelLocations.length; i++ ){ |
| 64 | tempModelLocations[i] = modelLocations[i]; |
| 65 | } |
| 66 | tempModelLocations[modelLocations.length] = optionalModel; |
| 67 | modelLocations = tempModelLocations; |
| 68 | } |
| 69 | |
| 70 | // build file paths |
| 71 | URI traceFileURI = QVTConfigurationHelper.getTraceFileURI(completionConfiguration.getProjectID()); |
| 72 | URI scriptFileURI = URI.createURI(transformation.getQVTFileURI()); |
| 73 | |
| 74 | // set the job configuration |
| 75 | jobConfiguration.setInoutModels(modelLocations); |
| 76 | jobConfiguration.setTraceFileURI(traceFileURI); |
| 77 | jobConfiguration.setScriptFileURI(scriptFileURI); |
| 78 | jobConfiguration.setOptions(new HashMap<String,Object>()); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | public QVTOTransformationJobConfiguration getJobConfiguration() { |
| 83 | return jobConfiguration; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void setBlackboard(MDSDBlackboard blackboard) { |
| 88 | this.blackboard = blackboard; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public String getName() { |
| 93 | return "Configure QVTO transformation"; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void rollback(IProgressMonitor monitor) |
| 98 | throws RollbackFailedException {} // nothing to roll back |
| 99 | |
| 100 | } |