Commit 1c2037e7 authored by Kyriakos Kritikos's avatar Kyriakos Kritikos

Small modifications due to CAMEL update

parent d7078fc8
......@@ -28,8 +28,7 @@
<dataCentres
name="Flexiant_Data_Centre"
codeName="flexiant"
location="//@locationModels.0/@countries.0"
cloudProvider="//@organisationModels.0/@provider"/>
location="//@locationModels.0/@countries.0"/>
</organisationModels>
<providerModels
name="Flexiant_Provider_Model">
......
......@@ -28,8 +28,7 @@
<dataCentres
name="GWDG_Data_Centre"
codeName="gwdg"
location="//@locationModels.0/@countries.0"
cloudProvider="//@organisationModels.0/@provider"/>
location="//@locationModels.0/@countries.0"/>
</organisationModels>
<providerModels
name="GWDG_Provider_Model">
......
......@@ -59,9 +59,9 @@ public class ModelImporter {
private boolean inCdo = false;
private CDOClient cl = null;
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CDOClient.class);
private boolean hibernate = false;
public ModelImporter(){
}
/* the constructor takes as input a boolean parameter indicating whether we store imported
......@@ -70,7 +70,18 @@ public class ModelImporter {
*/
public ModelImporter(boolean inCdo){
this.inCdo = inCdo;
cl = new CDOClient();
cl = new CDOClient("Administrator","0000");
if (inCdo) createRepositoryStructure();
}
/* the constructor takes as input a boolean parameter indicating whether we store imported
* or generated information in the CDO repository. In case we do, then the respective
* CDO Repository resource folder structure is created.
*/
public ModelImporter(boolean inCdo, boolean hibernate){
this.inCdo = inCdo;
this.hibernate = hibernate;
cl = new CDOClient("Administrator","0000");
if (inCdo) createRepositoryStructure();
}
......@@ -177,7 +188,11 @@ public class ModelImporter {
for (Country country: model.getCountries()){
String name = country.getName();
logger.debug("Processing country: " + name);
Country corCountry = trans.createQuery("hql", "select c from Country c where c.name like '%" + name + "%' or '" + name + "' member of c.alternativeNames").getResult(Country.class).get(0);
Country corCountry = null;
if (!hibernate)
corCountry = trans.createQuery("sql", "select distinct c.* from CAMEL_COUNTRY c, CAMEL_COUNTRY_ALTERNATIVENAMES_LIST list where c.name like '%" + name + "%' or (list.cdo_source=c.cdo_id and list.cdo_value='" + name + "')").getResult(Country.class).get(0);
else
corCountry = trans.createQuery("hql", "select c from Country c where c.name like '%" + 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();
......@@ -196,7 +211,11 @@ public class ModelImporter {
for (GeographicalRegion region: model.getRegions()){
String name = region.getName();
logger.debug("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);
GeographicalRegion corRegion = null;
if (!hibernate)
corRegion = trans.createQuery("sql", "select distinct r.* from CAMEL_GEOGRAPHICALREGION r, CAMEL_GEOGRAPHICALREGION_ALTERNATIVENAMES_LIST list where r.name='" + name + "' or (list.cdo_source=r.cdo_id and list.cdo_value='" + name + "')").getResult(GeographicalRegion.class).get(0);
else
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();
......@@ -289,7 +308,11 @@ public class ModelImporter {
CDOTransaction trans = cl.openTransaction();
OrganisationModel om2 = (OrganisationModel)trans.getOrCreateResource(orgPath + "/" + orgName).getContents().get(0);
CamelModel cm2 = (CamelModel)trans.getOrCreateResource(userPath + "/" + userEmail).getContents().get(0);
User u = trans.createQuery("hql", "select u from User u where u.email='" + user.getEmail() + "'").getResult(User.class).get(0);
User u = null;
if (!hibernate)
u = trans.createQuery("sql", "select u.* from CAMEL_USER u where u.email='" + user.getEmail() + "'").getResult(User.class).get(0);
else
u = trans.createQuery("hql", "select u from User u where u.email='" + user.getEmail() + "'").getResult(User.class).get(0);
u.getRequirementModels().addAll(cm2.getRequirementModels());
for (Application a: cm2.getApplications()) a.setOwner(u);
trans.commit();
......@@ -343,8 +366,16 @@ public class ModelImporter {
CDOResource res = trans.getOrCreateResource("locations/locations");
LocationModel lm2 = (LocationModel)res.getContents().get(0);
EList<CloudLocation> cloudLocations2 = lm2.getCloudLocations();
DataCenter flexiant = trans.createQuery("hql", "select dc from CloudProvider cp, DataCenter dc where cp.name='Flexiant' and dc.cloudProvider=cp").getResult(DataCenter.class).get(0);
DataCenter gwdg = trans.createQuery("hql", "select dc from CloudProvider cp, DataCenter dc where cp.name='GWDG' and dc.cloudProvider=cp").getResult(DataCenter.class).get(0);
DataCenter flexiant = null;
DataCenter gwdg = null;
if (!hibernate){
flexiant = trans.createQuery("sql", "select dc.* from CAMEL_ORGANISATION cp, CAMEL_DATACENTER dc, CAMEL_ORGANISATIONMODEL om, CAMEL_ORGANISATIONMODEL_DATACENTRES_LIST list where cp.name='Flexiant' and list.cdo_source=om.cdo_id and list.cdo_value=dc.cdo_id and om.organisation=cp.cdo_id").getResult(DataCenter.class).get(0);
gwdg = trans.createQuery("sql", "select dc.* from CAMEL_ORGANISATION cp, CAMEL_DATACENTER dc, CAMEL_ORGANISATIONMODEL om, CAMEL_ORGANISATIONMODEL_DATACENTRES_LIST list where cp.name='GWDG' and list.cdo_source=om.cdo_id and list.cdo_value=dc.cdo_id and om.organisation=cp.cdo_id").getResult(DataCenter.class).get(0);
}
else{
flexiant = trans.createQuery("hql", "select dc from Organisation cp, Datacenter dc, OrganisationModel om where cp.name='Flexiant' and dc member of om.dataCentres and om.provider=cp").getResult(DataCenter.class).get(0);
gwdg = trans.createQuery("hql", "select dc from Organisation cp, Datacenter dc, OrganisationModel om where cp.name='GWDG' and dc member of om.dataCentres and om.provider=cp").getResult(DataCenter.class).get(0);
}
for(CloudLocation cloc: cloudLocations){
String id = cloc.getId();
logger.debug("Checking CloudLocation: " + id);
......@@ -470,7 +501,7 @@ public class ModelImporter {
* according to the model storage guidelines specified in the content of PaaSage WP2
*/
public void createRepositoryStructure(){
CDOClient cl = new CDOClient();
//CDOClient cl = new CDOClient("Administrator","0000");
CDOTransaction trans = cl.openTransaction();
trans.getOrCreateResourceFolder("sec");
......@@ -496,7 +527,7 @@ public class ModelImporter {
logger.error("Something went wrong while creating CDO Repository Structure",e);
}
cl.closeTransaction(trans);
cl.closeSession();
//cl.closeSession();
}
/* This method is used to generate a basic security model through processing a specific
......@@ -518,8 +549,46 @@ public class ModelImporter {
CDOTransaction trans = cl.openTransaction();
List<Unit> replUnits = new ArrayList<Unit>();
for (Unit u: units){
Unit unit = trans.createQuery("hql", "select u from Unit u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class).get(0);
replUnits.add(unit);
if (!hibernate){
List<Unit> uns = trans.createQuery("sql", "select u.* from CAMEL_COREUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_MONETARYUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_REQUESTUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_STORAGEUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_THROUGHPUTUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_TIMEINTERVALUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
else{
uns = trans.createQuery("sql", "select u.* from CAMEL_TRANSACTIONUNIT u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
}
}
}
}
}
}
}
else{
List<Unit> uns = trans.createQuery("hql", "select u from Unit u where lower(u.name)='" + u.getName().toLowerCase() + "'").getResult(Unit.class);
if (uns != null && !uns.isEmpty())
replUnits.add(uns.get(0));
}
}
for (Metric m: mm.getMetrics()){
Unit u = m.getUnit();
......@@ -553,7 +622,7 @@ public class ModelImporter {
public static void main(String[] args){
int status = 0;
if (args.length == 0){
ModelImporter mi = new ModelImporter(true);
ModelImporter mi = new ModelImporter(true,true);
mi.importGeoLocationModels("input/geopolitical.owl", "locations");
mi.importProviderModels("input/providers");
//mi.importCloudLocations("input/providers/CloudLocationModel.xmi");
......
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