Commit 51a392e5 authored by Christoph Döbber's avatar Christoph Döbber
Browse files

working on external references

refs 1007
parent 5c2f5d29
......@@ -183,7 +183,7 @@ public class ImageSection {
return;
}
newItem.setUri(destFile.getName());
newItem.setUri(new File(PROJECT_IMAGE_SUBFOLDER, destFile.getName()).getPath());
ICommandStackService.INSTANCE.runAsCommand(editedObject, new Runnable() {
@Override
......
......@@ -116,7 +116,9 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ImageItem" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IExternalDocumentReference"/>
<eClassifiers xsi:type="ecore:EClass" name="ImageItem" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IExternalDocumentReference">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="path" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="IImageContainer">
<eStructuralFeatures xsi:type="ecore:EReference" name="images" upperBound="-1"
eType="#//ImageItem" containment="true"/>
......@@ -498,6 +500,7 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="isLocal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="description" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="url" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RequirementSourceElement" abstract="true"
eSuperTypes="#//ContextElement">
......
......@@ -59,7 +59,9 @@
<genClasses ecoreClass="mira.ecore#//RequirementSpecification">
<genOperations ecoreOperation="mira.ecore#//RequirementSpecification/getRequirement"/>
</genClasses>
<genClasses ecoreClass="mira.ecore#//ImageItem"/>
<genClasses ecoreClass="mira.ecore#//ImageItem">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//ImageItem/path"/>
</genClasses>
<genClasses ecoreClass="mira.ecore#//IImageContainer">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mira.ecore#//IImageContainer/images"/>
</genClasses>
......@@ -246,6 +248,7 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//requirementSource/FileItem/version"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//requirementSource/FileItem/isLocal"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//requirementSource/FileItem/description"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//requirementSource/FileItem/url"/>
</genClasses>
<genClasses image="false" ecoreClass="mira.ecore#//requirementSource/RequirementSourceElement">
<genOperations ecoreOperation="mira.ecore#//requirementSource/RequirementSourceElement/getRequirementSource"/>
......
......@@ -25,7 +25,12 @@ import static org.fortiss.af3.mira.utils.MiraModelElementFactory.createRequireme
import static org.fortiss.af3.mira.utils.MiraModelElementFactory.createRequirementsContainer;
import static org.fortiss.af3.mira.utils.MiraUtils.initializeRequirementRelationStatus;
import java.io.File;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ImageItem;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementRelation;
import org.fortiss.af3.mira.model.RequirementsContainer;
......@@ -35,6 +40,7 @@ import org.fortiss.af3.mira.model.relations.DirectedRequirementRelationType;
import org.fortiss.af3.mira.model.relations.OverridingRequirementRelation;
import org.fortiss.af3.mira.model.relations.RefinementRequirementRelation;
import org.fortiss.af3.mira.model.relations.UndirectedRequirementRelationType;
import org.fortiss.af3.mira.model.requirementSource.FileItem;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
......@@ -64,11 +70,83 @@ public class AnalysisMigrationProvider implements IMigrationProvider {
migrateRequirements1057((Analysis)projectRootElement);
migrateRequirementRelations1005((Analysis)projectRootElement);
// TODO (CD) remove after release of 2.4 AUG 2013
migrateImageAndFileURIs1007((Analysis)projectRootElement);
}
}
}
/**
* Check need for migration for https://af3.fortiss.org/issues/1007
*
* @param modelElement
* @return need of migration
*/
private boolean needMigration1007(ITopLevelElement modelElement) {
if(!(modelElement.getRootModelElement() instanceof FileProject)) {
return false;
}
FileProject fileProject = (FileProject)modelElement.getRootModelElement();
for(IProjectRootElement projectRootElement : fileProject.getRootElementsList()) {
if(projectRootElement instanceof Analysis) {
TreeIterator<EObject> iterator = projectRootElement.eAllContents();
while(iterator.hasNext()) {
EObject object = iterator.next();
if(object instanceof FileItem) {
FileItem item = (FileItem)object;
if(item.getUrl() != null) {
return true;
}
}
if(object instanceof ImageItem) {
ImageItem item = (ImageItem)object;
if(item.getPath() != null) {
return true;
}
}
}
}
}
return false;
}
/**
* Migration method for requirements for https://af3.fortiss.org/issues/1007
*
* @param analysis
*/
private void migrateImageAndFileURIs1007(Analysis analysis) {
String oldImagesFolder = "images";
TreeIterator<EObject> iterator = analysis.eAllContents();
while(iterator.hasNext()) {
EObject object = iterator.next();
if(object instanceof FileItem) {
FileItem item = (FileItem)object;
if(item.getUrl() != null) {
File f = new File(item.getUrl());
if(f.exists()) {
item.setUri(new File(f.getParent(), f.getName()).getPath());
} else {
item.setUri(item.getUrl());
}
item.setUrl(null);
}
}
if(object instanceof ImageItem) {
ImageItem item = (ImageItem)object;
if(item.getPath() != null) {
item.setUri(oldImagesFolder + item.getPath());
item.setPath(null);
}
}
}
}
/**
* Check need for migration for https://af3.fortiss.org/issues/1057
*
......@@ -86,7 +164,7 @@ public class AnalysisMigrationProvider implements IMigrationProvider {
for(IProjectRootElement projectRootElement : fileProject.getRootElementsList()) {
if(projectRootElement instanceof Analysis) {
for(IHierarchicElement containedElement : ((Analysis)projectRootElement)
.getContainedElementsList().toArray(new IHierarchicElement[0])) {
.getContainedElementsList()) {
if(containedElement instanceof Requirement) {
return true;
......@@ -105,8 +183,7 @@ public class AnalysisMigrationProvider implements IMigrationProvider {
private void migrateRequirements1057(Analysis analysis) {
RequirementsContainer container = null;
for(IHierarchicElement containedElement : analysis.getContainedElementsList().toArray(
new IHierarchicElement[0])) {
for(IHierarchicElement containedElement : analysis.getContainedElementsList()) {
if(containedElement instanceof Requirement) {
......@@ -207,6 +284,10 @@ public class AnalysisMigrationProvider implements IMigrationProvider {
if(needMigration1005(modelElement)) {
return true;
}
if(needMigration1007(modelElement)) {
return true;
}
return false;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.model.migration;
import java.io.File;
/**
*
* @author doebber
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String a = "/Users/doebber/Desktop/AF3 old models/DoorsManagementSystemECBS2013.af3_23";
String b =
"http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=43464";
File af = new File(a);
File bf = new File(b);
System.out.println(af.exists());
System.out.println(bf.exists());
System.out.println(af.toURI());
System.out.println(bf.toURI());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment