[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Fri Apr 16 17:33:26 UTC 2010
gordonp
Fri Apr 16 13:33:25 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv15287/src/main/ca/ucalgary/seahawk/gui
Modified Files:
MobyContentPane.java MobyPayloadCreator.java
MobyServicesGUI.java
Log Message:
First fully functional version of 'for each' service invocation in Seahawk
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.28,1.29 MobyPayloadCreator.java,1.2,1.3 MobyServicesGUI.java,1.19,1.20
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2010/04/14 23:48:27 1.28
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2010/04/16 17:33:25 1.29
@@ -1175,9 +1175,23 @@
String docFragID = targetURL.getRef(); // We store the xpath in the anchor part of the URL
- // Complex case, load the doc fragment from the MOBY XML source file
+ // Complex case, load the doc fragment from the MOBY XML source file
+ // where the targetURL is url#xptr with xptr like /1/2/1/1
if(docFragID != null && docFragID.length() > 0 && !targetURL.getHost().equals("moby")){
- return DataUtils.loadMobyDataFromXPointer(targetURL, filteredData, filterHistory.get(getCurrentURL()));
+ URL currentURL = null;
+ try{currentURL = new URL(targetURL.toString().replaceAll("#"+targetURL.getRef(), ""));}
+ catch(Exception e){
+ logger.error("Couldn't extract referenceless URL from " + targetURL, e);
+ }
+ // refers to currently loaded doc
+ if(currentURL.equals(getCurrentURL())){
+ return DataUtils.loadMobyDataFromXPointer(currentURL, getCurrentDoc(), docFragID,
+ filteredData, filterHistory.get(getCurrentURL()));
+ }
+ // refers to another moby doc, let DataUtils resolve the doc for us
+ else{
+ return DataUtils.loadMobyDataFromXPointer(targetURL, filteredData, filterHistory.get(getCurrentURL()));
+ }
}
// Simple case, build the object using the values encoded in the URL itself.
@@ -1218,7 +1232,7 @@
for(String peerMode: new String[]{DataUtils.ARTICLE_PEERS_MODE, DataUtils.DATATYPE_PEERS_MODE}){
// note that getPeerElements() will modify the userData to reflect the semantic of the requested peer mode
mobyData.setUserData(origUserData);
- NodeList peerElements = DataUtils.getPeerElements(getCurrentDoc(), mobyData, peerMode);
+ NodeList peerElements = DataUtils.getPeerElements(getCurrentDoc(), mobyData, getFilteredData(), peerMode);
if(peerElements.getLength() <= 1){
continue; // no 'for each' option if only one to process...
}
@@ -1227,21 +1241,33 @@
each += " '"+mobyData.getName()+"'";
}
MobyDataType dataType = ((MobyPrimaryData) mobyData).getDataType();
+ MobyNamespace[] namespaces = ((MobyPrimaryData) mobyData).getNamespaces();
if(mobyData instanceof MobyPrimaryDataSet){ // Collection
servicesGUI.addPopupOptions((MobyPrimaryDataSet) mobyData, popup, true, getDefaultHandler(),
new MobyPayloadCreator(this, (String) mobyData.getUserData()),
each);
}
else if(MobyTags.MOBYOBJECT.equals(dataType.getName())){
- MobyNamespace namespace = null;
- servicesGUI.addPopupOptions(namespace, popup, true, getDefaultHandler(),
- new MobyPayloadCreator(this, (String) mobyData.getUserData()),
- each);
+ if(namespaces != null && namespaces.length > 0){
+ servicesGUI.addPopupOptions(namespaces[0], popup, true, getDefaultHandler(),
+ new MobyPayloadCreator(this, (String) mobyData.getUserData()),
+ each);
+ }
+ //else base object wth no namespace...useless!
}
else{
- servicesGUI.addPopupOptions(dataType, popup, true, getDefaultHandler(),
- new MobyPayloadCreator(this, (String) mobyData.getUserData()),
- each);
+ // A non-base object, with a namespace too
+ if(namespaces != null && namespaces.length > 0){
+ ((MobyPrimaryDataSimple) mobyData).setId(""); //anonymize
+ servicesGUI.addPopupOptions((MobyPrimaryDataSimple) mobyData, popup, true, getDefaultHandler(),
+ new MobyPayloadCreator(this, (String) mobyData.getUserData()),
+ each);
+ }
+ else{ //just the data type useful
+ servicesGUI.addPopupOptions(dataType, popup, true, getDefaultHandler(),
+ new MobyPayloadCreator(this, (String) mobyData.getUserData()),
+ each);
+ }
}
}
@@ -1286,13 +1312,21 @@
if(getFilter() == null){
return;
}
+ String[] userData = mdi.getUserData() == null ? null :
+ mdi.getUserData().toString().split("\t");
+ // second user data arg is
+ Node mdiNode = userData == null || userData.length < 2 ? null :
+ XPointerResolver.getNodeFromXPointer(getCurrentDoc(), userData[1]);
//System.err.println("Should create a previous input menu item for " + mdi.getUserData());
try{
Document srcDoc = DataUtils.docBuilder.parse(srcURL.openStream());
+ //System.err.println("Context node is "+mdiNode+ " from user data" + mdi.getUserData());
// Get the input data for the *previous* service
- MobyDataJob inputData = DataUtils.getInputSample(srcDoc, SeahawkOptions.getRegistry());
+ MobyDataJob inputData = DataUtils.getInputSample(srcDoc,
+ DataUtils.findMobyJobName(mdiNode),
+ SeahawkOptions.getRegistry());
if(inputData == null){
// should only happen if Moby XML was loaded manually by a user, otherwise we've recorded this info...
logger.warn("No previous service info in Moby XML, 'previous input' option will not be displayed");
@@ -1529,7 +1563,7 @@
// Gray out the mismatched textual data
for(Map.Entry<String,String> dataToFilter: filteredData.entrySet()){
- System.err.println("Filtering "+dataToFilter.getKey());
+ //System.err.println("Filtering "+dataToFilter.getKey());
javax.swing.text.AbstractDocument.AbstractElement htmlDiv =
(javax.swing.text.AbstractDocument.AbstractElement) d.getElement(dataToFilter.getKey());
if(htmlDiv == null){
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyPayloadCreator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyPayloadCreator.java 2010/04/14 23:48:27 1.2
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyPayloadCreator.java 2010/04/16 17:33:25 1.3
@@ -27,6 +27,7 @@
// The request key is the sample data's app context:
// url#xpath <tab> sample_xptr <tab> filter_regex <tab> filter_xpath <tab> xpath_desc <tab> case_sensitive_boolean <tab> inverse selection
// from which we will build the peer dataset to submit.
+ System.err.println("Request key is " + requestKey);
String[] requestKeyFields = requestKey.split("\t");
String[] requestParts = requestKeyFields[0].split("#", 2);
@@ -50,20 +51,24 @@
Map<String,String> xptrsToFilter = new HashMap<String,String>();
FilterSearch filter = null;
// Was there a filter in the request?
- if(requestKeyFields.length >= 6){
- filter = new FilterSearch(requestKeyFields[1],
- new XPathOption(requestKeyFields[2], requestKeyFields[3]),
- Boolean.parseBoolean(requestKeyFields[4]),
- Boolean.parseBoolean(requestKeyFields[5]));
+ if(requestKeyFields.length >= 7){
+ filter = new FilterSearch(requestKeyFields[2],
+ new XPathOption(requestKeyFields[3], requestKeyFields[4]),
+ Boolean.parseBoolean(requestKeyFields[5]),
+ Boolean.parseBoolean(requestKeyFields[6]));
}
Document doc = null;
// Get the list of nodes to filter, using in-memory data if possible
if(targetURL.equals(srcPane.getCurrentURL())){
doc = srcPane.getCurrentDoc();
- if(filter.equals(srcPane.getFilter())){
+ if(filter == null){
+ xptrsToFilter = null;
+ }
+ else if(filter.equals(srcPane.getFilter())){
// no need to redo the filtering, it's the current display's filtering
- xptrsToFilter = srcPane.getFilteredData();
+ System.err.println("Reusing current filter");
+ xptrsToFilter = srcPane.getFilteredData();
}
else{
// we have the doc loaded, but the filter has changed since
@@ -75,44 +80,33 @@
doc = DataUtils.findFilteredNodes(targetURL, filter, xptrsToFilter);
}
- // Get the valid parts of the doc for forwarding.
- if(!xptrsToFilter.isEmpty()){
- if(doc == srcPane.getCurrentDoc()){
- // clone, because it'll be edited below by the filter, and we don't want to mess up currentDoc...
- doc = (Document) srcPane.getCurrentDoc().cloneNode(true);
- }
- DataUtils.filterDoc(doc, xptrsToFilter);
- }
+ MobyDataInstance mobyDataContext = new MobyDataObject("whatever");
+ mobyDataContext.setUserData(requestKey);
+ NodeList peerElements = DataUtils.getPeerElements(doc, mobyDataContext,
+ xptrsToFilter, DataUtils.DATATYPE_PEERS_MODE);
- // find the peers of templateElement and put them into a MobyContentInstance
+ // find the peers of defined by the userData selection constraints and put them into a MobyContentInstance
MobyContentInstance payload = new MobyContentInstance();
Map<String,Integer> jobPrefixes = new LinkedHashMap<String,Integer>();
- NodeList peerElements = null;
- try{
- peerElements = (NodeList) DataUtils.xPathFactory.newXPath().evaluate(selectionXPath,
- doc,
- XPathConstants.NODESET);
- } catch(Exception e){
- logger.log(Level.SEVERE, "Could not select nodes from "+targetURL+" with XPath " + selectionXPath, e);
- return null;
- }
+ System.err.println("Loading MobyContentInstance with "+peerElements.getLength()+" elements for xpath "+selectionXPath);
for(int i = 0; i < peerElements.getLength(); i++){
Element peerElement = (Element) peerElements.item(i);
// Try to make the job names trackable to the inputs:
// Name the jobs according to their original job + a iterated number suffix, e.g. originatingJob_1, originatingJob_2
String jobKey = DataUtils.findMobyJobName(peerElement);
if(!jobPrefixes.containsKey(jobKey)){
+ jobPrefixes.put(jobKey, new Integer(1));
if(peerElements.getLength() > 1){
jobKey += "_1"; // only add a suffix if multiple loop members for the job
}
- jobPrefixes.put(jobKey, new Integer(1));
}
else{
int suffixCount = jobPrefixes.get(jobKey).intValue();
- jobKey += "_"+suffixCount;
jobPrefixes.put(jobKey, new Integer(suffixCount+1));
+ jobKey += "_"+(suffixCount+1);
}
+ System.err.println("Adding job "+jobKey+" for "+peerElement.getLocalName());
MobyDataInstance mdi = null;
try{
mdi = MobyDataObject.createInstanceFromDOM(peerElement, SeahawkOptions.getRegistry());
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java 2010/04/14 23:48:27 1.19
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java 2010/04/16 17:33:25 1.20
@@ -182,9 +182,13 @@
return handler;
}
- // synchronized so simultaneous requests don't get their input data mixed up
+ /**
+ * Called when the 'Execute Service' button in the secondary input dialog in pushed.
+ * Section synchronized so simultaneous requests don't get their input data mixed up
+ */
public void setupServiceSecondaryData(MobyRequestEventHandler handler){
MobyDataInstance[] castInputs = new MobyDataInstance[primaryInput.length];
+ MobyContentInstance mci = null;
for(int i = 0; i < primaryInput.length; i++){
if(!(primaryInput[i] instanceof MobyDataInstance)){
logger.warn("Warning: setupServiceSecondaryData was called before the primary input" +
@@ -192,13 +196,34 @@
" of class "+primaryInput[i].getClass().getName());
return;
}
- castInputs[i] = (MobyDataInstance) primaryInput[i];
+ // Is one of the params a 'for each'
+ if(primaryInput[i] instanceof MobyContentCreator){
+ mci = ((MobyContentCreator) primaryInput[i]).getAllContents(primaryInput[i].getName());
+ }
+ else{
+ castInputs[i] = (MobyDataInstance) primaryInput[i];
+ }
+ }
+ // Cross product of single value primary params with param that is a content creator array
+ if(mci != null){
+ for(MobyDataJob job: mci.values()){
+ for(int i = 0; i < castInputs.length; i++){
+ if(castInputs[i] != null){
+ job.put(castInputs[i].getName(), castInputs[i]);
+ }
+ }
+ }
}
// code from mobyRequest.setInput() to executeService() should always be synced to avoid input mixup between requests
synchronized(mobyRequest){
try{
- mobyRequest.setInput(castInputs);
+ if(mci != null){
+ mobyRequest.setInput(mci);
+ }
+ else{
+ mobyRequest.setInput(castInputs);
+ }
mobyRequest.setSecondaryInput(secondaryInputInstances);
} catch(MobyException me){
me.printStackTrace();
@@ -224,8 +249,13 @@
// code from mobyRequest.setInput() to executeService() should always be synced to avoid input mixup between requests
synchronized(mobyRequest){
try{
+ if(mdi instanceof MobyContentCreator){
+ mobyRequest.setInput(((MobyContentCreator) mdi).getAllContents(primaryInput[0].getName()));
+ }
// Implement simple input (i.e. only one input argument)
- mobyRequest.setInput(mdi, "");
+ else{
+ mobyRequest.setInput(mdi, "");
+ }
}
catch(MobyException me){
logger.error("Failure in MOBY input, was not acceptable:" + me);
@@ -539,7 +569,7 @@
addPopupOptions(mobyData, popupList, false, handler, payloadCreator, extraMenuText);
}
else{
- logger.warn("Warning: OptionLoaderThread has no data to work with");
+ logger.warn("Warning: OptionLoaderThread has no data to work with", new Exception("Arrggh"));
}
}
}
@@ -646,27 +676,27 @@
MobyDataServiceAssocInstance serviceAssocObject = null;
// //Services for only the one piece of data
try{
- if(mobyData instanceof MobyDataObjectSet){
- serviceAssocObject = mobyClient.getServices((MobyDataObjectSet) mobyData);
- }
- else if(mobyData instanceof MobyDataObject){
- serviceAssocObject = mobyClient.getServices((MobyDataObject) mobyData);
- }
// The data will be loaded later
- else if(payloadCreator != null){
+ if(payloadCreator != null){
try{
if(mobyData instanceof MobyPrimaryDataSet){
serviceAssocObject = mobyClient.getServices(new MobyDataObjectSetDeferred((MobyPrimaryDataSet) mobyData,
payloadCreator));
}
- else if(mobyData instanceof MobyNamespace){
- serviceAssocObject = mobyClient.getServices(new MobyDataObjectDeferred((MobyNamespace) mobyData,
+ else if(mobyData instanceof MobyPrimaryDataSimple){ // pass in if datatype and namespace are useful
+ serviceAssocObject = mobyClient.getServices(new MobyDataObjectDeferred(((MobyPrimaryDataSimple) mobyData).getDataType(),
+ ((MobyPrimaryDataSimple) mobyData).getNamespaces()[0],
payloadCreator));
}
else if(mobyData instanceof MobyDataType){
serviceAssocObject = mobyClient.getServices(new MobyDataObjectDeferred((MobyDataType) mobyData,
payloadCreator));
}
+ else if(mobyData instanceof MobyNamespace){
+ System.err.println("Creating deferred dataset payload");
+ serviceAssocObject = mobyClient.getServices(new MobyDataObjectDeferred((MobyNamespace) mobyData,
+ payloadCreator));
+ }
else{
logger.warn("Ignoring unrecognized template class (" + mobyData.getClass().getName()+
") for deferred data creation by a MobyPayloadRequestListener");
@@ -675,6 +705,12 @@
} catch(Exception e){
logger.error("Could not create deferred Moby data object", e);
}
+ }
+ else if(mobyData instanceof MobyDataObjectSet){
+ serviceAssocObject = mobyClient.getServices((MobyDataObjectSet) mobyData);
+ }
+ else if(mobyData instanceof MobyDataObject){
+ serviceAssocObject = mobyClient.getServices((MobyDataObject) mobyData);
}
else{
logger.warn("Service options for objects other than MobyDataObject " +
@@ -730,9 +766,6 @@
logger.warn("Cannot add service options, cannot find " +
"parent moby object index for submenu " +
submenu.getText());
- System.err.println("Cannot add service options, cannot find " +
- "parent moby object index for submenu " +
- submenu.getText());
return;
}
dataIndex = ((Integer) submenu2msIndex.get(parent)).intValue();
@@ -1250,7 +1283,7 @@
datatype += " collection";
}
submenu = new JMenu("<html>Services for " + (extraMenuText == null ? "" : extraMenuText+" ") +
- datatype + (id == null ? "" : ":" + id)+"</html>");
+ "<font color='red'>"+datatype + "</font>" + (id == null ? "" : ":" + id)+"</html>");
assignMenuDataIndex(submenu);
}
else if(MobyTags.MOBYSTRING.equals(mobyDataType.getName())){
@@ -1269,7 +1302,7 @@
}
desc = "A piece of text";
submenu = new JMenu("<html>Services for "+(extraMenuText == null ? "" : extraMenuText+" ")+
- "String " + sample+"</html>");
+ "<font color='red'>String</font> " + sample+"</html>");
assignMenuDataIndex(submenu);
}
// Complex object
@@ -1283,17 +1316,19 @@
}
}
if(templateObject instanceof MobyDataObject && id != null && id.length() > 0){
- objectLabel += ":" + id;
+ objectLabel += "<font color='red'>"+objectLabel+"</font>:" + id;
}
else if(templateObject instanceof MobyDataObjectSet){
- objectLabel += " collection";
+ objectLabel = "<font color='red'>"+objectLabel+" collection</font>";
+ }
+ else{
+ objectLabel = "<font color='red'>"+objectLabel+"</font>";
}
submenu = new JMenu("<html>Services for " + (extraMenuText == null ? "" : extraMenuText+" ")+objectLabel+"</html>");
assignMenuDataIndex(submenu);
}
desc = "Input data: " + desc;
desc = HTMLUtils.htmlifyToolTipText(desc, MAX_SERVICE_DESC_LEN);
- System.err.println("New submenu has label " + submenu.getText());
submenu.setToolTipText(desc);
submenu.setName(SERVICE_SUBMENU_NAME);
return submenu;
More information about the MOBY-guts
mailing list