Commit 50a12261 authored by Kyriakos Kritikos's avatar Kyriakos Kritikos

Modifications to consider locations referenced locally to be replaced with...

Modifications to consider locations referenced locally to be replaced with references to locations in the CDOResource /locations/locations
parent 37cfa2bc
......@@ -3,6 +3,7 @@ package eu.paasage.mddb.model.importer;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
......@@ -11,35 +12,27 @@ import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.util.EcoreUtil;
import eu.paasage.camel.Application;
import eu.paasage.camel.CamelFactory;
import eu.paasage.camel.CamelModel;
import eu.paasage.camel.CamelPackage;
import eu.paasage.camel.deployment.Component;
import eu.paasage.camel.deployment.DeploymentModel;
import eu.paasage.camel.deployment.VMRequirementSet;
import eu.paasage.camel.location.Country;
import eu.paasage.camel.location.GeographicalRegion;
import eu.paasage.camel.location.LocationModel;
import eu.paasage.camel.metric.ConditionContext;
import eu.paasage.camel.metric.MetricContext;
import eu.paasage.camel.metric.MetricModel;
import eu.paasage.camel.organisation.CloudProvider;
import eu.paasage.camel.organisation.Entity;
import eu.paasage.camel.organisation.Organisation;
import eu.paasage.camel.organisation.OrganisationModel;
import eu.paasage.camel.organisation.OrganisationPackage;
import eu.paasage.camel.organisation.User;
import eu.paasage.camel.provider.ProviderModel;
import eu.paasage.camel.requirement.LocationRequirement;
import eu.paasage.camel.requirement.OSOrImageRequirement;
import eu.paasage.camel.requirement.OptimisationRequirement;
import eu.paasage.camel.requirement.QuantitativeHardwareRequirement;
import eu.paasage.camel.requirement.Requirement;
import eu.paasage.camel.requirement.RequirementFactory;
import eu.paasage.camel.requirement.RequirementModel;
import eu.paasage.camel.requirement.ScaleRequirement;
import eu.paasage.camel.requirement.ServiceLevelObjective;
import eu.paasage.camel.scalability.ScalabilityModel;
import eu.paasage.mddb.cdo.client.CDOClient;
import eu.paasage.mddb.model.importer.location.LocationGenerator;
......@@ -119,6 +112,39 @@ public class ModelImporter {
return false;
}
private void fixLocationModel(LocationModel model, CDOTransaction trans){
for (Country country: model.getCountries()){
String name = country.getName();
System.out.println("Processing country: " + name);
Country corCountry = trans.createQuery("hql", "select c from Country c where c.name='" + name + "' or '" + name + "' member of c.alternativeNames").getResult(Country.class).get(0);
Collection<Setting> references = EcoreUtil.UsageCrossReferencer.find(country, country.eResource());
for (Setting setting : references) {
EObject source = setting.getEObject();
System.out.println("Source is: " + source);
if (source instanceof LocationRequirement){
LocationRequirement lr = (LocationRequirement)source;
lr.getLocations().remove(country);
lr.getLocations().add(corCountry);
}
}
}
for (GeographicalRegion region: model.getRegions()){
String name = region.getName();
System.out.println("Processing region: " + name);
GeographicalRegion corRegion = trans.createQuery("hql", "select r from GeographicalRegion r where r.name='" + name + "' or '" + name + "' member of r.alternativeNames").getResult(GeographicalRegion.class).get(0);
Collection<Setting> references = EcoreUtil.UsageCrossReferencer.find(region, region.eResource());
for (Setting setting : references) {
EObject source = setting.getEObject();
System.out.println("Source is: " + source);
if (source instanceof LocationRequirement){
LocationRequirement lr = (LocationRequirement)source;
lr.getLocations().remove(region);
lr.getLocations().add(corRegion);
}
}
}
}
private boolean processUseCaseModel(EObject model){
if (model instanceof CamelModel){
CamelModel cm = (CamelModel)model;
......@@ -173,7 +199,18 @@ public class ModelImporter {
}
}
String userPath = orgPath + "/" + userEmail;
stored = cl.storeModel(cm, userPath + "/" + userEmail, false);
try{
CDOTransaction trans = cl.openTransaction();
CDOResource userRes = trans.getOrCreateResource(userPath + "/" + userEmail);
for (LocationModel lm: cm.getLocationModels()) fixLocationModel(lm,trans);
cm.getLocationModels().clear();
userRes.getContents().add(cm);
trans.commit();
trans.close();
}
catch(Exception e){
e.printStackTrace();
}
if (stored){
try{
CDOTransaction trans = cl.openTransaction();
......
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