2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
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-04-22 14:11:53 +02:00
|
|
|
import org.gcube.common.core.porttypes.GCUBEStartupPortType;
|
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-10-22 19:48:08 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.stubs.GetExistingNamesResponseMessage;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.globus.wsrf.encoding.ObjectDeserializer;
|
|
|
|
import org.globus.wsrf.tests.basic.CreateResource;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ModelFactoryService extends GCUBEStartupPortType{
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
private GCUBELog logger = new GCUBELog(this);
|
|
|
|
private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
@Override
|
2008-04-22 15:04:13 +02:00
|
|
|
protected ServiceContext getServiceContext() {
|
|
|
|
return ServiceContext.getContext();
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementation of createResource Operation */
|
2008-04-22 15:04:13 +02:00
|
|
|
public EndpointReferenceType createResource(CreateResource request) throws GCUBEFault {
|
|
|
|
String id=uuidGen.nextUUID();
|
|
|
|
ModelerResource mr;
|
|
|
|
try{
|
|
|
|
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
|
|
|
mr=(ModelerResource)pctx.getWSHome().create(pctx.makeKey(id), id);
|
|
|
|
return mr.getEPR();
|
|
|
|
}catch (Exception e){logger.error("error creating resource",e); throw new GCUBEFault(e);}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return the existing DL Name
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return array of string qith exististin dl names
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-10-22 19:48:08 +02:00
|
|
|
public GetExistingNamesResponseMessage getExistingNamesVREs() throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
ArrayList<String> toReturn= new ArrayList<String>();
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
|
|
|
res= DBInterface.queryDB("select DL.name from DL;");
|
|
|
|
while (res.next()) toReturn.add(res.getString(1));
|
2008-04-22 16:07:12 +02:00
|
|
|
//String customXquery="for $query in collection(\"/db/Profiles/VDL\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource return <name>$query/Profile/Name/string()</name>";
|
|
|
|
//String queryResult= DISHLSClient.getGeneralQueryManager(cred, factoryEPR).queryDISIC(customXquery,cred, factoryEPR);
|
|
|
|
//logger.debug("VDL get Name QUERY: "+queryResult);
|
|
|
|
}catch(Exception e) {logger.error("VDL Model: error on DB"); throw new GCUBEFault(e);}
|
|
|
|
GetExistingNamesResponseMessage response = new GetExistingNamesResponseMessage();
|
2008-04-22 14:11:53 +02:00
|
|
|
response.setNames(toReturn.toArray(new String[0]));
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the DB
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return void
|
|
|
|
* @throws RemoteException remote exception
|
|
|
|
*/
|
2008-04-22 16:07:12 +02:00
|
|
|
public void initDB() throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
logger.debug("initDB method");
|
2008-04-22 16:07:12 +02:00
|
|
|
//new InitThread(factoryEPR, cred).start();
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return String
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-10-21 19:09:24 +02:00
|
|
|
public String getAllVREs() throws GCUBEFault{
|
2008-04-22 14:11:53 +02:00
|
|
|
String toReturn = null;
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
|
|
|
res= DBInterface.queryDB("select DL.name, DL.description, DL.status, DL.epr from DL;");
|
2008-04-22 16:07:12 +02:00
|
|
|
}catch(Exception e) {logger.error("VDL Model: 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) {
|
|
|
|
logger.error("VDLModel 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
|
|
|
|
*
|
|
|
|
* @param request the id of DL to remove
|
|
|
|
* @return void
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-10-30 19:54:34 +01:00
|
|
|
public void removeVRE(String request) throws GCUBEFault{
|
2008-04-22 14:11:53 +02:00
|
|
|
try{
|
2008-10-21 19:09:24 +02:00
|
|
|
ResultSet res=DBInterface.queryDB("Select VRE.epr from VRE where VRE.id='"+request+"';");
|
2008-04-22 14:11:53 +02:00
|
|
|
EndpointReferenceType dlEpr;
|
|
|
|
|
|
|
|
|
|
|
|
if (res.next()){
|
|
|
|
StringReader stringReader = new StringReader(res.getString(1));
|
|
|
|
InputSource inputSource = new InputSource(stringReader);
|
|
|
|
dlEpr = (EndpointReferenceType) ObjectDeserializer.deserialize(inputSource, EndpointReferenceType.class);
|
2008-10-21 19:09:24 +02:00
|
|
|
}else throw new Exception("VRE not retreived in DB");
|
2008-04-22 14:11:53 +02:00
|
|
|
|
2008-04-22 16:07:12 +02:00
|
|
|
//destroy the resource;
|
2008-10-21 19:09:24 +02:00
|
|
|
DBInterface.ExecuteUpdate("DELETE FROM VRE where VRE.id='"+request+"';");
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("VDLModel: "+e.getMessage());
|
2008-04-22 16:07:12 +02:00
|
|
|
throw new GCUBEFault( e);
|
|
|
|
}
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|