aslcore/src/org/gcube/application/framework/core/vremanagement/impl/VREGenerator.java

291 lines
8.6 KiB
Java

package org.gcube.application.framework.core.vremanagement.impl;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.application.framework.core.security.PortalSecurityManager;
import org.gcube.application.framework.core.session.D4ScienceSession;
import org.gcube.application.framework.core.vremanagement.VREGeneratorI;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.common.core.types.VOID;
import org.gcube.vremanagement.vremodeler.stubs.CheckedRows;
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.ModelerFactoryPortType;
import org.gcube.vremanagement.vremodeler.stubs.ModelerServicePortType;
import org.gcube.vremanagement.vremodeler.stubs.SetMDFormatArgs;
import org.gcube.vremanagement.vremodeler.stubs.VdlRequest;
import org.gcube.vremanagement.vremodeler.stubs.service.ModelerFactoryServiceAddressingLocator;
import org.gcube.vremanagement.vremodeler.stubs.service.ModelerServiceAddressingLocator;
import org.globus.wsrf.encoding.DeserializationException;
import org.globus.wsrf.encoding.ObjectDeserializer;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class VREGenerator implements VREGeneratorI{
D4ScienceSession session;
ModelerServicePortType modelPortType;
GCUBESecurityManagerImpl managerSec;
/**
* @param session
* @param epr
*/
public VREGenerator(D4ScienceSession session, String epr) {
super();
this.session = session;
modelPortType = deserializeEPR(epr);
managerSec = new PortalSecurityManager(session);
}
/**
* @param session
*/
public VREGenerator(D4ScienceSession session) {
super();
this.session = session;
modelPortType = null;
}
ModelerServicePortType deserializeEPR(String epr)
{
StringReader stringReader = new StringReader(epr);
InputSource inputSource = new InputSource(stringReader);
EndpointReferenceType endpointReferenceType = null;
try {
endpointReferenceType = (EndpointReferenceType) ObjectDeserializer.deserialize(inputSource, EndpointReferenceType.class);
ModelerServiceAddressingLocator mSALocator = new ModelerServiceAddressingLocator();
modelPortType = GCUBERemotePortTypeContext.getProxy(mSALocator.getModelerServicePortTypePort(endpointReferenceType), session.getScope(),managerSec);
return modelPortType;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void getAllVREs()
{
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#checkVREStatus()
*/
public String[][] checkVREStatus() throws RemoteException {
// TODO pou vrisketai auti i sunartisi sta stubs?????
return null;
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#deployVRE()
*/
public void deployVRE() throws RemoteException {
modelPortType.deployDL(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getCollection()
*/
public String getCollection() throws RemoteException {
return modelPortType.getCollection(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getGHNs()
*/
public String getGHNs() throws RemoteException {
return modelPortType.getDHNs(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getVREModel()
*/
public String getVREModel() throws RemoteException {
modelPortType.getDLModel(new VOID());
return null;
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getExistingNamesVREs()
*/
public String[] getExistingNamesVREs() {
// return getModelPortType().get(new VOID());
return null;
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getFunctionality()
*/
public String getFunctionality() throws RemoteException {
return modelPortType.getFunctionality(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getMetadataRelatedToCollection()
*/
public String getMetadataRelatedToCollection() throws RemoteException {
return modelPortType.getMetadataRelatedToCollection(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#getQuality()
*/
public String getQuality() throws RemoteException {
return modelPortType.getQuality(new VOID());
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#setCollection(java.lang.String[])
*/
public void setCollection(String[] collections) throws RemoteException {
modelPortType.setCollection(new CollectionArray(collections));
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#setGHNs(java.lang.String[])
*/
public void setGHNs(String[] GHNElements) throws RemoteException {
modelPortType.setDHNs(new DHNArray(GHNElements));
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#setVREModel(java.lang.String, java.lang.String, java.lang.String, java.lang.String, long, long)
*/
public void setVREModel(String VREName, String VREDescription, String VREDesigner, String VREManager, long startTime, long endTime) throws RemoteException {
VdlRequest vdlReq = new VdlRequest();
vdlReq.setDLDescription(VREDescription);
vdlReq.setDLDesigner(VREDesigner);
vdlReq.setDLManager(VREManager);
vdlReq.setDLName(VREName);
vdlReq.setStartTime(startTime);
vdlReq.setEndTime(endTime);
modelPortType.setDLModel(vdlReq);
}
/* (non-Javadoc)
* @see org.gcube.application.framework.VVREGeneratorI#setVREtoPendingState()
*/
public void setVREtoPendingState() throws RemoteException {
modelPortType.setDLtoPendingState(new VOID());
}
public void setFunctionality(String[] csIDElement, String[] functionalityIDElement)
throws RemoteException {
FunctionalityIDArray functArray = new FunctionalityIDArray();
functArray.setCsIDElement(csIDElement);
functArray.setFunctionalityIDElement(functionalityIDElement);
modelPortType.setFunctionality(functArray );
}
public void setMetadataRelatedToCollection(String[] collectionIDArray, boolean[][] checkedArray, String[] mdFormatIDArray)
throws RemoteException {
SetMDFormatArgs mdFormat = new SetMDFormatArgs();
int numRows = checkedArray.length;
CheckedRows[] checkedRows = new CheckedRows[numRows];
for(int i=0; i<numRows; i++){
CheckedRows row = new CheckedRows(checkedArray[i]);
checkedRows[i] = row;
}
mdFormat.setCheckedArray(checkedRows);
mdFormat.setCollectionIDArray(collectionIDArray);
mdFormat.setMdFormatIDArray(mdFormatIDArray);
modelPortType.setMetadataRelatedToCollection(mdFormat);
}
public void setQuality(String quality) throws RemoteException {
modelPortType.setQuality(quality);
}
private void getModelPortType(){
System.out.println("--- Get ModelPortType ---");
EndpointReferenceType epr = null;
ModelerFactoryPortType mFPType = null;
ModelerServicePortType mServicePortType = null;
EndpointReferenceType VREEndpointReferenceType;
if(modelPortType==null){
System.out.println("VREEndpointReferenceType==null");
ModelerFactoryServiceAddressingLocator mFSLocator = new ModelerFactoryServiceAddressingLocator();
try {
System.out.println("getModelFactoryPortTypePort(epr)");
mFPType = GCUBERemotePortTypeContext.getProxy(mFSLocator.getModelerFactoryPortTypePort(epr),
session.getScope(),managerSec);
VREEndpointReferenceType = mFPType.createResource(new VOID());
ModelerServiceAddressingLocator mSALocator = new ModelerServiceAddressingLocator();
mServicePortType = GCUBERemotePortTypeContext.getProxy(mSALocator.getModelerServicePortTypePort(VREEndpointReferenceType), session.getScope(),managerSec);
// Attaching Credential to port type
System.out.println("Attaching Credential to port type");
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
System.out.println("modelPortType!=null");
System.out.println(modelPortType.toString());
}
System.out.println("--- Get ModelPortType done ---");
modelPortType = mServicePortType;
}
}