2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.util.ArrayList;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.apache.axis.components.uuid.UUIDGen;
|
|
|
|
import org.apache.axis.components.uuid.UUIDGenFactory;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.apache.axis.message.addressing.EndpointReferenceType;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.gcube.common.core.faults.GCUBEFault;
|
2008-11-07 18:45:29 +01:00
|
|
|
import org.gcube.common.core.types.VOID;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
2008-04-22 16:07:12 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
2008-12-10 19:09:38 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.impl.util.XMLUtil;
|
2008-10-22 19:48:08 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.stubs.GetExistingNamesResponseMessage;
|
2009-01-14 12:11:12 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-08 19:58:31 +02:00
|
|
|
|
|
|
|
public class ModelFactoryService{
|
2008-04-22 14:11:53 +02:00
|
|
|
|
2010-01-29 17:42:06 +01:00
|
|
|
private GCUBELog logger = new GCUBELog(ModelFactoryService.class);
|
2008-04-22 15:04:13 +02:00
|
|
|
private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
|
|
|
|
|
|
|
|
protected ServiceContext getServiceContext() {
|
|
|
|
return ServiceContext.getContext();
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 12:11:12 +01:00
|
|
|
/**
|
|
|
|
* implementation of createResource method
|
|
|
|
* @param request creation request
|
|
|
|
* @return the EndpointReference pointing to the resource
|
|
|
|
* @throws GCUBEFault if something fails
|
|
|
|
*/
|
2009-05-08 19:58:31 +02:00
|
|
|
public EndpointReferenceType createResource() throws GCUBEFault {
|
2008-04-22 15:04:13 +02:00
|
|
|
String id=uuidGen.nextUUID();
|
2009-01-14 12:11:12 +01:00
|
|
|
logger.trace("resource "+id+" created");
|
2008-04-22 15:04:13 +02:00
|
|
|
ModelerResource mr;
|
|
|
|
try{
|
|
|
|
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
|
|
|
mr=(ModelerResource)pctx.getWSHome().create(pctx.makeKey(id), id);
|
2009-04-01 01:05:14 +02:00
|
|
|
mr.store();
|
2008-04-22 15:04:13 +02:00
|
|
|
return mr.getEPR();
|
|
|
|
}catch (Exception e){logger.error("error creating resource",e); throw new GCUBEFault(e);}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 18:45:29 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
/**
|
|
|
|
* return the existing DL Name
|
|
|
|
*
|
|
|
|
* @param request void
|
2009-01-14 12:11:12 +01:00
|
|
|
* @return array of string with existing VRE names
|
2008-04-22 14:11:53 +02:00
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public GetExistingNamesResponseMessage getExistingNamesVREs(VOID arg) throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
ArrayList<String> toReturn= new ArrayList<String>();
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
2008-11-07 18:45:29 +01:00
|
|
|
res= DBInterface.queryDB("select VRE.name from VRE;");
|
|
|
|
while (res.next())
|
|
|
|
toReturn.add(res.getString(1));
|
2010-01-29 17:42:06 +01:00
|
|
|
}catch(Exception e) {logger.error("error on DB"); throw new GCUBEFault(e);}
|
2008-04-22 16:07:12 +02:00
|
|
|
GetExistingNamesResponseMessage response = new GetExistingNamesResponseMessage();
|
2008-04-22 14:11:53 +02:00
|
|
|
response.setNames(toReturn.toArray(new String[0]));
|
2008-11-07 18:45:29 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the DB
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return void
|
2009-02-13 20:04:00 +01:00
|
|
|
* @throws GCUBEFault thrown if something fails
|
2008-04-22 14:11:53 +02:00
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public void initDB(VOID arg) throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
logger.debug("initDB method");
|
2009-02-13 20:04:00 +01:00
|
|
|
|
|
|
|
Thread t= new Thread(){
|
|
|
|
public void run(){
|
|
|
|
try{
|
|
|
|
ServiceContext.getContext().intializeDB();
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("DB inizialization failed"+e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
t.start();
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return String
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public String getAllVREs(VOID arg) throws GCUBEFault{
|
2008-04-22 14:11:53 +02:00
|
|
|
String toReturn = null;
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
2008-11-07 18:45:29 +01:00
|
|
|
res= DBInterface.queryDB("select VRE.name, VRE.description, VRE.status, VRE.epr from VRE;");
|
|
|
|
}catch(Exception e) {logger.error("VREModel: error on DB"); throw new GCUBEFault(e);}
|
2008-04-22 14:11:53 +02:00
|
|
|
try {
|
2008-10-21 19:09:24 +02:00
|
|
|
toReturn=XMLUtil.PrepareAllVREsXML(res);
|
2008-04-22 14:11:53 +02:00
|
|
|
} catch (Exception e) {
|
2008-11-07 18:45:29 +01:00
|
|
|
logger.error("VREModel parsing error in function getAllDLs "+e.getMessage());
|
2008-04-22 16:07:12 +02:00
|
|
|
throw new GCUBEFault(e);
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* remove the DL instance
|
|
|
|
*
|
2010-01-29 17:42:06 +01:00
|
|
|
* @param request the id of VRE to remove
|
2008-04-22 14:11:53 +02:00
|
|
|
* @return void
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2010-01-29 17:42:06 +01:00
|
|
|
public VOID removeVRE(String id) throws GCUBEFault{
|
|
|
|
logger.trace("Deleting resource with id "+id);
|
2008-04-22 14:11:53 +02:00
|
|
|
try{
|
2009-01-14 12:11:12 +01:00
|
|
|
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
2008-04-22 16:07:12 +02:00
|
|
|
//destroy the resource;
|
2009-01-14 12:11:12 +01:00
|
|
|
DBInterface.ExecuteUpdate("DELETE FROM VRE where VRE.id='"+id+"';");
|
2009-05-08 19:58:31 +02:00
|
|
|
pctx.getWSHome().remove(pctx.makeKey(id));
|
2010-01-29 17:42:06 +01:00
|
|
|
return new VOID();
|
2008-04-22 14:11:53 +02:00
|
|
|
}catch(Exception e){
|
2010-01-29 17:42:06 +01:00
|
|
|
logger.error("error removing resource",e);
|
|
|
|
throw new GCUBEFault(e);
|
2008-04-22 16:07:12 +02:00
|
|
|
}
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|