package jalview.ws.rest;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentOrder;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.io.packed.DataProvider;
import jalview.io.packed.JalviewDataset;
+import jalview.io.packed.ParsePackedSet;
+import jalview.io.packed.SimpleDataProvider;
+import jalview.io.packed.DataProvider.JvDataType;
import jalview.ws.AWsJob;
import jalview.ws.rest.params.Alignment;
import jalview.ws.rest.params.SeqGroupIndexVector;
public class RestJob extends AWsJob
{
-
+
// TODO: input alignmentview and other data for this job
RestServiceDescription rsd;
+
// boolean submitted;
boolean gotresponse;
+
boolean error;
+
boolean waiting;
+
boolean gotresult;
+
Hashtable squniq;
-
+
+ /**
+ * dataset associated with this input data.
+ */
+ AlignmentI dsForIO;
+
+ AlignmentOrder inputOrder;
+
+ /**
+ * context of input data with respect to an AlignmentView's visible contigs.
+ */
+ int[] origviscontig;
+
+ private AlignmentI contextAl=null;
+
/**
- * create a rest job using data bounded by the given start/end column.
+ * create a rest job using data bounded by the given start/end column.
+ *
* @param addJobPane
* @param restJobThread
* @param _input
+ * @param viscontigs
+ * visible contigs of an alignment view from which _input was derived
*/
public RestJob(int jobNum, RestJobThread restJobThread,
- AlignmentI _input)
+ AlignmentI _input, int[] viscontigs)
{
rsd = restJobThread.restClient.service;
jobnum = jobNum;
+ if (viscontigs != null)
+ {
+ origviscontig = new int[viscontigs.length];
+ System.arraycopy(viscontigs, 0, origviscontig, 0, viscontigs.length);
+ }
// get sequences for the alignmentI
// get groups trimmed to alignment columns
// get any annotation trimmed to start/end columns, too.
-
+
// prepare input
- // form alignment+groups+annotation,preprocess and then record references for formatters
+ // form alignment+groups+annotation,preprocess and then record references
+ // for formatters
ArrayList<InputType> alinp = new ArrayList<InputType>();
- int paramsWithData=0;
- // we cheat for moment - since we know a-priori what data is available and what inputs we have implemented so far
- for (Map.Entry<String,InputType>prm: rsd.inputParams.entrySet())
+ int paramsWithData = 0;
+ // we cheat for moment - since we know a-priori what data is available and
+ // what inputs we have implemented so far
+ for (Map.Entry<String, InputType> prm : rsd.inputParams.entrySet())
{
if (!prm.getValue().isConstant())
{
if (prm.getValue() instanceof Alignment)
- {
- alinp.add(prm.getValue());
- } else
- {
- if ((prm.getValue() instanceof SeqGroupIndexVector)
- &&(_input.getGroups()!=null && _input.getGroups().size()>0))
{
alinp.add(prm.getValue());
}
- }
- } else {
+ else
+ {
+ if ((prm.getValue() instanceof SeqGroupIndexVector)
+ && (_input.getGroups() != null && _input.getGroups()
+ .size() > 0))
+ {
+ alinp.add(prm.getValue());
+ }
+ }
+ }
+ else
+ {
paramsWithData++;
}
}
- if ((paramsWithData+alinp.size())==rsd.inputParams.size())
+ if ((paramsWithData + alinp.size()) == rsd.inputParams.size())
{
+ inputOrder = new AlignmentOrder(_input);
+ if ((dsForIO = _input.getDataset()) == null)
+ {
+ _input.setDataset(null);
+ }
+ dsForIO = _input.getDataset();
+ if (contextAl==null)
+ {
+ contextAl = _input;
+ }
setAlignmentForInputs(alinp, _input);
- validInput=true;
- } else {
+ validInput = true;
+ }
+ else
+ {
// not enough data, so we bail.
- validInput=false;
+ validInput = false;
}
}
- boolean validInput=false;
+
+ boolean validInput = false;
+
@Override
public boolean hasResults()
{
@Override
public boolean isRunning()
{
- return running; // TODO: can we check the response body for status messages ?
+ return running; // TODO: can we check the response body for status messages
+ // ?
}
@Override
@Override
public boolean isFinished()
{
- return resSet!=null;
+ return resSet != null;
}
@Override
}
protected String statMessage = null;
+
public HttpResultSet resSet;
@Override
@Override
public boolean hasResponse()
{
- return statMessage!=null || resSet!=null;
+ return statMessage != null || resSet != null;
}
@Override
public void clearResponse()
{
- // only clear the transient server response
+ // only clear the transient server response
// statMessage=null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jalview.ws.AWsJob#getState()
*/
@Override
public String getState()
{
- // TODO generate state string - prolly should have a default abstract method for this
+ // TODO generate state string - prolly should have a default abstract method
+ // for this
return "Job is clueless";
}
public String getPostUrl()
{
-
+
// TODO Auto-generated method stub
return rsd.postUrl;
}
- public Set<Map.Entry<String,InputType>> getInputParams()
+ public Set<Map.Entry<String, InputType>> getInputParams()
{
return rsd.inputParams.entrySet();
}
/**
*
- * @return new context for parsing results from service
+ * @return the context for parsing results from service
*/
public JalviewDataset newJalviewDataset()
{
- /*
- * TODO: initialise dataset with correct input context
- */
- JalviewDataset njd = new JalviewDataset();
- return njd;
+ if (context == null)
+ {
+ context = new JalviewDataset(dsForIO, null, squniq, null);
+ if (contextAl!=null)
+ {
+ context.addAlignment(contextAl);
+ }
+
+ }
+ return context;
}
/**
- * Extract list of sequence IDs for input parameter 'token' with given molecule type
+ * Extract list of sequence IDs for input parameter 'token' with given
+ * molecule type
+ *
* @param token
* @param type
* @return
*/
- public SequenceI[] getSequencesForInput(String token, InputType.molType type) throws NoValidInputDataException
+ public SequenceI[] getSequencesForInput(String token,
+ InputType.molType type) throws NoValidInputDataException
{
Object sgdat = inputData.get(token);
// can we form an alignment from this data ?
- if (sgdat==null)
+ if (sgdat == null)
{
- throw new NoValidInputDataException("No Sequence vector data bound to input '"+token+"' for service at "+rsd.postUrl);
+ throw new NoValidInputDataException(
+ "No Sequence vector data bound to input '" + token
+ + "' for service at " + rsd.postUrl);
}
if (sgdat instanceof AlignmentI)
{
}
if (sgdat instanceof SequenceGroup)
{
- return ((SequenceGroup)sgdat).getSequencesAsArray(null);
+ return ((SequenceGroup) sgdat).getSequencesAsArray(null);
}
if (sgdat instanceof Vector)
{
- if (((Vector)sgdat).size()>0 && ((Vector)sgdat).get(0) instanceof SequenceI)
+ if (((Vector) sgdat).size() > 0
+ && ((Vector) sgdat).get(0) instanceof SequenceI)
{
- SequenceI[] sq = new SequenceI[((Vector)sgdat).size()];
- ((Vector)sgdat).copyInto(sq);
+ SequenceI[] sq = new SequenceI[((Vector) sgdat).size()];
+ ((Vector) sgdat).copyInto(sq);
return sq;
}
}
- throw new NoValidInputDataException("No Sequence vector data bound to input '"+token+"' for service at "+rsd.postUrl);
+ throw new NoValidInputDataException(
+ "No Sequence vector data bound to input '" + token
+ + "' for service at " + rsd.postUrl);
}
+
/**
- * binding between input data (AlignmentI, SequenceGroup, NJTree) and input param names.
+ * binding between input data (AlignmentI, SequenceGroup, NJTree) and input
+ * param names.
*/
- private Hashtable<String,Object> inputData=new Hashtable<String,Object>();
+ private Hashtable<String, Object> inputData = new Hashtable<String, Object>();
+
/**
* is the job fully submitted to server and apparently in progress ?
*/
- public boolean running=false;
+ public boolean running = false;
+
/**
*
* @param itypes
- * @param al - reference to object to be stored as input. Note - input data may be modifed by formatter
+ * @param al
+ * - reference to object to be stored as input. Note - input data may
+ * be modifed by formatter
*/
- public void setAlignmentForInputs(Collection<InputType> itypes, AlignmentI al)
+ public void setAlignmentForInputs(Collection<InputType> itypes,
+ AlignmentI al)
{
- for (InputType itype: itypes) {
+ for (InputType itype : itypes)
+ {
if (!rsd.inputParams.values().contains(itype))
{
- throw new IllegalArgumentException("InputType "+itype.getClass()+
- " is not valid for service at "+rsd.postUrl);
+ throw new IllegalArgumentException("InputType " + itype.getClass()
+ + " is not valid for service at " + rsd.postUrl);
}
if (itype instanceof AlignmentProcessor)
{
- ((AlignmentProcessor)itype).prepareAlignment(al);
+ ((AlignmentProcessor) itype).prepareAlignment(al);
}
// stash a reference for recall when the alignment data is formatted
inputData.put(itype.token, al);
}
-
+
}
+
/**
*
* @param token
* @return alignment object bound to the given token
* @throws NoValidInputDataException
*/
- public AlignmentI getAlignmentForInput(String token, InputType.molType type) throws NoValidInputDataException
+ public AlignmentI getAlignmentForInput(String token,
+ InputType.molType type) throws NoValidInputDataException
{
Object al = inputData.get(token);
// can we form an alignment from this data ?
- if (al==null || !(al instanceof AlignmentI))
+ if (al == null || !(al instanceof AlignmentI))
{
- throw new NoValidInputDataException("No alignment data bound to input '"+token+"' for service at "+rsd.postUrl);
+ throw new NoValidInputDataException(
+ "No alignment data bound to input '" + token
+ + "' for service at " + rsd.postUrl);
}
return (AlignmentI) al;
}
/**
* test to see if the job has data of type cl that's needed for the job to run
+ *
* @param cl
* @return true or false
*/
public boolean hasDataOfType(Class cl)
{
- if (AlignmentI.class.isAssignableFrom(cl)) {
+ if (AlignmentI.class.isAssignableFrom(cl))
+ {
return true;
}
- // TODO: add more source data types
-
+ // TODO: add more source data types
+
return false;
}
+ /**
+ * context used to parse results from service
+ */
+ JalviewDataset context = null;
+
+ Object[] jvresultobj = null;
+
+ /**
+ * process the results obtained from the server into jalview datamodel objects
+ * ready to be merged/added to the users' view.
+ */
+ public void parseResultSet() throws Exception, Error
+ {
+ jvresultobj = resSet.parseResultSet();
+ }
+
}