From f86a3a0d59af728efad4f7db45bf29b9c446f9ed Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Fri, 6 May 2011 10:36:42 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@38407 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 7 +- etc/hsqldb/vreModelerDBInitializer | 3 - schema/ModelerService.wsdl | 31 +---- .../consumers/CollectionConsumer.java | 7 +- .../consumers/MCollectionConsumer.java | 55 --------- .../vremodeler/db/IStoDBUtil.java | 8 +- .../vremodeler/impl/ModelerService.java | 108 +----------------- .../vremodeler/impl/ServiceContext.java | 6 - .../vremodeler/impl/util/Util.java | 47 -------- .../resources/handlers/CollectionHandler.java | 29 +++-- .../resources/handlers/GHNHandler.java | 3 - .../handlers/MCollectionHandler.java | 60 ---------- .../handlers/MetadataFormatHandler.java | 60 ---------- .../handlers/NativeMetadataFormatHandler.java | 24 ---- 14 files changed, 28 insertions(+), 420 deletions(-) delete mode 100644 src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java delete mode 100644 src/org/gcube/vremanagement/vremodeler/resources/handlers/MCollectionHandler.java delete mode 100644 src/org/gcube/vremanagement/vremodeler/resources/handlers/MetadataFormatHandler.java delete mode 100644 src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java diff --git a/.classpath b/.classpath index 328dfe7..d5b1e22 100644 --- a/.classpath +++ b/.classpath @@ -2,8 +2,11 @@ - - + + + + + diff --git a/etc/hsqldb/vreModelerDBInitializer b/etc/hsqldb/vreModelerDBInitializer index 24d5ef0..8bb35ea 100644 --- a/etc/hsqldb/vreModelerDBInitializer +++ b/etc/hsqldb/vreModelerDBInitializer @@ -1,14 +1,11 @@ CREATE CACHED TABLE COLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,MEMBERS VARCHAR,CREATION VARCHAR,LASTUPDATE VARCHAR) CREATE CACHED TABLE GHN(ID VARCHAR NOT NULL PRIMARY KEY,HOST VARCHAR,SECURITY VARCHAR,UPTIME VARCHAR,MAINMEMORYVA VARCHAR,MAINMEMORYVS VARCHAR,LOCALAS VARCHAR,LOCATION VARCHAR,COUNTRY VARCHAR,DOMAIN VARCHAR, ISONCLOUD BOOLEAN) -CREATE CACHED TABLE MCOLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,RELATEDCOLLECTIONID VARCHAR NOT NULL,CONSTRAINT SYS_FK_50 FOREIGN KEY(RELATEDCOLLECTIONID) REFERENCES COLLECTION(ID)) CREATE CACHED TABLE VRE(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,DESCRIPTION VARCHAR NOT NULL,VREDESIGNER VARCHAR NOT NULL,VREMANAGER VARCHAR NOT NULL,INTERVALFROM DATE,INTERVALTO DATE,STATUS VARCHAR) CREATE CACHED TABLE CS(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,DESCRIPTION VARCHAR NOT NULL) CREATE CACHED TABLE RUNNINGINSTANCE(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL, CLASS VARCHAR NOT NULL) CREATE CACHED TABLE GHNRELATEDRI(GHNID VARCHAR NOT NULL,RIID VARCHAR NOT NULL,PRIMARY KEY(GHNID,RIID)) CREATE CACHED TABLE RIRELATEDPKG(RIID VARCHAR NOT NULL,PKGID INTEGER NOT NULL,PRIMARY KEY(RIID,PKGID)) CREATE CACHED TABLE FUNCTIONALITY(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,DESCRIPTION VARCHAR NOT NULL,FATHER INTEGER,FLAG INTEGER NOT NULL) -CREATE CACHED TABLE METADATAFORMAT(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,SCHEMAURI VARCHAR NOT NULL,LANGUAGE VARCHAR NOT NULL) -CREATE CACHED TABLE NATIVEMDF(MDCOLLID VARCHAR NOT NULL,MDFID VARCHAR NOT NULL,PRIMARY KEY(MDCOLLID,MDFID),CONSTRAINT SYS_FK_178 FOREIGN KEY(MDCOLLID) REFERENCES MCOLLECTION(ID),CONSTRAINT SYS_FK_179 FOREIGN KEY(MDFID) REFERENCES METADATAFORMAT(ID)) CREATE CACHED TABLE VRERELATEDCOLLECTION(VREID VARCHAR NOT NULL,COLLID VARCHAR NOT NULL,PRIMARY KEY(VREID,COLLID)) CREATE CACHED TABLE VRERELATEDGHN(VREID VARCHAR NOT NULL,GHNID VARCHAR NOT NULL, ISCANDIDATE BOOLEAN,PRIMARY KEY(VREID,GHNID)) CREATE CACHED TABLE VRERELATEDCS(VREID VARCHAR NOT NULL,CSID VARCHAR NOT NULL,PRIMARY KEY(VREID,CSID)) diff --git a/schema/ModelerService.wsdl b/schema/ModelerService.wsdl index 4c918f3..8558468 100644 --- a/schema/ModelerService.wsdl +++ b/schema/ModelerService.wsdl @@ -75,11 +75,6 @@ - - - - - @@ -201,21 +196,7 @@ - - - - - - - - - - - - - - - + @@ -346,16 +327,6 @@ - - - - - - - - - - diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java index 8e2af10..fb46741 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java @@ -6,7 +6,7 @@ import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; -import org.gcube.common.core.resources.GCUBECollection; +import org.gcube.common.core.resources.GCUBEGenericResource; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; @@ -16,10 +16,11 @@ public class CollectionConsumer extends BaseNotificationConsumer{ private GCUBELog logger= new GCUBELog(GHNConsumer.class); - public static final GCUBENotificationTopic collectionTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","Collection")); + public static final GCUBENotificationTopic collectionTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry",GCUBEGenericResource.TYPE)); static{ collectionTopic.setUseRenotifier(false); + collectionTopic.setPrecondition("//profile[contains(.,'GCUBECollection') and contains(.,'true')]"); } private GCUBEScope scope; @@ -38,7 +39,7 @@ public class CollectionConsumer extends BaseNotificationConsumer{ if (operation.compareTo("create")==0){ logger.trace("adding a new Collection in DB"); - GCUBECollection collection= GHNContext.getImplementation(GCUBECollection.class); + GCUBEGenericResource collection= GHNContext.getImplementation(GCUBEGenericResource.class); String profile=event.getPayload().getMessage()[0].getChildNodes().item(1).getChildNodes().item(0).getNodeValue(); collection.load(new StringReader(profile)); new CollectionHandler().add(collection); diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java deleted file mode 100644 index 0bc04b9..0000000 --- a/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.gcube.vremanagement.vremodeler.consumers; - -import java.io.StringReader; - -import javax.xml.namespace.QName; - -import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; -import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; -import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; -import org.gcube.common.core.resources.GCUBEMCollection; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.vremanagement.vremodeler.impl.ServiceContext; -import org.gcube.vremanagement.vremodeler.resources.handlers.MCollectionHandler; - -public class MCollectionConsumer extends BaseNotificationConsumer{ - - public static final GCUBENotificationTopic mCollectionTopic=new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","MetadataCollection")); - - static{ - mCollectionTopic.setUseRenotifier(false); - } - - private GCUBELog logger= new GCUBELog(MCollectionConsumer.class); - - private GCUBEScope scope; - - public MCollectionConsumer(GCUBEScope scope){ - super(); - this.scope=scope; - } - - public void onNotificationReceived(NotificationEvent event){ - try{ - //logger.trace("notification received"); - ServiceContext.getContext().setScope(this.scope); - String id= event.getPayload().getMessage()[0].getChildNodes().item(0).getChildNodes().item(0).getNodeValue(); - String operation=event.getPayload().getMessage()[0].getChildNodes().item(2).getChildNodes().item(0).getNodeValue(); - if (operation.compareTo("create")==0){ - logger.trace("adding a new MCollection in DB"); - String profile=event.getPayload().getMessage()[0].getChildNodes().item(1).getChildNodes().item(0).getNodeValue(); - GCUBEMCollection mCollection= GHNContext.getImplementation(GCUBEMCollection.class); - mCollection.load(new StringReader(profile)); - new MCollectionHandler(mCollection.getRelCollection().getCollectionID()).add(mCollection); - } else if (operation.compareTo("destroy")==0){ - logger.trace("removing a MCollection from DB"); - new MCollectionHandler(null).drop(id); - } - - }catch(Exception e){logger.error("error in notification received",e);} - - } - -} diff --git a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java index b9e5cae..f6ccb98 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java @@ -13,9 +13,6 @@ import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandle import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler; import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler; import org.gcube.vremanagement.vremodeler.resources.handlers.GhnRiRelationHandler; -import org.gcube.vremanagement.vremodeler.resources.handlers.MCollectionHandler; -import org.gcube.vremanagement.vremodeler.resources.handlers.MetadataFormatHandler; -import org.gcube.vremanagement.vremodeler.resources.handlers.NativeMetadataFormatHandler; import org.gcube.vremanagement.vremodeler.resources.handlers.RunningInstancesHandler; @@ -68,10 +65,9 @@ public class IStoDBUtil { //DBInterface.deleteAll("VRERELATEDFUNCT"); //DBInterface.deleteAll("VRERELATEDGHN"); //DBInterface.deleteAll("VRE"); - DBInterface.deleteAll(NativeMetadataFormatHandler.tableName); + //DBInterface.deleteAll(NativeMetadataFormatHandler.tableName); //DBInterface.deleteAll("derivablemdf"); - DBInterface.deleteAll(MetadataFormatHandler.tableName); - DBInterface.deleteAll(MCollectionHandler.tableName); + //DBInterface.deleteAll(MetadataFormatHandler.tableName); DBInterface.deleteAll(CollectionHandler.tableName); //DBInterface.deleteAll("relatedserviceid"); DBInterface.deleteAll(GHNHandler.tableName); diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java b/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java index 1d520a1..c27cb4b 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java @@ -1,21 +1,16 @@ package org.gcube.vremanagement.vremodeler.impl; -import java.net.URI; import java.rmi.RemoteException; import java.sql.Date; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.faults.GCUBEUnrecoverableFault; import org.gcube.common.core.types.VOID; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.impl.deploy.DeployVRE; -import org.gcube.vremanagement.vremodeler.impl.util.ModelerCollection; import org.gcube.vremanagement.vremodeler.impl.util.Util; -import org.gcube.vremanagement.vremodeler.resources.MetadataFormat; import org.gcube.vremanagement.vremodeler.stubs.CollectionArray; import org.gcube.vremanagement.vremodeler.stubs.CollectionList; import org.gcube.vremanagement.vremodeler.stubs.CollectionType; @@ -25,8 +20,6 @@ import org.gcube.vremanagement.vremodeler.stubs.FunctionalityList; import org.gcube.vremanagement.vremodeler.stubs.GHNArray; import org.gcube.vremanagement.vremodeler.stubs.GHNList; import org.gcube.vremanagement.vremodeler.stubs.GHNType; -import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatResponse; -import org.gcube.vremanagement.vremodeler.stubs.SetMDFormatArgs; import org.gcube.vremanagement.vremodeler.stubs.Utils; import org.gcube.vremanagement.vremodeler.stubs.VREDescription; import org.gcube.vremanagement.vremodeler.stubs.deployreport.State; @@ -174,10 +167,9 @@ public class ModelerService { ResultSet resRelated= DBInterface.queryDB("select collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+getResource().getId()+"';"); - while(resRelated.next()){ + while(resRelated.next()) relatedCollection.add(resRelated.getString(1)); - } - + }catch(Exception e) { logger.error("error getting collections",e); throw new GCUBEFault(e);} @@ -223,102 +215,6 @@ public class ModelerService { } - /** - * Return the possibles metadata format for selected collection - * - * @param request void - * @return a list of MetadataFormat - * @throws GCUBEFault - - */ - public MetadataFormatResponse getMetadataRelatedToCollection(VOID var) throws GCUBEFault { - - Hashtable> nativeMetadataFormat; - Hashtable> selectedMetadataFormat; - - try{ - DBInterface.connect(); - - //retrieve all possible metadataformat for the selected collection - nativeMetadataFormat= new Hashtable>(); - ResultSet allPossibleMDF= DBInterface.queryDB("select rel.collid, mdf.id, mdf.name, mdf.schemauri, mdf.language, coll.name, coll.description from COLLECTION as coll, VRERELATEDCOLLECTION as rel, MCOLLECTION as mcoll, METADATAFORMAT as mdf, NATIVEMDF as native where rel.vreid='"+getResource().getId()+"' and mcoll.relatedcollectionid=rel.collid and mdf.id=native.mdfid and native.mdcollid=mcoll.id and coll.id=rel.collid;"); - while (allPossibleMDF.next()){ - ModelerCollection collection= new ModelerCollection(allPossibleMDF.getString(1), allPossibleMDF.getString(7), allPossibleMDF.getString(6) ); - MetadataFormat mf= new MetadataFormat(allPossibleMDF.getString(2), allPossibleMDF.getString(3), new URI(allPossibleMDF.getString(4)), allPossibleMDF.getString(5)); - if (nativeMetadataFormat.containsKey(collection)){ - nativeMetadataFormat.get(collection).add(mf); - }else { - ArrayList keyList=new ArrayList(); - keyList.add(mf); - nativeMetadataFormat.put(collection, keyList); - } - } - - //retrieving selected metadaformat - //hashtable - selectedMetadataFormat= new Hashtable>(); - ResultSet selectedFormat= DBInterface.queryDB("select rel.collid, mf.id, mf.name, mf.schemauri, mf.language , coll.name, coll.description from COLLECTION as coll, VRERELATEDMETADATAFORMAT as rel, METADATAFORMAT as mf where mf.id=rel.mfid and rel.vreid='"+getResource().getId()+"' and coll.id=rel.collid;"); - while (selectedFormat.next()){ - ModelerCollection collection= new ModelerCollection(selectedFormat.getString(1), selectedFormat.getString(7), selectedFormat.getString(6)); - MetadataFormat mf= new MetadataFormat(selectedFormat.getString(2),selectedFormat.getString(3), new URI(selectedFormat.getString(4)), selectedFormat.getString(5)); - - if (selectedMetadataFormat.containsKey(collection)) - selectedMetadataFormat.get(collection).add(mf); - else { - ArrayList keyList=new ArrayList(); - keyList.add(mf); - selectedMetadataFormat.put(collection, keyList); - } - } - - - }catch(Exception e) { - logger.error("getMEtadataRelatedToCollection Error ",e); - throw new GCUBEFault(e); - } - - - return Util.prepareMCFormat( nativeMetadataFormat ,selectedMetadataFormat); - } - - - /** - * - * Sets selected Metadata Format - * - * @param request - * @return void - * @throws GCUBEFault - - */ - public void setMetadataRelatedToCollection(SetMDFormatArgs request) throws GCUBEFault { - try{ - DBInterface.ExecuteUpdate("DELETE FROM VRERELATEDMETADATAFORMAT WHERE VRERELATEDMETADATAFORMAT.vreid='"+getResource().getId()+"';"); - //String[] singleElement; - String key=(String) getResource().getId(); - - //logger.debug(request.getCollectionIDArray().length+" "+request.getMdFormatIDArray().length+" "+request.getCheckedArray().length+" "+request.getCheckedArray(0).getCheckedRowElement().length); - ArrayList values= new ArrayList(request.getCollectionIDArray().length); - ArrayList row=null; - for (int i=0; i(3); - row.add(key); - row.add(request.getCollectionIDArray(i)); - row.add(request.getMdFormatIDArray(j)); - values.add(row.toArray(new String[3])); - } - } - - DBInterface.insertInto("VRERELATEDMETADATAFORMAT", values.toArray(new String[0][0])); - }catch(Exception e){ - logger.error("setMetadataRelateToCollection failed ",e); - throw new GCUBEFault(e); - - } - } - - /** * Return an xml with the selectable functionalities * String diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java index 5853e2b..6141213 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java @@ -12,7 +12,6 @@ import org.gcube.common.core.scope.GCUBEScope; import org.gcube.vremanagement.vremodeler.consumers.CollectionConsumer; import org.gcube.vremanagement.vremodeler.consumers.GHNConsumer; import org.gcube.vremanagement.vremodeler.consumers.GenericResourceConsumer; -import org.gcube.vremanagement.vremodeler.consumers.MCollectionConsumer; import org.gcube.vremanagement.vremodeler.consumers.RunningInstanceConsumer; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.db.IStoDBUtil; @@ -92,10 +91,6 @@ public class ServiceContext extends GCUBEServiceContext{ qnameList= new ArrayList(); qnameList.add(CollectionConsumer.collectionTopic); notifier.registerToISNotification(new CollectionConsumer(scope), qnameList, this, scope); - //MCollectionNotification - qnameList= new ArrayList(); - qnameList.add(MCollectionConsumer.mCollectionTopic); - notifier.registerToISNotification(new MCollectionConsumer(scope), qnameList, this, scope); //FunctionalityResource qnameList= new ArrayList(); qnameList.add(GenericResourceConsumer.functionalityTopic); @@ -108,7 +103,6 @@ public class ServiceContext extends GCUBEServiceContext{ topicToRemove.add(GHNConsumer.ghnTopic); topicToRemove.add(RunningInstanceConsumer.riTopic); topicToRemove.add(CollectionConsumer.collectionTopic); - topicToRemove.add(MCollectionConsumer.mCollectionTopic); topicToRemove.add(GenericResourceConsumer.functionalityTopic); } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java b/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java index ee906e5..9ea5deb 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java @@ -6,7 +6,6 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; -import java.util.Hashtable; import java.util.List; import javax.xml.transform.OutputKeys; @@ -29,17 +28,12 @@ import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.service.Res import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.impl.ModelerService; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; -import org.gcube.vremanagement.vremodeler.resources.MetadataFormat; import org.gcube.vremanagement.vremodeler.stubs.CollectionType; import org.gcube.vremanagement.vremodeler.stubs.CollectionTypeInfo; import org.gcube.vremanagement.vremodeler.stubs.FunctionalityItem; import org.gcube.vremanagement.vremodeler.stubs.GHNType; import org.gcube.vremanagement.vremodeler.stubs.GHNTypeMemory; import org.gcube.vremanagement.vremodeler.stubs.GHNTypeSite; -import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatCollectionRelation; -import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatItem; -import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatRelation; -import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatResponse; import org.gcube.vremanagement.vremodeler.stubs.Report; import org.gcube.vremanagement.vremodeler.stubs.RunningInstance; import org.gcube.vremanagement.vremodeler.stubs.VREDescription; @@ -135,47 +129,6 @@ public class Util { return tmpList; } - /** - * - * @param res - * @return - */ - public static MetadataFormatResponse prepareMCFormat(Hashtable> nativeMetadataFormat, Hashtable> selectedMetadataFormat){ - - List mdflistMultiple= new ArrayList(); - for (List mftmpList: nativeMetadataFormat.values()) - mdflistMultiple.addAll(mftmpList); - List totalMDF= getDistinctObjects(mdflistMultiple); - - List metadataFormatItemList= new ArrayList(); - List metadataFormatRelationList= new ArrayList(); - - try{ - - for (MetadataFormat mf: totalMDF) - metadataFormatItemList.add(new MetadataFormatItem( mf.getId(),mf.getLanguage(),mf.getName(),mf.getSchemaURI().toString())); - - //setting the native MDF - for(ModelerCollection key: nativeMetadataFormat.keySet()){ - MetadataFormatCollectionRelation mfCollectionRelation= new MetadataFormatCollectionRelation(); - mfCollectionRelation.setCollId(key.getId()); - mfCollectionRelation.setDescription(key.getDescription()); - mfCollectionRelation.setName(key.getName()); - - List mfList= new ArrayList(); - for(MetadataFormat mf: nativeMetadataFormat.get(key)) - if(selectedMetadataFormat.isEmpty() || ((selectedMetadataFormat.get(key)!=null) && selectedMetadataFormat.get(key).contains(mf))) - mfList.add(new MetadataFormatRelation(mf.getId(),true, true)); - else mfList.add(new MetadataFormatRelation(mf.getId(),true, false)); - - mfCollectionRelation.setMfList(mfList.toArray(new MetadataFormatRelation[mfList.size()])); - metadataFormatRelationList.add(mfCollectionRelation); - } - }catch(Exception e){ - logger.warn("error getting metadataFormats",e); - } - return new MetadataFormatResponse(metadataFormatRelationList.toArray(new MetadataFormatCollectionRelation[metadataFormatRelationList.size()]),metadataFormatItemList.toArray(new MetadataFormatItem[metadataFormatItemList.size()])); - } /** * diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/CollectionHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/CollectionHandler.java index 560f9dc..df069bd 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/CollectionHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/handlers/CollectionHandler.java @@ -1,23 +1,24 @@ package org.gcube.vremanagement.vremodeler.resources.handlers; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; 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.GCUBECollectionQuery; -import org.gcube.common.core.resources.GCUBECollection; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery; +import org.gcube.common.core.resources.GCUBEGenericResource; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; -public class CollectionHandler implements ResourceHandler { +public class CollectionHandler implements ResourceHandler { private static GCUBELog logger = new GCUBELog(CollectionHandler.class); public static final String tableName="COLLECTION"; - public void add(GCUBECollection resource) throws Exception { + public void add(GCUBEGenericResource resource) throws Exception { this.insert(resource); } @@ -30,29 +31,27 @@ public class CollectionHandler implements ResourceHandler { public void initialize() throws Exception { ISClient client= GHNContext.getImplementation(ISClient.class); - GCUBECollectionQuery query=client.getQuery(GCUBECollectionQuery.class); - query.addAtomicConditions(new AtomicCondition("/Profile/IsUserCollection/@value","true")); - List collectionList= client.execute(query, ServiceContext.getContext().getScope()); - for (GCUBECollection collection:collectionList) + //TODO: change when the new CM will return to GCUBECollection + GCUBEGenericResourceQuery query=client.getQuery(GCUBEGenericResourceQuery.class); + query.addAtomicConditions(new AtomicCondition("/Profile/Body/CollectionInfo/user","true"), new AtomicCondition("/Profile/SecondaryType", "GCUBECollection")); + List collectionList= client.execute(query, ServiceContext.getContext().getScope()); + for (GCUBEGenericResource collection:collectionList) try{ insert(collection); }catch(Exception e){logger.error("error inserting values in "+tableName, e);} } - private void insert(GCUBECollection collection) throws Exception { - if (!collection.isUserCollection()) return; + private void insert(GCUBEGenericResource collection) throws Exception { ArrayList row= new ArrayList(6); row.add(collection.getID()); row.add(collection.getName()); row.add(collection.getDescription()==null? "not provided" : collection.getDescription()); - row.add(collection.getNumberOfMembers()+""); - row.add(collection.getCreationTime().getTime().getTime()+""); - row.add(collection.getLastUpdateTime().getTime().getTime()+""); + row.add("-1"); + row.add(System.currentTimeMillis()+""); + row.add(System.currentTimeMillis()+""); DBInterface.connect(); DBInterface.insertInto(tableName, row.toArray(new String[6])); - MCollectionHandler mcollHandler= new MCollectionHandler(collection.getID()); - mcollHandler.initialize(); } } diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java index 3723573..2664811 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java @@ -1,11 +1,8 @@ package org.gcube.vremanagement.vremodeler.resources.handlers; -import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; - import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.contexts.GHNContext.Status; import org.gcube.common.core.informationsystem.client.AtomicCondition; import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery; diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/MCollectionHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/MCollectionHandler.java deleted file mode 100644 index a2617c4..0000000 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/MCollectionHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.gcube.vremanagement.vremodeler.resources.handlers; - -import java.util.ArrayList; -import java.util.List; - -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.GCUBEMCollectionQuery; -import org.gcube.common.core.resources.GCUBEMCollection; -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.vremanagement.vremodeler.db.DBInterface; -import org.gcube.vremanagement.vremodeler.impl.ServiceContext; -import org.gcube.vremanagement.vremodeler.resources.MetadataFormat; - -public class MCollectionHandler implements ResourceHandler { - - - private static GCUBELog logger= new GCUBELog(MCollectionHandler.class); - - public static final String tableName="MCOLLECTION"; - - private String relatedCollectionId; - - public MCollectionHandler(String relatedCollectionId){ - this.relatedCollectionId= relatedCollectionId; - } - - - public void add(GCUBEMCollection resource) throws Exception { - this.insert(resource); - } - - public void drop(String resourceId) throws Exception { - DBInterface.deleteElement(tableName, "ID='"+resourceId+"'"); - } - - public void initialize() throws Exception { - ISClient client= GHNContext.getImplementation(ISClient.class); - GCUBEMCollectionQuery queryMColl= client.getQuery(GCUBEMCollectionQuery.class); - queryMColl.addAtomicConditions(new AtomicCondition("/Profile/RelatedCollection/CollectionID",this.relatedCollectionId)); - List mcollList= client.execute(queryMColl, ServiceContext.getContext().getScope()); - for (GCUBEMCollection mcoll: mcollList) - try{ - insert(mcoll); - }catch(Exception e){logger.error("error inserting values in "+tableName, e);} - } - - private void insert(GCUBEMCollection mcollection) throws Exception { - List row= new ArrayList(4); - row.add(mcollection.getID()); - row.add(mcollection.getName()); - row.add(mcollection.getDescription()); - row.add(mcollection.getRelCollection().getCollectionID()); - DBInterface.connect(); - DBInterface.insertInto(tableName, row.toArray(new String[4])); - new MetadataFormatHandler(mcollection.getID()).add(new MetadataFormat(mcollection.getMetaFormat().getName(), mcollection.getMetaFormat().getSchemaURI(), mcollection.getMetaFormat().getLanguage())); - } - -} diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/MetadataFormatHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/MetadataFormatHandler.java deleted file mode 100644 index e01c746..0000000 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/MetadataFormatHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.gcube.vremanagement.vremodeler.resources.handlers; - -import java.sql.ResultSet; - -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.vremanagement.vremodeler.db.DBInterface; -import org.gcube.vremanagement.vremodeler.resources.MFRelationNative; -import org.gcube.vremanagement.vremodeler.resources.MetadataFormat; - -public class MetadataFormatHandler implements ResourceHandler { - - private static GCUBELog logger= new GCUBELog(MetadataFormatHandler.class); - - private static final String nameFieldDb="NAME"; - private static final String schemaFieldDb="SCHEMAURI"; - private static final String languageFieldDb="LANGUAGE"; - - public static final String tableName="METADATAFORMAT"; - - private String relatedMCollectionID; - - public MetadataFormatHandler(String relatedMCollectionId){ - this.relatedMCollectionID= relatedMCollectionId; - } - - public void add(MetadataFormat resource) throws Exception { - String id; - if ((id=exists(resource))!=null){ - new NativeMetadataFormatHandler().add(new MFRelationNative(this.relatedMCollectionID, id)); - }else{ - DBInterface.connect(); - DBInterface.insertIntoListable(tableName, resource); - new NativeMetadataFormatHandler().add(new MFRelationNative(this.relatedMCollectionID, resource.getId())); - } - } - - public void drop(String resourceId) throws Exception { - // TODO Auto-generated method stub - } - - public void initialize() throws Exception {} - - - /** - * this method returns the id of the MetadataFormat if this metadataFormat exists, null otherwise - */ - private static String exists(MetadataFormat metadataFormat) throws Exception{ - DBInterface.connect(); - ResultSet result; - if (metadataFormat.getLanguage().compareTo(MetadataFormat.ANY_LANGUAGE)==0){ - result=DBInterface.queryDB("SELECT ID from "+tableName+" WHERE "+nameFieldDb+"='"+metadataFormat.getName()+"' AND "+schemaFieldDb+"='"+metadataFormat.getSchemaURI()+"'"); - }else - result=DBInterface.queryDB("SELECT ID from "+tableName+" WHERE "+nameFieldDb+"='"+metadataFormat.getName()+"' AND "+schemaFieldDb+"='"+metadataFormat.getSchemaURI()+"' AND ("+languageFieldDb+"='"+MetadataFormat.ANY_LANGUAGE+"' OR "+languageFieldDb+"='"+metadataFormat.getLanguage()+"')"); - if (result.next()) { - logger.trace("the metadataFormat already exists"); - return result.getString(1); - }else return null; - } - -} diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java deleted file mode 100644 index 6693b8f..0000000 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.gcube.vremanagement.vremodeler.resources.handlers; - -//import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.vremanagement.vremodeler.db.DBInterface; -import org.gcube.vremanagement.vremodeler.resources.MFRelationNative; - -public class NativeMetadataFormatHandler implements ResourceHandler { - - //private static GCUBELog logger= new GCUBELog(NativeMetadataFormatHandler.class); - public static final String tableName="NATIVEMDF"; - - - public void add(MFRelationNative resource) throws Exception { - DBInterface.connect(); - DBInterface.insertIntoListable(tableName, resource); - } - - public void drop(String resourceId) throws Exception { - // TODO Auto-generated method stub - } - - public void initialize() throws Exception {} - -}