2009-09-30 11:29:45 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.consumers;
|
|
|
|
|
2010-05-13 18:20:41 +02:00
|
|
|
import java.io.StringReader;
|
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
|
|
|
import org.gcube.common.core.contexts.GHNContext;
|
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer;
|
2010-11-03 19:32:06 +01:00
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent;
|
2010-05-13 18:20:41 +02:00
|
|
|
import org.gcube.common.core.resources.GCUBEHostingNode;
|
2009-09-30 11:29:45 +02:00
|
|
|
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{
|
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
public static GCUBENotificationTopic ghnTopic;
|
2009-09-30 11:29:45 +02:00
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
static{
|
|
|
|
ghnTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","GHN"));
|
|
|
|
ghnTopic.setPrecondition("(//operationType[text()='destroy']) or (//operationType[text()='create'])");
|
2010-11-09 19:58:58 +01:00
|
|
|
ghnTopic.setUseRenotifier(false);
|
2010-11-03 19:32:06 +01:00
|
|
|
}
|
2009-09-30 11:29:45 +02:00
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
private GCUBEScope scope;
|
|
|
|
|
|
|
|
public GHNConsumer(GCUBEScope scope){
|
|
|
|
super();
|
|
|
|
this.scope=scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onNotificationReceived(NotificationEvent event){
|
|
|
|
try{
|
2010-05-13 18:20:41 +02:00
|
|
|
logger.trace("notification received");
|
2009-09-30 11:29:45 +02:00
|
|
|
ServiceContext.getContext().setScope(this.scope);
|
|
|
|
String id= event.getPayload().getMessage()[0].getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
|
2010-05-13 18:20:41 +02:00
|
|
|
String operation=event.getPayload().getMessage()[0].getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
|
|
|
|
//logger.trace("received id: "+id+" op: "+operation+" profile: "+profile);
|
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
if (operation.compareTo("create")==0){
|
|
|
|
logger.trace("adding a new GHN in DB");
|
2010-05-13 18:20:41 +02:00
|
|
|
GCUBEHostingNode ghn= GHNContext.getImplementation(GCUBEHostingNode.class);
|
2010-11-09 19:58:58 +01:00
|
|
|
String profile=event.getPayload().getMessage()[0].getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
|
2010-05-13 18:20:41 +02:00
|
|
|
ghn.load(new StringReader(profile));
|
|
|
|
new GHNHandler().add(ghn);
|
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);}
|
|
|
|
}
|
|
|
|
}
|