vre-modeler/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java

145 lines
4.4 KiB
Java
Raw Normal View History

package org.gcube.vremanagement.vremodeler.impl;
import java.io.StringReader;
import java.sql.ResultSet;
import java.util.ArrayList;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.porttypes.GCUBEStartupPortType;
import org.gcube.common.core.types.VOID;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.impl.util.XMLUtil;
import org.gcube.vremanagement.vremodeler.stubs.GetExistingNamesResponseMessage;
import org.globus.wsrf.encoding.ObjectDeserializer;
import org.globus.wsrf.tests.basic.CreateResource;
import org.xml.sax.InputSource;
public class ModelFactoryService extends GCUBEStartupPortType{
private GCUBELog logger = new GCUBELog(ModelFactoryService.class.getName());
private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
@Override
protected ServiceContext getServiceContext() {
return ServiceContext.getContext();
}
/* Implementation of createResource Operation */
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);}
}
/**
* return the existing DL Name
*
* @param request void
* @return array of string qith exististin dl names
* @throws RemoteException -
*/
public GetExistingNamesResponseMessage getExistingNamesVREs(VOID arg) throws GCUBEFault {
ArrayList<String> toReturn= new ArrayList<String>();
ResultSet res=null;
try{
DBInterface.connect();
res= DBInterface.queryDB("select VRE.name from VRE;");
while (res.next())
toReturn.add(res.getString(1));
//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("VRE Model: error on DB"); throw new GCUBEFault(e);}
GetExistingNamesResponseMessage response = new GetExistingNamesResponseMessage();
response.setNames(toReturn.toArray(new String[0]));
return response;
}
/**
* Initialize the DB
*
* @param request void
* @return void
* @throws RemoteException remote exception
*/
public void initDB(VOID arg) throws GCUBEFault {
logger.debug("initDB method");
//new InitThread(factoryEPR, cred).start();
}
/**
*
* @param request void
* @return String
* @throws RemoteException -
*/
public String getAllVREs(VOID arg) throws GCUBEFault{
String toReturn = null;
ResultSet res=null;
try{
DBInterface.connect();
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);}
try {
toReturn=XMLUtil.PrepareAllVREsXML(res);
} catch (Exception e) {
logger.error("VREModel parsing error in function getAllDLs "+e.getMessage());
throw new GCUBEFault(e);
}
return toReturn;
}
/**
*
* remove the DL instance
*
* @param request the id of DL to remove
* @return void
* @throws RemoteException -
*/
public void removeVRE(String request) throws GCUBEFault{
try{
ResultSet res=DBInterface.queryDB("Select VRE.epr from VRE where VRE.id='"+request+"';");
EndpointReferenceType dlEpr;
if (res.next()){
StringReader stringReader = new StringReader(res.getString(1));
InputSource inputSource = new InputSource(stringReader);
dlEpr = (EndpointReferenceType) ObjectDeserializer.deserialize(inputSource, EndpointReferenceType.class);
}else throw new Exception("VRE not retreived in DB");
//destroy the resource;
DBInterface.ExecuteUpdate("DELETE FROM VRE where VRE.id='"+request+"';");
}catch(Exception e){
logger.error("VDLModel: "+e.getMessage());
throw new GCUBEFault( e);
}
}
}