vre-modeler/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java

53 lines
2.2 KiB
Java
Raw Normal View History

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.GCUBEMCollectionQuery;
import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer;
import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent;
import org.gcube.common.core.resources.GCUBEMCollection;
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.MCollectionHandler;
public class MCollectionConsumer extends BaseNotificationConsumer{
public static final QName mCollectionQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","MetadataCollection");
private GCUBELog logger= new GCUBELog(MCollectionConsumer.class);
private GCUBEScope scope;
public MCollectionConsumer(GCUBEScope scope){
super();
this.scope=scope;
}
public void onNotificationReceived(NotificationEvent event){
try{
//logger.trace("notification 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 MCollection in DB");
ISClient client=GHNContext.getImplementation(ISClient.class);
GCUBEMCollectionQuery query= client.getQuery(GCUBEMCollectionQuery.class);
query.addAtomicConditions(new AtomicCondition("/ID",id));
GCUBEMCollection mColl= client.execute(query, this.scope).get(0);
Thread.sleep(60000);
new MCollectionHandler(mColl.getRelCollection().getCollectionID()).add(mColl);
} else if (operation.compareTo("remove")==0){
logger.trace("removing a GHN from DB");
}
}catch(Exception e){logger.error("error in notification received",e);}
}
}