EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.cip.workflow.jobs]

COVERAGE SUMMARY FOR SOURCE FILE [SplitTransformationResultJob.java]

nameclass, %method, %block, %line, %
SplitTransformationResultJob.java0%   (0/1)0%   (0/6)0%   (0/262)0%   (0/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SplitTransformationResultJob0%   (0/1)0%   (0/6)0%   (0/262)0%   (0/52)
SplitTransformationResultJob (QVTRTransformationJobConfiguration, CompletionC... 0%   (0/1)0%   (0/26)0%   (0/8)
createResource (EObject, ResourceSetPartition, IFolder): void 0%   (0/1)0%   (0/87)0%   (0/15)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/142)0%   (0/25)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
setBlackboard (MDSDBlackboard): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.cip.workflow.jobs;
2 
3import java.io.IOException;
4import java.util.ArrayList;
5import java.util.HashMap;
6import java.util.Iterator;
7 
8import org.apache.log4j.Logger;
9import org.eclipse.core.resources.IFolder;
10import org.eclipse.core.runtime.IProgressMonitor;
11import org.eclipse.emf.common.util.EList;
12import org.eclipse.emf.common.util.URI;
13import org.eclipse.emf.ecore.EObject;
14import org.eclipse.emf.ecore.resource.Resource;
15import org.eclipse.emf.ecore.resource.ResourceSet;
16 
17import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration;
18import de.uka.ipd.sdq.cip.configuration.QVTConfigurationHelper;
19import de.uka.ipd.sdq.cip.configuration.Transformation;
20import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
21import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
22import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
23import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
24import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
25import de.uka.ipd.sdq.workflow.mdsd.blackboard.ModelLocation;
26import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition;
27import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.jobs.QVTRTransformationJobConfiguration;
28 
29public class SplitTransformationResultJob implements IBlackboardInteractingJob<MDSDBlackboard> {
30        
31        /** The logger for this class */
32        private Logger logger = Logger.getLogger(SplitTransformationResultJob.class);
33        
34        /** The blackboard to interact with */
35        private MDSDBlackboard blackboard = null;
36        
37        /** The blackboard partition for this Job */
38        private String modelPartitionID;
39        
40        /** The project id where to create folders */
41        private String projectID;
42 
43        /** The transformation id where to copy models */
44        private String transformationID;
45 
46        /** The configuration for a qvtr completion job */
47        private QVTRTransformationJobConfiguration qvtrTransformationJobConfiguration;
48 
49        public SplitTransformationResultJob(
50                        QVTRTransformationJobConfiguration qvtrTransformationJobConfiguration, 
51                        CompletionConfiguration completionConfiguration, 
52                        Transformation transformation) {
53                
54                this.modelPartitionID = completionConfiguration.getInputPartitionName();
55                this.qvtrTransformationJobConfiguration = qvtrTransformationJobConfiguration;
56                this.projectID = completionConfiguration.getProjectID();
57                
58                
59                this.transformationID = QVTConfigurationHelper.createTransformationID(completionConfiguration, transformation);
60        }
61        
62        @Override
63        public void execute(IProgressMonitor monitor) throws JobFailedException,
64                        UserCanceledException {
65                
66                IFolder modelFolder = PrepareTransformationsJob.createFolder(
67                                PrepareTransformationsJob.getModelFolder(projectID).getFolder(
68                                                transformationID),
69                                logger);
70                
71                ResourceSetPartition partition = this.blackboard.getPartition(modelPartitionID);
72                ResourceSet resourceSet = partition.getResourceSet();
73                
74                // Collect Resources to delete
75                ArrayList<Resource> resourcesToDelete = new ArrayList<Resource>();
76                for (Resource resource : resourceSet.getResources()) {
77                        // we only need to delete the file models
78                        if (resource.getURI().isFile()) {                
79                                resourcesToDelete.add(resource);
80                        }
81                }
82                
83                // Split output models
84                Iterator<ModelLocation[]> iterator  = qvtrTransformationJobConfiguration.getModelLocationSets().iterator();
85                iterator.next(); // go to second element
86                for (ModelLocation modelLocation : iterator.next()) {
87                                
88                        ResourceSetPartition modelPartition = this.blackboard.getPartition(modelLocation.getPartitionID());
89                                
90                        EList<EObject> topLevelObjects = (EList<EObject>) modelPartition.getContents(modelLocation.getModelID());
91                        while (topLevelObjects.size() > 0)
92                                createResource(topLevelObjects.get(0), partition, modelFolder);
93                        
94                        // Delete all temporary resources
95                        Resource resource = modelPartition.getResourceSet().getResource(modelLocation.getModelID(), false);
96                        if(resource.isLoaded())
97                                try {
98                                        resource.delete(new HashMap<String, String>());
99                                } catch (IOException e) {
100                                        logger.error("Unable to delete resource " + resource.getURI(),e);
101                                }
102                }
103                
104                // remove all marked resources from partition
105                for (Resource resource : resourcesToDelete) {
106                                partition.getResourceSet().getResources().remove(resource);
107                }
108                
109 
110        }
111 
112        private void createResource(EObject eobject, ResourceSetPartition partition, IFolder modelFolder) {
113 
114                URI baseURI = URI.createFileURI(modelFolder.getFullPath().toString());
115                String eobjectName = eobject.eClass().getName();
116                URI modelURI = baseURI.appendSegment(eobjectName + ".xmi");
117                Resource resource = partition.getResourceSet().getResource(modelURI, false);
118                
119                // find unused name
120                long num = 1;
121                while(resource != null)
122                {
123                        
124                        modelURI = baseURI.appendSegment(eobjectName + "_" + String.valueOf(num) + ".xmi");
125                        resource = partition.getResourceSet().getResource(modelURI, false);
126                        num++;
127                }
128                
129                resource = partition.getResourceSet().createResource(modelURI);        
130                
131                resource.getContents().add(eobject);
132                
133                try {
134                        resource.save(new HashMap<String, String>());
135                        //partition.setContents(resource.getURI(), resource.getContents());
136                } catch (IOException e) {
137                        logger.error("Unable to store resource "+resource.getURI(),e);
138                }
139        }
140 
141        @Override
142        public String getName() {
143                return "Clean up qvtr completion transformation result";
144        }
145 
146        @Override
147        public void rollback(IProgressMonitor monitor)
148                        throws RollbackFailedException {} // not needed
149 
150        @Override
151        public void setBlackboard(MDSDBlackboard blackboard) {
152                this.blackboard = blackboard;
153        }
154 
155}

[all classes][de.uka.ipd.sdq.cip.workflow.jobs]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov