2009-09-30 11:29:45 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.consumers;
|
|
|
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
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;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.common.core.resources.GCUBEGenericResource;
|
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.FunctionalityHandler;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.kxml.KGCUBEGenericFunctionalityResource;
|
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
public class GenericResourceConsumer extends BaseNotificationConsumer{
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
public static final GCUBENotificationTopic functionalityTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","GenericResource"));
|
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
private String functionalityResourceId;
|
2009-09-30 11:29:45 +02:00
|
|
|
private GCUBEScope scope;
|
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
public GenericResourceConsumer(GCUBEScope scope, String resourceId){
|
2009-09-30 11:29:45 +02:00
|
|
|
super();
|
|
|
|
this.scope=scope;
|
2009-11-27 17:20:12 +01:00
|
|
|
this.functionalityResourceId= resourceId;
|
2009-09-30 11:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onNotificationReceived(NotificationEvent event){
|
|
|
|
try{
|
|
|
|
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 profile=event.getPayload().getMessage()[0].getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
|
|
|
|
String operation=event.getPayload().getMessage()[0].getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
|
|
|
|
|
2009-10-14 11:57:31 +02:00
|
|
|
logger.info("notification received for genericResource "+id+" and operation "+operation);
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2009-12-21 16:28:25 +01:00
|
|
|
if (id.compareTo(this.functionalityResourceId)==0 && (operation.compareTo("update")==0)){
|
2009-10-14 11:57:31 +02:00
|
|
|
logger.trace("notification received for functionalityResource with id "+id+" in scope "+scope.toString());
|
2009-09-30 11:29:45 +02:00
|
|
|
KGCUBEGenericFunctionalityResource resource= new KGCUBEGenericFunctionalityResource();
|
2010-05-13 18:20:41 +02:00
|
|
|
resource.load(new StringReader(profile));
|
2009-10-14 11:57:31 +02:00
|
|
|
//FunctionalityHandler
|
2009-09-30 11:29:45 +02:00
|
|
|
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
|
|
|
functionalityHandler.add(resource);
|
2009-11-27 17:20:12 +01:00
|
|
|
}else if (operation.compareTo("create")==0){
|
|
|
|
logger.trace("notification received for generic resource with operation create");
|
2009-12-21 16:28:25 +01:00
|
|
|
|
2010-05-13 18:20:41 +02:00
|
|
|
GCUBEGenericResource genericResource= GHNContext.getImplementation(GCUBEGenericResource.class);
|
|
|
|
genericResource.load(new StringReader(profile));
|
|
|
|
if (genericResource.getName().compareTo("FuctionalitiesResource")==0){
|
2009-12-21 16:28:25 +01:00
|
|
|
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
|
|
|
KGCUBEGenericFunctionalityResource functResource=new KGCUBEGenericFunctionalityResource();
|
2010-05-13 18:20:41 +02:00
|
|
|
functResource.load(new StringReader(profile));
|
2009-12-21 16:28:25 +01:00
|
|
|
functionalityHandler.add(functResource);
|
|
|
|
} else
|
2010-05-13 18:20:41 +02:00
|
|
|
if (ServiceContext.getContext().getSecondaryTypeGenericResourceRequired().contains(genericResource.getSecondaryType()))
|
|
|
|
new GenericResourceHandler().add(genericResource);
|
2009-11-27 17:20:12 +01:00
|
|
|
}else if (operation.compareTo("destroy")==0){
|
|
|
|
logger.trace("notification received for generic resource with operation destroy");
|
|
|
|
new GenericResourceHandler().drop(id);
|
2009-09-30 11:29:45 +02:00
|
|
|
}
|
|
|
|
|
2009-10-14 11:57:31 +02:00
|
|
|
}catch(Exception e){logger.error("error in functionality notification",e);}
|
2009-09-30 11:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|