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 [CreateCopyOfModelsJob.java]

nameclass, %method, %block, %line, %
CreateCopyOfModelsJob.java0%   (0/1)0%   (0/6)0%   (0/171)0%   (0/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateCopyOfModelsJob0%   (0/1)0%   (0/6)0%   (0/171)0%   (0/40)
CreateCopyOfModelsJob (CompletionConfiguration, Transformation): void 0%   (0/1)0%   (0/40)0%   (0/9)
copyModelsFromBlackboard (IFolder): void 0%   (0/1)0%   (0/110)0%   (0/21)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/14)0%   (0/6)
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.HashMap;
5 
6import org.apache.log4j.Logger;
7import org.eclipse.core.resources.IFolder;
8import org.eclipse.core.runtime.IProgressMonitor;
9import org.eclipse.emf.common.util.URI;
10import org.eclipse.emf.ecore.resource.Resource;
11import org.eclipse.emf.ecore.resource.ResourceSet;
12 
13import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration;
14import de.uka.ipd.sdq.cip.configuration.Transformation;
15import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
16import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
17import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
18import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
19import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
20import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition;
21 
22public class CreateCopyOfModelsJob implements
23                IBlackboardInteractingJob<MDSDBlackboard> {
24 
25        /** The logger for this class */
26        private Logger logger = Logger.getLogger(CreateCopyOfModelsJob.class);
27        
28        /** The blackboard to interact with */
29        private MDSDBlackboard blackboard = null;
30        
31        /** The blackboard partition for this Job */
32        private String modelPartition;
33        
34        /** The project id where to create folders */
35        private String projectID;
36 
37        /** The transformation id where to copy models */
38        private String transformationID;
39        
40        public CreateCopyOfModelsJob(
41                        CompletionConfiguration completionConfiguration,
42                        Transformation transformation) {
43                
44                this.projectID = completionConfiguration.getProjectID();
45                this.modelPartition = completionConfiguration.getInputPartitionName();
46                
47                URI qvtFileURI = URI.createURI(transformation.getQVTFileURI());
48                this.transformationID = qvtFileURI.lastSegment().replace(qvtFileURI.fileExtension(), "") + 
49                        completionConfiguration.getTransformations().indexOf(transformation);
50        }
51 
52        @Override
53        public void execute(IProgressMonitor monitor) throws JobFailedException,
54                        UserCanceledException {
55                
56                IFolder modelFolder = PrepareTransformationsJob.createFolder(
57                                PrepareTransformationsJob.getModelFolder(projectID).getFolder(
58                                                transformationID),
59                                logger);
60                
61                // Copy models
62                copyModelsFromBlackboard(modelFolder);
63                
64        }
65        
66        private void copyModelsFromBlackboard(IFolder modelFolder) throws JobFailedException {
67        
68 
69                URI baseURI = URI.createURI("file:/"+modelFolder.getLocation().toOSString());
70                
71                // access the resources
72                ResourceSetPartition partition = (ResourceSetPartition) this.blackboard.getPartition(modelPartition);
73                ResourceSet resourceSet = partition.getResourceSet();
74                for (Resource resource : resourceSet.getResources()) {
75                        
76                        // we only need to copy the file models
77                        if (resource.getURI().isFile()) {
78                                
79                                // get old resource path
80                                URI oldURI = resource.getURI();
81                                String[] oldURISegments = oldURI.segments();
82                                // set the new resource path
83                                URI newURI = baseURI;
84                                if(oldURISegments.length > 1)
85                                        newURI = newURI.appendSegment(oldURISegments[oldURISegments.length - 2]);
86                                newURI = newURI.appendSegment(oldURISegments[oldURISegments.length - 1]);
87                                resource.setURI(newURI);
88                                
89                                try {
90                                        resource.save(new HashMap<String ,String>());
91                                        partition.setContents(resource.getURI(), resource.getContents());
92                                } catch (IOException e) {
93                                        logger.error("Unable to store resource "+resource.getURI(),e);
94                                }
95                        }
96                }
97                
98                try {
99                        partition.storeAllResources();
100                } catch (IOException e) {
101                        logger.error("unable to store all resources",e);
102                        throw new JobFailedException("Unable to store all Resources");
103                }
104        }
105 
106        @Override
107        public void setBlackboard(MDSDBlackboard blackboard) {
108                this.blackboard = blackboard;        
109        }
110 
111 
112        @Override
113        public String getName() {
114                return null;
115        }
116 
117        @Override
118        public void rollback(IProgressMonitor monitor)
119                        throws RollbackFailedException {}  // nothing to roll back
120}

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