2009-09-30 11:29:45 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.resources.handlers;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2011-05-06 12:36:42 +02:00
|
|
|
import java.util.Calendar;
|
2009-09-30 11:29:45 +02:00
|
|
|
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;
|
2011-05-06 12:36:42 +02:00
|
|
|
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
|
|
|
|
import org.gcube.common.core.resources.GCUBEGenericResource;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
|
|
|
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
|
|
|
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
|
|
|
|
2011-05-06 12:36:42 +02:00
|
|
|
public class CollectionHandler implements ResourceHandler<GCUBEGenericResource> {
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
private static GCUBELog logger = new GCUBELog(CollectionHandler.class);
|
|
|
|
|
|
|
|
public static final String tableName="COLLECTION";
|
|
|
|
|
2011-05-06 12:36:42 +02:00
|
|
|
public void add(GCUBEGenericResource resource) throws Exception {
|
2009-09-30 11:29:45 +02:00
|
|
|
this.insert(resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
public void drop(String collectionId) throws Exception {
|
|
|
|
DBInterface.connect();
|
|
|
|
DBInterface.deleteElement(tableName, "ID='"+collectionId+"'");
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initialize() throws Exception {
|
|
|
|
ISClient client= GHNContext.getImplementation(ISClient.class);
|
2011-05-06 12:36:42 +02:00
|
|
|
//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<GCUBEGenericResource> collectionList= client.execute(query, ServiceContext.getContext().getScope());
|
|
|
|
for (GCUBEGenericResource collection:collectionList)
|
2009-09-30 11:29:45 +02:00
|
|
|
try{
|
|
|
|
insert(collection);
|
2010-10-29 19:36:10 +02:00
|
|
|
}catch(Exception e){logger.error("error inserting values in "+tableName, e);}
|
2009-09-30 11:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-06 12:36:42 +02:00
|
|
|
private void insert(GCUBEGenericResource collection) throws Exception {
|
2009-09-30 11:29:45 +02:00
|
|
|
ArrayList<String> row= new ArrayList<String>(6);
|
|
|
|
row.add(collection.getID());
|
|
|
|
row.add(collection.getName());
|
|
|
|
row.add(collection.getDescription()==null? "not provided" : collection.getDescription());
|
2011-05-06 12:36:42 +02:00
|
|
|
row.add("-1");
|
|
|
|
row.add(System.currentTimeMillis()+"");
|
|
|
|
row.add(System.currentTimeMillis()+"");
|
2009-09-30 11:29:45 +02:00
|
|
|
DBInterface.connect();
|
|
|
|
DBInterface.insertInto(tableName, row.toArray(new String[6]));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|