57 lines
2.2 KiB
Java
57 lines
2.2 KiB
Java
|
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.GCUBECollectionQuery;
|
||
|
import org.gcube.common.core.resources.GCUBECollection;
|
||
|
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<GCUBECollection> {
|
||
|
|
||
|
private static GCUBELog logger = new GCUBELog(CollectionHandler.class);
|
||
|
|
||
|
public static final String tableName="COLLECTION";
|
||
|
|
||
|
public void add(GCUBECollection resource) throws Exception {
|
||
|
this.insert(resource);
|
||
|
|
||
|
}
|
||
|
|
||
|
public void drop(GCUBECollection resource) throws Exception {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
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<GCUBECollection> collectionList= client.execute(client.getQuery(GCUBECollectionQuery.class), ServiceContext.getContext().getScope());
|
||
|
for (GCUBECollection collection:collectionList)
|
||
|
try{
|
||
|
insert(collection);
|
||
|
}catch(Exception e){logger.error("error insertin values in "+tableName, e);}
|
||
|
}
|
||
|
|
||
|
|
||
|
private void insert(GCUBECollection collection) throws Exception {
|
||
|
ArrayList<String> row= new ArrayList<String>(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()+"");
|
||
|
DBInterface.connect();
|
||
|
DBInterface.insertInto(tableName, row.toArray(new String[6]));
|
||
|
MCollectionHandler mcollHandler= new MCollectionHandler(collection.getID());
|
||
|
mcollHandler.initialize();
|
||
|
}
|
||
|
|
||
|
}
|