| 1 | package de.uka.ipd.sdq.cip.workflow.jobs; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | |
| 5 | import org.eclipse.core.runtime.IProgressMonitor; |
| 6 | import org.eclipse.emf.common.util.URI; |
| 7 | |
| 8 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
| 9 | import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration; |
| 10 | import de.uka.ipd.sdq.cip.configuration.QVTConfigurationHelper; |
| 11 | import de.uka.ipd.sdq.cip.configuration.Transformation; |
| 12 | import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob; |
| 13 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
| 14 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
| 15 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
| 16 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
| 17 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ModelLocation; |
| 18 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition; |
| 19 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.QVTRScript; |
| 20 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.jobs.QVTRTransformationJobConfiguration; |
| 21 | |
| 22 | public class QVTRHotConfigurationJob implements |
| 23 | IBlackboardInteractingJob<MDSDBlackboard> { |
| 24 | |
| 25 | private CompletionConfiguration completionConfiguration = null; |
| 26 | private Transformation transformation = null; |
| 27 | private QVTRTransformationJobConfiguration jobConfiguration = null; |
| 28 | private MDSDBlackboard blackboard = null; |
| 29 | |
| 30 | public QVTRHotConfigurationJob(QVTRTransformationJobConfiguration jobConfiguration, |
| 31 | CompletionConfiguration completionConfiguration, Transformation transformation) { |
| 32 | |
| 33 | this.jobConfiguration = jobConfiguration; |
| 34 | this.transformation = transformation; |
| 35 | this.completionConfiguration = completionConfiguration; |
| 36 | |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void execute(IProgressMonitor monitor) throws JobFailedException, |
| 41 | UserCanceledException { |
| 42 | |
| 43 | assert (completionConfiguration != null); |
| 44 | assert (transformation != null); |
| 45 | assert (jobConfiguration != null); |
| 46 | |
| 47 | String modelPartitionID = completionConfiguration.getInputPartitionName(); |
| 48 | |
| 49 | // check if hot partition exists and remove |
| 50 | if( blackboard.hasPartition(ConstantsContainer.HOT_PARTITION_ID)){ |
| 51 | blackboard.removePartition(ConstantsContainer.HOT_PARTITION_ID); |
| 52 | } |
| 53 | |
| 54 | // create new empty hot partition |
| 55 | ResourceSetPartition hotPartition = new ResourceSetPartition(); |
| 56 | blackboard.addPartition(ConstantsContainer.HOT_PARTITION_ID, hotPartition); |
| 57 | |
| 58 | hotPartition.initialiseResourceSetEPackages(ConstantsContainer.HOT_METAMODELS); |
| 59 | |
| 60 | ModelLocation[] featureConfigLocation = new ModelLocation[] { |
| 61 | QVTConfigurationHelper.loadResourceToInputPartition( |
| 62 | blackboard, |
| 63 | ConstantsContainer.HOT_PARTITION_ID, |
| 64 | URI.createURI(transformation.getFeatureFileURI()))}; |
| 65 | |
| 66 | |
| 67 | |
| 68 | ModelLocation[] outputModelLocations = new ModelLocation[] { |
| 69 | QVTConfigurationHelper.createResourceToInputPartition( |
| 70 | blackboard, |
| 71 | modelPartitionID, |
| 72 | URI.createURI(PrepareTransformationsJob. |
| 73 | getModelFolder(completionConfiguration.getProjectID()). |
| 74 | getFile("qvt.xmi").getFullPath().toPortableString()))}; |
| 75 | |
| 76 | // get meta models needed for qvt script |
| 77 | Collection<Object> metamodels = QVTConfigurationHelper.getMetaModelsFromBlackboard(blackboard, ConstantsContainer.HOT_PARTITION_ID); |
| 78 | |
| 79 | QVTRScript qvtrScript = QVTConfigurationHelper.createQVTScript(ConstantsContainer.FEATURECONFIG2QVT_FILE, metamodels, null, null); |
| 80 | |
| 81 | URI traceFileURI = QVTConfigurationHelper.getTraceFileURI(completionConfiguration.getProjectID()); |
| 82 | |
| 83 | Boolean isDebug = completionConfiguration.getDebug(); |
| 84 | |
| 85 | // set the job configuration |
| 86 | jobConfiguration.setDebug(isDebug); |
| 87 | jobConfiguration.addModelLocationSets(featureConfigLocation); |
| 88 | jobConfiguration.addModelLocationSets(outputModelLocations); |
| 89 | jobConfiguration.setTraceFileURI(traceFileURI); |
| 90 | jobConfiguration.setQVTRScript(qvtrScript); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void setBlackboard(MDSDBlackboard blackboard) { |
| 95 | this.blackboard = blackboard; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String getName() { |
| 101 | return "Configure QVTR HOT transformation"; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void rollback(IProgressMonitor monitor) |
| 106 | throws RollbackFailedException {} // nothing to roll back |
| 107 | |
| 108 | } |