2009-09-30 11:29:45 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.consumers;
|
|
|
|
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
|
|
|
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.GCUBEGHNQuery;
|
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer;
|
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent;
|
|
|
|
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.GHNHandler;
|
|
|
|
|
|
|
|
|
|
|
|
public class GHNConsumer extends BaseNotificationConsumer{
|
|
|
|
|
|
|
|
private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
|
|
|
|
|
|
|
public static final QName ghnQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","GHN");
|
|
|
|
|
|
|
|
private GCUBEScope scope;
|
|
|
|
|
|
|
|
public GHNConsumer(GCUBEScope scope){
|
|
|
|
super();
|
|
|
|
this.scope=scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onNotificationReceived(NotificationEvent event){
|
|
|
|
try{
|
|
|
|
logger.trace("notificetion 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(1).getChildNodes().item(0).getNodeValue();
|
|
|
|
if (operation.compareTo("create")==0){
|
|
|
|
logger.trace("adding a new GHN in DB");
|
|
|
|
ISClient client=GHNContext.getImplementation(ISClient.class);
|
|
|
|
GCUBEGHNQuery query= client.getQuery(GCUBEGHNQuery.class);
|
|
|
|
query.addAtomicConditions(new AtomicCondition("/ID",id));
|
|
|
|
Thread.sleep(60000);
|
|
|
|
new GHNHandler().add(client.execute(query, this.scope).get(0));
|
2009-11-27 17:20:12 +01:00
|
|
|
} else if (operation.compareTo("destroy")==0){
|
2009-09-30 11:29:45 +02:00
|
|
|
logger.trace("removing a GHN from DB");
|
2009-11-27 17:20:12 +01:00
|
|
|
new GHNHandler().drop(id);
|
2009-09-30 11:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}catch(Exception e){logger.error("error in notification received",e);}
|
|
|
|
}
|
|
|
|
}
|