diff --git a/etc/hsqldb/vdldb.script b/etc/hsqldb/vdldb.script index 22ab2ec..93064a2 100644 --- a/etc/hsqldb/vdldb.script +++ b/etc/hsqldb/vdldb.script @@ -19,8 +19,9 @@ CREATE MEMORY TABLE VRERELATEDMETADATAFORMAT(VREID VARCHAR,COLLID VARCHAR,MFID V CREATE MEMORY TABLE SERVICES(ID INTEGER NOT NULL,NAME VARCHAR NOT NULL,CLASS VARCHAR NOT NULL, VERSION VARCHAR NOT NULL, PRIMARY KEY(NAME,CLASS),CONSTRAINT SYS_FK_189 FOREIGN KEY(ID) REFERENCES FUNCTIONALITY(ID)) CREATE MEMORY TABLE VRERELATEDFUNCT(VREID VARCHAR NOT NULL,FUNCID VARCHAR NOT NULL,PRIMARY KEY(VREID,FUNCID)) CREATE MEMORY TABLE RELATEDSERVICEID(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,CLASS VARCHAR NOT NULL) -CREATE MEMORY TABLE PORTLET(NAME VARCHAR NOT NULL PRIMARY KEY, PORTLETCLASS VARCHAR, PARENT VARCHAR) -CREATE MEMORY TABLE PORTLETRELTOFUNCT(FUNCID INTEGER NOT NULL,PORTLETNAME VARCHAR NOT NULL ,PRIMARY KEY(FUNCID, PORTLETNAME), FOREIGN KEY(PORTLETNAME) REFERENCES PORTLET(NAME), FOREIGN KEY(FUNCID) REFERENCES FUNCTIONALITY(ID) ) +CREATE MEMORY TABLE PORTLETRELTOFUNCT(FUNCID INTEGER NOT NULL,PORTLETCLASS VARCHAR NOT NULL, FOREIGN KEY(FUNCID) REFERENCES FUNCTIONALITY(ID) ) +CREATE MEMORY TABLE NEEDEDRESOURCES(ID VARCHAR NOT NULL, TYPE VARCHAR NOT NULL, PRIMARY KEY(ID)) + ALTER TABLE FUNCTIONALITY ALTER COLUMN ID RESTART WITH 17 CREATE USER SA PASSWORD "" GRANT DBA TO SA @@ -28,10 +29,6 @@ SET WRITE_DELAY 10 SET SCHEMA PUBLIC CREATE VIEW SELECTEDNATIVEMDFORMAT(vreid, mdfid, mdcollid, collectionid) AS SELECT v.vreid, v.mfid, mdc.id, v.collid FROM VRERELATEDMETADATAFORMAT AS v, MDCOLLECTION AS mdc, NATIVEMDF AS n WHERE v.mfid=n.MDFID AND v.collid=mdc.relatedcollectionid AND n.mdcollid=mdc.id CREATE VIEW SELECTEDDERIVABLEMDFORMAT(vreid, mdfid, mdcollid, collectionid, tpid) AS SELECT v.vreid, v.mfid, mdc.id, v.collid, n.tpid FROM VRERELATEDMETADATAFORMAT AS v, MDCOLLECTION AS mdc, DERIVABLEMDF AS n WHERE v.mfid=n.MDFID AND v.collid=mdc.relatedcollectionid AND n.mdcollid=mdc.id -INSERT INTO PORTLET VALUES('Search', null, null) -INSERT INTO PORTLET VALUES('search', null, 'Search') -INSERT INTO PORTLET VALUES('CollectionsNavigatorPortlet','collectionsnavigator#CollectionsNavigatorPortlet', 'search') -INSERT INTO PORTLET VALUES('GSPortlet','searchGUI#Search', 'search') INSERT INTO FUNCTIONALITY VALUES(0,'Search (Browse, Simple, and Combined)','By selecting this function VRE users will be provided with facilities supporting the discovery of Information Objects by issuing simple keyword based queries. This is the simplest modality for discovering the Information Objects constituting the VRE Information Space. In addition to the specification of the keywords characterising the Information Objects the user is interested in, this function permit to restrict the Information Space in which to search by specifying the set of Collections against which the query will be evaluated.',7,0) INSERT INTO FUNCTIONALITY VALUES(1,'Annotation','By selecting this function VRE users will be provided with facilities for annotating Information Objects. Annotations are additional Information Objects including notes, structured comments or links that an Actor may associate to an existing Information Object to add an interpretative value. This function is particularly useful to support co-operation between the users of a VRE since it allows not only to enrich an Information Object with personal observation and thus share this comment within the VRE community but, in general, also as a mean for transmitting and sharing ideas and thus doing research.',8,0) @@ -46,8 +43,14 @@ INSERT INTO FUNCTIONALITY VALUES(9,'Search by Query Expression','',7,0) INSERT INTO FUNCTIONALITY VALUES(10,'Google Search','By selecting this function VRE users will be provided with facilities supporting the discovery of Information Objects through Google and thus conceptually residing in the Web. Google is nowadays one of the most used search engines for the World Wide Web, the activation of this function integrates the power of such a search engine into the Virtual Research Environment providing thus providing the VRE users with operations for searching the Web and using the discovered objects to accomplish their activities.',7,0) INSERT INTO FUNCTIONALITY VALUES(11,'Metadata Editing','',8,0) -INSERT INTO PORTLETRELTOFUNCT VALUES(0,'CollectionsNavigatorPortlet') -INSERT INTO PORTLETRELTOFUNCT VALUES(0,'GSPortlet') +INSERT INTO PORTLETRELTOFUNCT VALUES(0,'quicksearchportlet#QuickSearchPortlet') +INSERT INTO PORTLETRELTOFUNCT VALUES(0,'collectionsnavigator#CollectionsNavigatorPortlet') +INSERT INTO PORTLETRELTOFUNCT VALUES(0,'searchGUI#Search') +INSERT INTO PORTLETRELTOFUNCT VALUES(0,'resultsetPortlet#ResultsetPortlet') +INSERT INTO PORTLETRELTOFUNCT VALUES(0,'Metadata_Viewing_Portlet#Metadata_Viewing_Portlet') +INSERT INTO PORTLETRELTOFUNCT VALUES(1,'AnnotationFrontEnd#GenericAnnotationPortlet') + + INSERT INTO SERVICES VALUES(1,'ABE','Annotation', '1.00.00') INSERT INTO SERVICES VALUES(0,'FilterXPathOperator','Search','1.00.00') diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java b/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java index a3feeee..af61048 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java @@ -81,12 +81,23 @@ public class ModelFactoryService extends GCUBEStartupPortType{ * * @param request void * @return void - * @throws RemoteException remote exception + * @throws GCUBEFault thrown if something fails */ public void initDB(VOID arg) throws GCUBEFault { logger.debug("initDB method"); - //new InitThread(factoryEPR, cred).start(); - + + Thread t= new Thread(){ + public void run(){ + try{ + ServiceContext.getContext().intializeDB(); + }catch(Exception e){ + logger.error("DB inizialization failed"+e); + e.printStackTrace(); + } + } + }; + + t.start(); } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java index f9406b3..474ea40 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java @@ -22,8 +22,7 @@ public class ServiceContext extends GCUBEServiceContext{ protected void onReady() throws Exception{ try{ logger.info("ready event invoked on " + this.getName()); - ServiceContext.getContext().setScope(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]); - IStoDBUtil.initDB(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]); + this.intializeDB(); ModelerContext.getPortTypeContext().getWSHome().checkResourceScope(); }catch (Exception e){ this.setStatus(Status.FAILED, true); @@ -31,4 +30,8 @@ public class ServiceContext extends GCUBEServiceContext{ } } + protected void intializeDB() throws Exception{ + ServiceContext.getContext().setScope(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]); + IStoDBUtil.initDB(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]); + } } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java index bd760f4..d6e0188 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java @@ -42,6 +42,7 @@ import org.gcube.vremanagement.vremodeler.impl.ModelerService; import org.gcube.vremanagement.vremodeler.impl.util.Couple; import org.gcube.vremanagement.vremodeler.impl.util.VREManagerServiceHandler; import org.gcube.vremanagement.vremodeler.portallayout.CollectionResourceCreation; +import org.gcube.vremanagement.vremodeler.portallayout.GenericResourcePortlet; import org.gcube.vremanagement.vremodeler.portallayout.LayoutCreation; import org.globus.wsrf.ResourceException; import org.w3c.dom.Document; @@ -56,7 +57,6 @@ public class DeployVRE extends Thread{ private String resourceId; private GCUBEScope startingScope; private String vreName=null; - private LayoutCreation layoutCreation; private CollectionResourceCreation collectionResourceCreation; public DeployVRE(String resourceId, GCUBEScope scope){ @@ -71,17 +71,18 @@ public class DeployVRE extends Thread{ public void run() { try { - ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid from VRERELATEDGHN where VRERELATEDGHN.vreid='"+this.resourceId+"'; "); + ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid, GHN.domain from VRERELATEDGHN, GHN where GHN.id=VRERELATEDGHN.ghnid and VRERELATEDGHN.vreid='"+this.resourceId+"'; "); if (!resRelatedGHN.next()){ throw new Exception("No ghn Selected"); } + String firstGHNId= resRelatedGHN.getString(1); List GHNList= new ArrayList(); while (resRelatedGHN.next()) GHNList.add(resRelatedGHN.getString(1)); if (!deployManagerOnVRE(firstGHNId)){ - if (!createVRE(GHNList, firstGHNId)){ + if (!createVRE(GHNList)){ DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+ModelerService.DEPLOYED+"' WHERE VRE.id='"+this.resourceId+"';"); logger.info("Deploying of the VRE with id "+this.resourceId+" FINISHED"); } @@ -172,31 +173,18 @@ public class DeployVRE extends Thread{ return false; } this.vreName= vreName; - layoutCreation= new LayoutCreation(this.resourceId, this.vreName); collectionResourceCreation= new CollectionResourceCreation(this.resourceId, this.vreName); return vreManagerHandler.getReturnValue(); } - private boolean createVRE(List ghnList, String ghnId) throws GCUBEFault{ + + + + + private boolean createVRE(List ghnList) throws GCUBEFault{ VREManagerServiceHandler, String>> vreManagerHandler= new VREManagerServiceHandler, String>>(){ - - @Override - protected List findInstances() throws Exception { - try{ - ISClient client = GHNContext.getImplementation(ISClient.class); - GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addAtomicConditions(new AtomicCondition("//ServiceName", "VREManager"), new AtomicCondition("/Profile/GHN/@UniqueID", this.relatedGhnId)); - System.out.println(this.relatedGhnId); - List eprs = new ArrayList(); - for (GCUBERunningInstance instance : client.execute(query, scope)) - eprs.add(instance.getAccessPoint().getEndpoint("gcube/vremanagement/VREManager")); - return eprs; - }catch(Exception e){e.printStackTrace(); throw e;} - } - - //the parameter is resourceID @SuppressWarnings("static-access") @Override @@ -243,8 +231,8 @@ public class DeployVRE extends Thread{ ops.setScopeOptionList(scopeOptionList); vreManPortType.setScopeOptions(ops); - //creating the GenericResource - layoutCreation.createAndPublishLayout(); + //creating the GenericResources for Portlets and Collection + GenericResourcePortlet.createResource(getResource().getId(), vreName); collectionResourceCreation.createAndPublish(); //waiting few seconds to be sure that generic resources will be published @@ -283,13 +271,8 @@ public class DeployVRE extends Thread{ logger.error("Error contacting HSQLDB "+sqle); } - //adding the Layout genericResource - ResourceItem genResItem= new ResourceItem(); - genResItem.setID(layoutCreation.getCreatedResourceId()); - genResItem.setType(GCUBEGenericResource.TYPE); - resItemList.add(genResItem); - //adding the CollectionResource genericResource + ResourceItem genResItem= new ResourceItem(); genResItem= new ResourceItem(); genResItem.setID(collectionResourceCreation.getCreatedResourceId()); genResItem.setType(GCUBEGenericResource.TYPE); @@ -353,7 +336,6 @@ public class DeployVRE extends Thread{ }; vreManagerHandler.clearState(); - vreManagerHandler.relatedGhnId=ghnId; vreManagerHandler.setHandled(new GCUBEServiceClientImpl()); vreManagerHandler.setParameter(new Couple, String>(ghnList,this.resourceId)); vreManagerHandler.scope=GCUBEScope.getScope(this.startingScope+"/"+this.vreName); diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/VREManagerServiceHandler.java b/src/org/gcube/vremanagement/vremodeler/impl/util/VREManagerServiceHandler.java index 89db0a9..0ecfd8f 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/VREManagerServiceHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/VREManagerServiceHandler.java @@ -6,7 +6,6 @@ import java.util.List; import org.apache.axis.message.addressing.EndpointReferenceType; import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.informationsystem.client.AtomicCondition; import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; import org.gcube.common.core.resources.GCUBERunningInstance; @@ -48,7 +47,14 @@ public abstract class VREManagerServiceHandler extends GCUBEServiceHandler try{ ISClient client = GHNContext.getImplementation(ISClient.class); GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addAtomicConditions(new AtomicCondition("//ServiceName", "VREManager")); + + query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" + + " for $outer in collection(\"/db/Profiles/RunningInstance\")//Document/Data/is:Profile/Resource " + + " let $scope:= $outer/Scopes/Scope[string() eq '"+scope.toString()+"'] " + + " where count($scope)>0 and $outer/Profile/ServiceName/string() eq 'VREManager'" + + " and $outer/Profile/ServiceName/string() eq 'VREManager' " + + " return $outer"); + List eprs = new ArrayList(); for (GCUBERunningInstance instance : client.execute(query, scope)) eprs.add(instance.getAccessPoint().getEndpoint("gcube/vremanagement/VREManager")); diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/GenericResourcePortlet.java b/src/org/gcube/vremanagement/vremodeler/portallayout/GenericResourcePortlet.java new file mode 100644 index 0000000..9de44ad --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/GenericResourcePortlet.java @@ -0,0 +1,39 @@ +package org.gcube.vremanagement.vremodeler.portallayout; + +import java.sql.ResultSet; + +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; +import org.w3c.dom.Document; + + +public class GenericResourcePortlet { + + public static void createResource(String vreId, String vreName) throws Exception{ + + GCUBEGenericResource resource= GHNContext.getImplementation(GCUBEGenericResource.class); + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + DBInterface.connect(); + ResultSet rs= DBInterface.queryDB("select pf.PORTLETCLASS from PORTLETRELTOFUNCT as pf, VRERELATEDFUNCT as vf where vf.vreid='"+vreId+"' and pf.FUNCID=vf.FUNCID"); + while(rs.next()) + doc.appendChild(XMLUtil.createTextElement(doc, "Portlet", rs.getString(1))); + resource.setBody(XMLUtil.docToString(doc)); + + resource.setDescription("List of selectable Portlet for the VRE "+vreName); + resource.setName("AvailablePortlets"); + resource.setSecondaryType("PortletLayoutResource"); + + ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class); + publisher.registerGCUBEResource(resource,GCUBEScope.getScope(ServiceContext.getContext().getScope()+"/"+vreName) , ServiceContext.getContext()); + } + + + +} diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java b/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java index c7debcc..2b14bf1 100644 --- a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java @@ -71,7 +71,6 @@ public class LayoutCreation { ResultSet parentPortlet= DBInterface.queryDB("select p.name, p.parent from PORTLET as p WHERE p.name='"+parent+"' ;"); parentPortlet.next(); AbstractTree tempParent= new TreeNode(parentPortlet.getString(1)); - System.out.println("parentPortlet: "+parentPortlet.getString(1)); tempParent.addPathNode(child); child= tempParent; try{