diff --git a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java index d700ba9..cfd11e1 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java @@ -26,11 +26,13 @@ import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.queries.GCUBECSQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery; import org.gcube.common.core.resources.GCUBECS; import org.gcube.common.core.resources.GCUBECollection; +import org.gcube.common.core.resources.GCUBEGenericResource; import org.gcube.common.core.resources.GCUBEHostingNode; import org.gcube.common.core.resources.GCUBEMCollection; import org.gcube.common.core.resources.GCUBERunningInstance; @@ -76,11 +78,13 @@ public class IStoDBUtil { logger.debug("initialization: collection"); insertMetadataCollection(scope); logger.debug("initialization: metadata"); - insertCS(scope); - logger.debug("initialization: CS"); + //insertCS(scope); + //logger.debug("initialization: CS"); //insertServices(scope); insertGHN(scope); logger.debug("initialization: GHN"); + insertNeededResources(scope); + logger.debug("initialization: Needed Resources"); logger.info("Database Initialized!!"); } @@ -104,12 +108,42 @@ public class IStoDBUtil { DBInterface.deleteAll("runninginstance"); DBInterface.deleteAll("ghnrelatedri"); DBInterface.deleteAll("cs"); + DBInterface.deleteAll("NEEDEDRESOURCES"); }catch (SQLException e){logger.error("error cleaning sqlDB"); e.printStackTrace(); throw new GCUBEFault(e); } } + private static void insertNeededResources(GCUBEScope scope) throws GCUBEFault{ + List genericResourcesList= null; + try{ + if (queryClient==null) queryClient= GHNContext.getImplementation(ISClient.class); + GCUBEGenericResourceQuery query= queryClient.getQuery(GCUBEGenericResourceQuery.class); + query.addGenericCondition("$result/Profile/SecondType/string() eq 'UserProfile' or $result/Profile/SecondType/string() eq 'Schemas Searchable Fields' or $result/Profile/SecondType/string() eq 'MetadataXSLT' or $result/Profile/SecondType/string() eq 'PresentationXSLT'"); + genericResourcesList= queryClient.execute(query, scope); + }catch(Exception e ){logger.error("Error queryng IS"); throw new GCUBEFault(e); } + + //NEEDEDRESOURCES(ID, TYPE) + List> values = new ArrayList>(genericResourcesList.size()); + List row; + for (GCUBEGenericResource gen :genericResourcesList){ + row= new ArrayList(2); + row.add(gen.getID()); + row.add(gen.getType()); + } + + try{ + DBInterface.connect(); + DBInterface.InsertInto("NEEDEDRESOURCES", values); + }catch (SQLException e){ + logger.error("VDLModel: DB error "+e.getMessage()); + throw new GCUBEFault(e); + } + + } + + private static void insertCollection(GCUBEScope scope) throws GCUBEFault { List collectionList= null; diff --git a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java index d091cf4..bd760f4 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java @@ -295,6 +295,21 @@ public class DeployVRE extends Thread{ genResItem.setType(GCUBEGenericResource.TYPE); resItemList.add(genResItem); + //adding the other needed resources + try{ + ResourceItem resItem; + ResultSet neededRes =DBInterface.queryDB("select n.id, n.type from NEEDEDRESOURCES AS n;"); + while (neededRes.next()){ + resItem= new ResourceItem(); + resItem.setID(neededRes.getString(1)); + resItem.setType(neededRes.getString(2)); + resItemList.add(resItem); + } + }catch(SQLException sqle){ + sqle.printStackTrace(); + logger.error("Error contacting HSQLDB "+sqle); + } + rl.setResource(resItemList.toArray(new ResourceItem[0])); arp.setResources(rl); diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java b/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java index c2b1114..7968f1f 100644 --- a/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java @@ -23,6 +23,7 @@ import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery; import org.gcube.common.core.informationsystem.publisher.ISPublisher; import org.gcube.common.core.resources.GCUBEGenericResource; +import org.gcube.common.core.scope.GCUBEScope; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; import org.w3c.dom.Document; @@ -54,7 +55,7 @@ public class CollectionResourceCreation { res.load(new StringReader(this.transformCollectionResource())); ISPublisher pub= GHNContext.getImplementation(ISPublisher.class); res.setID(""); - res.load(new StringReader(pub.registerGCUBEResource(res, ServiceContext.getContext().getScope(), ServiceContext.getContext()))); + res.load(new StringReader(pub.registerGCUBEResource(res, GCUBEScope.getScope(ServiceContext.getContext().getScope()+"/"+this.vreName), ServiceContext.getContext()))); this.createdResourceId= res.getID(); } diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java b/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java index 414ccc0..c7debcc 100644 --- a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java @@ -7,6 +7,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.publisher.ISPublisher; import org.gcube.common.core.resources.GCUBEGenericResource; +import org.gcube.common.core.scope.GCUBEScope; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; import org.gcube.vremanagement.vremodeler.impl.util.XMLUtil; @@ -37,7 +38,7 @@ public class LayoutCreation { resource.setName("Layout_"+splitScope[1]+"_"+splitScope[2]+"_"+this.vreName); resource.setSecondaryType("VRE"); ISPublisher publisher= GHNContext.getImplementation(ISPublisher.class); - resource.load(new StringReader(publisher.registerGCUBEResource(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext()))); + resource.load(new StringReader(publisher.registerGCUBEResource(resource, GCUBEScope.getScope(ServiceContext.getContext().getScope()+"/"+this.vreName), ServiceContext.getContext()))); this.createdResourceId= resource.getID(); }