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())); } }