2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
2009-07-06 19:36:03 +02:00
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
import java.util.ArrayList;
|
2009-11-27 17:20:12 +01:00
|
|
|
import java.util.Collections;
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.common.core.contexts.GHNContext;
|
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
|
|
|
|
import org.gcube.common.core.scope.GCUBEScope;
|
|
|
|
import org.gcube.common.core.security.GCUBESecurityManager;
|
|
|
|
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
|
|
|
|
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.CollectionConsumer;
|
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.GHNConsumer;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.GenericResourceConsumer;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.MCollectionConsumer;
|
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.RunningInstanceConsumer;
|
2008-10-21 19:09:24 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
public class ServiceContext extends GCUBEServiceContext{
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
/** Single context instance, created eagerly */
|
|
|
|
private static ServiceContext cache = new ServiceContext();
|
|
|
|
|
|
|
|
/** Returns cached instance */
|
|
|
|
public static ServiceContext getContext() {return cache;}
|
|
|
|
|
|
|
|
/** Prevents accidental creation of more instances */
|
|
|
|
private ServiceContext(){};
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
2008-10-30 19:54:34 +01:00
|
|
|
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
|
2008-04-22 15:04:13 +02:00
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
private ArrayList<String> secondaryTypeGenericResourceRequired= new ArrayList<String>();
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
protected void onReady() throws Exception{
|
2009-04-01 01:05:14 +02:00
|
|
|
try{
|
2009-02-10 19:54:48 +01:00
|
|
|
logger.info("ready event invoked on " + this.getName());
|
2009-02-13 20:04:00 +01:00
|
|
|
this.intializeDB();
|
2009-02-10 19:54:48 +01:00
|
|
|
}catch (Exception e){
|
2009-10-01 16:59:26 +02:00
|
|
|
logger.error("error initializing VREModeler",e);
|
2009-05-08 19:58:31 +02:00
|
|
|
this.setStatus(Status.FAILED);
|
2009-02-10 19:54:48 +01:00
|
|
|
throw e;
|
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:04:00 +01:00
|
|
|
protected void intializeDB() throws Exception{
|
2009-09-30 11:29:45 +02:00
|
|
|
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
|
2009-10-01 16:59:26 +02:00
|
|
|
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){
|
2009-09-30 11:29:45 +02:00
|
|
|
ServiceContext.getContext().setScope(scope);
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2009-12-21 16:28:25 +01:00
|
|
|
ArrayList<String> genResList= new ArrayList<String>();
|
|
|
|
for (String gen:((String)this.getProperty("GenericResourceToAdd", true)).split(","))
|
|
|
|
genResList.add(gen.trim());
|
|
|
|
this.setSecondaryTypeGenericResourceRequired(genResList.toArray(new String[0]));
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2009-12-21 16:28:25 +01:00
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
GCUBESecurityManager secMan= new GCUBESecurityManagerImpl(){
|
|
|
|
@Override
|
|
|
|
public boolean isSecurityEnabled() {
|
|
|
|
return false;
|
|
|
|
}};
|
|
|
|
|
|
|
|
IStoDBUtil.initDB(scope);
|
|
|
|
new GHNHandler().initialize();
|
|
|
|
new CollectionHandler().initialize();
|
|
|
|
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
|
|
|
functionalityHandler.initialize();
|
2009-11-27 17:20:12 +01:00
|
|
|
new GenericResourceHandler().initialize();
|
2009-09-30 11:29:45 +02:00
|
|
|
logger.debug("Service initialized!!");
|
|
|
|
|
|
|
|
//GHNNotification
|
|
|
|
ArrayList<QName> qnameList= new ArrayList<QName>();
|
|
|
|
qnameList.add(GHNConsumer.ghnQName);
|
|
|
|
notifier.registerToISNotification(qnameList, new GHNConsumer(scope), secMan, scope);
|
|
|
|
//RINotification
|
|
|
|
qnameList= new ArrayList<QName>();
|
|
|
|
qnameList.add(RunningInstanceConsumer.riQName);
|
|
|
|
notifier.registerToISNotification(qnameList, new RunningInstanceConsumer(scope), secMan, scope);
|
|
|
|
//CollectionNotification
|
|
|
|
qnameList= new ArrayList<QName>();
|
|
|
|
qnameList.add(CollectionConsumer.collectionQName);
|
|
|
|
notifier.registerToISNotification(qnameList, new CollectionConsumer(scope), secMan, scope);
|
|
|
|
//MCollectionNotification
|
|
|
|
qnameList= new ArrayList<QName>();
|
|
|
|
qnameList.add(MCollectionConsumer.mCollectionQName);
|
|
|
|
notifier.registerToISNotification(qnameList, new MCollectionConsumer(scope), secMan, scope);
|
|
|
|
//FunctionalityResource
|
|
|
|
qnameList= new ArrayList<QName>();
|
2009-11-27 17:20:12 +01:00
|
|
|
qnameList.add(GenericResourceConsumer.functionalityQName);
|
|
|
|
notifier.registerToISNotification(qnameList, new GenericResourceConsumer(scope,functionalityHandler.getFunctionalityResourceId()), secMan, scope);
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
logger.debug("consumers registered");
|
|
|
|
}
|
2009-02-13 20:04:00 +01:00
|
|
|
}
|
2009-11-27 17:20:12 +01:00
|
|
|
|
|
|
|
public ArrayList<String> getSecondaryTypeGenericResourceRequired() {
|
|
|
|
return secondaryTypeGenericResourceRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSecondaryTypeGenericResourceRequired(
|
|
|
|
String[] secondaryTypeGenericResourceRequired) {
|
|
|
|
Collections.addAll(this.secondaryTypeGenericResourceRequired,secondaryTypeGenericResourceRequired);
|
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|