This commit is contained in:
Lucio Lelii 2008-04-22 14:54:47 +00:00
parent ef79154f75
commit 54cf2d00c2
2 changed files with 538 additions and 1 deletions

View File

@ -4,11 +4,36 @@ import org.gcube.common.core.state.GCUBEWSResource;
import org.globus.wsrf.ResourceException;
public class ModelerResource extends GCUBEWSResource {
protected static final String RP_ID = "Id";
protected static String[] RPNames = { RP_ID};
@Override
protected void initialise(Object... arg0) throws ResourceException {
// TODO Auto-generated method stub
}
/**
* {@inheritDoc}
*/
public String[] getPropertyNames() {
return RPNames;
}
/**
* Returns the id.
*
* @return the id.
*/
public String getId() throws ResourceException {
return (String) this.getResourcePropertySet().get(RP_ID).get(0);
}
protected synchronized void setId(String id) throws Exception {
this.getResourcePropertySet().get(RP_ID).clear();
this.getResourcePropertySet().get(RP_ID).add(id);
}
}

View File

@ -1,5 +1,517 @@
package org.gcube.vremanagement.vremodeler.impl;
import java.rmi.RemoteException;
import java.sql.Date;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Hashtable;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.stubs.CollectionArray;
import org.gcube.vremanagement.vremodeler.stubs.DHNArray;
import org.gcube.vremanagement.vremodeler.stubs.FunctionalityIDArray;
import org.gcube.vremanagement.vremodeler.stubs.SetMDFormatArgs;
import org.gcube.vremanagement.vremodeler.stubs.VdlRequest;
import org.globus.wsrf.ResourceException;
import org.globus.wsrf.encoding.ObjectSerializer;
import org.globus.wsrf.encoding.SerializationException;
public class ModelerService {
protected ModelerResource getResource() throws ResourceException{
return (ModelerResource) ModelerContext.getPortTypeContext().getWSHome().find();
}
/**
*
* @param request void
* @return VoidType
* @throws RemoteException -
*
*/
public void setDLModel(VdlRequest request) throws GCUBEFault{
Date dateFrom=null, dateTo=null;
ResultSet res=null;
try {
res=DBInterface.queryDB("select * from DL where DL.id='"+getResource().getId()+"'; ");
if(res.next())
{
dateFrom=new Date(request.getStartTime());
dateTo=new Date(request.getEndTime());
DBInterface.queryDB("update DL set name='"+request.getDLName()+"', description='"+request.getDLDescription()+"', dldesigner='"+request.getDLDesigner()+"', dlmanager= '"+request.getDLManager()+"', intervalfrom='"+dateFrom+"', intervalto='"+dateTo+"' where DL.id='"+getResource().getID()+"'; ");
}else{
dateFrom=new Date(request.getStartTime());
dateTo=new Date(request.getEndTime());
String eprToString;
try {
eprToString = ObjectSerializer.toString(getResource().getEPR());
//logger.debug("EPR: "+eprToString);
} catch (SerializationException e) {
//logger.error("VDL Model Service: error serializing EPR");
throw new RemoteException("VDL Model Service: error serializing EPR",e);
}
DBInterface.ExecuteUpdate("insert into DL values('"+getResource().getID()+"','"+request.getDLName()+"','"+request.getDLDescription()+"','"+request.getDLDesigner()+"','"+request.getDLManager()+"','"+dateFrom+"','"+dateTo+"','"+eprToString+"','In Progress'); ");
}
} catch (Exception e) {
//logger.error(e.getMessage());
//e.printStackTrace();
throw new GCUBEFault(e);
}
}
/**
*
*
* @param request void
* @return VoidType
* @throws RemoteException -
*/
public String getDLModel() throws GCUBEFault{
String toReturn =null;
ResultSet res=null;
//logger.debug("Request DL with ID "+ID);
try {
String ID=getResource().getId();
DBInterface.connect();
res=DBInterface.queryDB("select * from DL where DL.id='"+ID+"';");
// toReturn=XMLUtil.PrepareDLModelXML(res);
} catch (Exception e) {
//logger.error("VDLModel parsing error in function getDLModel "+e.getMessage());
throw new GCUBEFault(e);
}
return toReturn;
}
/**
* return an XML containing the DHN list
*
* @param request void
* @return a XML String
* @throws RemoteException -
*/
public String getDHNs() throws GCUBEFault{
ResultSet res;
ArrayList<String> relatedDHN=new ArrayList<String>();
try{
DBInterface.connect();
res= DBInterface.queryDB("select * from DHN;");
ResultSet resRelated= DBInterface.queryDB("select dhnid from DLRELATEDDHN where DLRELATEDDHN.dlid='"+getResource().getId()+"';");
while(resRelated.next()){
relatedDHN.add(resRelated.getString(1));
}
}catch(Exception e) {//logger.error("VDL Model: error on DB");
throw new GCUBEFault(e);}
return null; //XMLUtil.PrepareDHNsXML(res, relatedDHN);
}
/**
* Set the selected DHN
*
* @param request array of dhn id
* @return VoidType
* @throws RemoteException -
*/
public void setDHNs(DHNArray request) throws GCUBEFault{
try{
String instanceID=(String) getResource().getId();
DBInterface.ExecuteUpdate("DELETE FROM DLRELATEDDHN WHERE DLRELATEDDHN.dlid='"+instanceID+"';");
String[][] toInsert= new String[request.getDHNElement().length][2];
String dlKey=instanceID;
//logger.debug("KEY: "+dlKey);
for (int i=0; i<request.getDHNElement().length; i++)
{
toInsert[i][0]=dlKey;
toInsert[i][1]=request.getDHNElement()[i];
//logger.debug("selected dhn is: "+request.getCollectionElement()[i]);
}
DBInterface.InsertInto("DLRELATEDDHN", toInsert, false);
}catch(Exception e){throw new GCUBEFault(e);}
}
/**
*
* Return an XML with all the collection selectable
*
* @param request void
* @return the collection retreived from the database
* @throws RemoteException -
*/
public String getCollection() throws GCUBEFault{
ResultSet res;
ArrayList<String> relatedCollection=new ArrayList<String>();
try{
DBInterface.connect();
res= DBInterface.queryDB("select * from COLLECTION;");
ResultSet resRelated= DBInterface.queryDB("select collid from DLRELATEDCOLLECTION where DLRELATEDCOLLECTION.dlid='"+getResource().getId()+"';");
while(resRelated.next()){
relatedCollection.add(resRelated.getString(1));
}
}catch(Exception e) {//logger.error("VDL Model: error on DB");
throw new GCUBEFault(e);}
return null; //XMLUtil.PrepareCollectionXML(res, relatedCollection);
}
/**
*
* Insert in the DB the selected collection
*
* @param request An Array that contains the selected collections ids
* @return void
* @throws RemoteException -
*/
public void setCollection(CollectionArray request) throws GCUBEFault{
try{
DBInterface.ExecuteUpdate("DELETE FROM DLRELATEDCOLLECTION WHERE DLRELATEDCOLLECTION.dlid='"+getResource().getID()+"';");
String[][] toInsert= new String[request.getCollectionElement().length][2];
String dlKey=(String) getResource().getId();
//logger.debug("KEY: "+dlKey);
for (int i=0; i<request.getCollectionElement().length; i++)
{
toInsert[i][0]=dlKey;
toInsert[i][1]=request.getCollectionElement()[i];
//logger.debug("selected collection is: "+request.getCollectionElement()[i]);
}
DBInterface.InsertInto("DLRELATEDCOLLECTION", toInsert, false);
}catch(Exception e){throw new GCUBEFault(e);}
}
/**
* Return the possibles metadata format for selected collection
*
* @param request void
* @return a XML format string
* @throws RemoteException -
*/
public String getMetadataRelatedToCollection() throws GCUBEFault {
ResultSet resDerivable, resNative, collectionRelated, totalMF;
String preparedWhere="";
Hashtable<String, ArrayList<String>> selectedMetadataStructure= new Hashtable<String, ArrayList<String>>();
boolean enter=false;
try{
DBInterface.connect();
collectionRelated= DBInterface.queryDB("select DLRELATEDCOLLECTION.collid from DLRELATEDCOLLECTION where DLRELATEDCOLLECTION.dlid='"+getResource().getId()+"';");
//select only the resuls related with selected collection
preparedWhere= " and ( ";
while (collectionRelated.next()){
enter=true;
preparedWhere+= " mdc.collid='"+collectionRelated.getString(1)+"' or ";
}
ResultSet metadataSelected= DBInterface.queryDB("select collid, mfid from DLRELATEDMETADATAFORMAT where dlid='"+getResource().getID()+"';");
//recovering possible previsious selection for metadataFormat
while (metadataSelected.next()){
if(selectedMetadataStructure.containsKey(metadataSelected.getString(1)))
selectedMetadataStructure.get(metadataSelected.getString(1)).add(metadataSelected.getString(2));
else {
ArrayList<String> temp= new ArrayList<String>();
temp.add(metadataSelected.getString(2));
selectedMetadataStructure.put(metadataSelected.getString(1), temp);
}
}
if(!enter) throw new RemoteException("no collection selected for this DL");
else preparedWhere=preparedWhere.substring(0, preparedWhere.length()-4)+") ";
totalMF = DBInterface.queryDB("select MDFORMAT.id, MDFORMAT.name, MDFORMAT.schemauri, MDFORMAT.language from MDFORMAT;");
resDerivable= DBInterface.queryDB("select mdc.collid, mdc.collname, mdc.colldesc , collmdf.id as mdfid from (select * from DERIVABLEMDF INNER JOIN MDFORMAT on DERIVABLEMDF.mdfid= MDFORMAT.id) " +
"as COLLMDF,(select COLLECTION.id as collid, COLLECTION.name as collname, COLLECTION.description as colldesc, MDCOLLECTION.id as mdid from COLLECTION INNER JOIN MDCOLLECTION " +
"ON COLLECTION.id = MDCOLLECTION.relatedcollectionid) as MDC where COLLMDF.mdcollid= MDC.mdid "+preparedWhere+";");
resNative= DBInterface.queryDB("select mdc.collid, mdc.collname, mdc.colldesc , collmdf.id as mdfid from (select * from NATIVEMDF INNER JOIN MDFORMAT on NATIVEMDF.mdfid= MDFORMAT.id) " +
"as COLLMDF,(select COLLECTION.id as collid, COLLECTION.name as collname, COLLECTION.description as colldesc, MDCOLLECTION.id as mdid from COLLECTION INNER JOIN MDCOLLECTION " +
"ON COLLECTION.id = MDCOLLECTION.relatedcollectionid) as MDC where COLLMDF.mdcollid= MDC.mdid "+preparedWhere+";");
}catch(Exception e) {//logger.error("ModelService: "+e.getMessage());
throw new GCUBEFault(e);
}
return null; //XMLUtil.PrepareMCFormatXML(resNative, resDerivable, totalMF, selectedMetadataStructure);
}
/**
*
* Sets selected Metadata Format
*
* @param request
* @return void
* @throws RemoteException -
*/
public void setMetadataRelatedToCollection(SetMDFormatArgs request) throws GCUBEFault {
try{
DBInterface.ExecuteUpdate("DELETE FROM DLRELATEDMETADATAFORMAT WHERE DLRELATEDMETADATAFORMAT.dlid='"+getResource().getId()+"';");
String[] singleElement;
ArrayList<String[]> elementsList= new ArrayList<String[]>();
String key=(String) getResource().getId();
//logger.debug(request.getCollectionIDArray().length+" "+request.getMdFormatIDArray().length+" "+request.getCheckedArray().length+" "+request.getCheckedArray(0).getCheckedRowElement().length);
for (int i=0; i<request.getCollectionIDArray().length; i++)
for( int j=0; j<request.getMdFormatIDArray().length; j++)
{
if (request.getCheckedArray(i).getCheckedRowElement(j)){
singleElement=new String[3];
singleElement[0]=key;
singleElement[1]=request.getCollectionIDArray(i);
singleElement[2]=request.getMdFormatIDArray(j);
elementsList.add(singleElement);
//logger.debug("SELECTED coll "+singleElement[1]+" MF "+singleElement[2]);
}
//logger.debug("pervenuto: coll "+ request.getCollectionIDArray(i)+" MF "+request.getMdFormatIDArray(j));
}
DBInterface.InsertInto("DLRELATEDMETADATAFORMAT", elementsList.toArray(new String[0][0]), false);
}catch(Exception e){throw new GCUBEFault(e);}
}
/**
* Return an xml with the selectable functionalities
* String
*
* @param request void
* @return an xml String containing selectable functionalities
* @throws RemoteException -
*/
public String getFunctionality() throws GCUBEFault {
ResultSet resFunct=null;
ResultSet selectedFuncRes=null;
ResultSet selectedCSRes=null;
ArrayList<Integer> selectedFunctionality= new ArrayList<Integer>();
ArrayList<String> selectedCS= new ArrayList<String>();
try {
DBInterface.connect();
resFunct= DBInterface.queryDB("select * from functionality where father is null;");
selectedFuncRes= DBInterface.queryDB("select funcid from DLRELATEDFUNCT where dlid='"+getResource().getID()+"';");
while (selectedFuncRes.next())
selectedFunctionality.add(selectedFuncRes.getInt(1));
selectedCSRes= DBInterface.queryDB("select csid from DLRELATEDCS where dlid='"+getResource().getID()+"';");
while (selectedCSRes.next())
selectedCS.add(selectedCSRes.getString(1));
} catch (Exception e) {
//logger.error("VDLModel Service: error retreiving functionality");
e.printStackTrace();
throw new GCUBEFault(e);
}
return null; //XMLUtil.PrepareFunctionalityXML(resFunct, selectedFunctionality, selectedCS);
}
/**
*
*
*
* @return void
* @throws RemoteException -
*/
public void setFunctionality(FunctionalityIDArray request) throws GCUBEFault {
try{
DBInterface.ExecuteUpdate("DELETE FROM DLRELATEDFUNCT WHERE DLRELATEDFUNCT.dlid='"+getResource().getId()+"';");
DBInterface.ExecuteUpdate("DELETE FROM DLRELATEDCS WHERE DLRELATEDCS.dlid='"+getResource().getId()+"';");
String dlKey=(String) getResource().getId();
//logger.debug("KEY: "+dlKey);
if (request.getFunctionalityIDElement()!=null){
String[][] toInsertFunc= new String[request.getFunctionalityIDElement().length][2];
for (int i=0; i<request.getFunctionalityIDElement().length; i++)
{
toInsertFunc[i][0]=dlKey;
toInsertFunc[i][1]=request.getFunctionalityIDElement()[i];
}
DBInterface.InsertInto("DLRELATEDFUNCT", toInsertFunc, false);
}
if (request.getCsIDElement()!=null)
{
String[][] toInsertCS= new String[request.getCsIDElement().length][2];
for (int i=0; i<request.getCsIDElement().length; i++)
{
toInsertCS[i][0]=dlKey;
toInsertCS[i][1]=request.getCsIDElement()[i];
}
DBInterface.InsertInto("DLRELATEDCS", toInsertCS, false);
}
}catch(Exception e){throw new GCUBEFault(e);}
}
/**
* Return an XML with Quality parameter to insert
*
* @param request void
* @return a XML format String
* @throws RemoteException -
*/
public String getQuality() throws GCUBEFault{
return null; //XMLUtil.PrepareQualityXML();
}
/**
* Sets Quality parameters
*
* @param request
* @throws RemoteException -
*/
public void setQuality(String request) throws GCUBEFault{
}
/**
*
* set the DL state to Pending
*
* @param request
* @return
* @throws RemoteException -
*/
public void setDLtoPendingState() throws GCUBEFault{
try{
DBInterface.ExecuteUpdate("UPDATE DL SET STATUS='Pending' WHERE DL.id='"+getResource().getId()+"';");
}catch(Exception e){throw new GCUBEFault(e);}
}
/**
*
* @param request
* @return
* @throws RemoteException -
*/
public void deployDL() throws RemoteException{
/*DBInterface.ExecuteUpdate("UPDATE DL SET STATUS='Deploying' WHERE DL.id='"+getResource().getId()+"';");
DLManagementFactoryServiceAddressingLocator dlMan=new DLManagementFactoryServiceAddressingLocator();
try {
//retreive and connect to the DLManagement
EndpointReferenceType eprDLMan= new EndpointReferenceType(new AttributedURI(DISHLSClient.getRunningInstanceManager(null, getMyEPR()).getEPRsRIFromClassAndName("Keeper", "DLManagement", "diligentproject/keeperservice/dlmanagement/DLManagementFactoryService", null, getMyEPR())[0]));
DLManagementFactoryPortType dlManagementFactory= dlMan.getDLManagementFactoryPortTypePort(eprDLMan);
// authorization control (if in the container the security is enabled)
if (ModelFactoryService.isSecurityEnabled){
CredentialManager cred= new CredentialManager();
ConfigureSecurity.setSecurity(((javax.xml.rpc.Stub)dlManagementFactory), cred.getCredentials());
}
logger.debug("DLManagement retreived");
String dlId=(String)getResource().getId();
CreateDLMessage createDLMessage= new CreateDLMessage();
createDLMessage.setVDLUniqueID(dlId);
ResultSet dlGenRes= DBInterface.queryDB("select name, description, dldesigner, dlmanager, intervalto, id from DL where DL.id='"+dlId+"';");
if (dlGenRes.next()){
createDLMessage.setDLName((new NAL().getDefaultVO())+"/"+dlGenRes.getString(1));
createDLMessage.setDescription(dlGenRes.getString(2));
createDLMessage.setDLDesigner(dlGenRes.getString(3));
createDLMessage.setDLManager(dlGenRes.getString(4));
Calendar terminationTime=Calendar.getInstance();
terminationTime.setTime(dlGenRes.getDate(5));
createDLMessage.setDLTerminationTime(terminationTime);
createDLMessage.setVDLUniqueID(dlGenRes.getString(6));
createDLMessage.setIsSecurityEnabled(ModelFactoryService.isSecurityEnabled);
}else throw new RemoteException("VDLModel Service: impossible to retreive specific DL");
//logger.debug("Setted first parameters");
ArrayList<String> tempArray= new ArrayList<String>();
//retreive and set collection ids
ResultSet dlCollRes= DBInterface.queryDB("select collid from DLRELATEDCOLLECTION where DLRELATEDCOLLECTION.dlid='"+dlId+"';");
for (int i=0; dlCollRes.next(); i++)
tempArray.add(dlCollRes.getString(1));
createDLMessage.setColIDsList(tempArray.toArray(new String[0]));
tempArray= new ArrayList<String>();
//retreive Metadata IDs
ResultSet dlMetadataRes=DBInterface.queryDB("select DISTINCT NATIVEMDF.MDCOLLID from DLRELATEDMETADATAFORMAT, NATIVEMDF where DLRELATEDMETADATAFORMAT.mfid=NATIVEMDF.mdfid and DLRELATEDMETADATAFORMAT.dlid='"+dlId+"';");
for (int i=0; dlMetadataRes.next(); i++)
tempArray.add(dlMetadataRes.getString(1));
createDLMessage.setMcIDsList(tempArray.toArray(new String[0]));
//TODO: TP retriving is a mistery :)
//adding functionality to DLManagement request
tempArray= new ArrayList<String>();
ResultSet dlRelatedFunctionality=DBInterface.queryDB("select RELATEDSERVICEID.id from RELATEDSERVICEID, SERVICES, DLRELATEDFUNCT where DLRELATEDFUNCT.dlid='"+dlId+"' and SERVICES.id=DLRELATEDFUNCT.funcid and SERVICES.class=RELATEDSERVICEID.class and SERVICES.name=RELATEDSERVICEID.name;");
for (int i=0; dlRelatedFunctionality.next(); i++){
tempArray.add(dlRelatedFunctionality.getString(1));
logger.debug("ServiceID: "+dlRelatedFunctionality.getString(1));
}
createDLMessage.setServiceIDsList(tempArray.toArray(new String[0]));
//adding DHN to DLManagement request
tempArray= new ArrayList<String>();
ResultSet dlRelatedDHN=DBInterface.queryDB("select DLRELATEDDHN.dhnid from DLRELATEDDHN where DLRELATEDDHN.dlid='"+dlId+"'");
for (int i=0; dlRelatedDHN.next(); i++)
tempArray.add(dlRelatedDHN.getString(1));
createDLMessage.setDhnIDsList(tempArray.toArray(new String[0]));
//adding cs to DLManagement request
tempArray= new ArrayList<String>();
ResultSet dlCSRes= DBInterface.queryDB("select csid from DLRELATEDCS where DLRELATEDCS.dlid='"+getResource().getId()+"';");
for (int i=0; dlCSRes.next(); i++)
tempArray.add(dlCSRes.getString(1));
createDLMessage.setCsIDsList(tempArray.toArray(new String[0]));
//DLManagement invocation
dlManagementFactory.createDL(createDLMessage);
} catch (Exception e) {
logger.error("VDLModel Service: Error Deploying DL "+e.getMessage());
e.printStackTrace();
DBInterface.ExecuteUpdate("UPDATE DL SET STATUS='Failed' WHERE DL.id='"+getResource().getId()+"';");
throw new RemoteException("VDLModel Service: Error Deploying DL" ,e);
}
*/
}
}