From: <rv...@us...> - 2009-06-23 13:04:11
|
Revision: 83 http://treebase.svn.sourceforge.net/treebase/?rev=83&view=rev Author: rvos Date: 2009-06-23 11:10:53 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Added download URL forwarding. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-23 11:10:17 UTC (rev 82) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-23 11:10:53 UTC (rev 83) @@ -73,8 +73,13 @@ } String prefix = pathComponents[1]; String fullyQualifiedId = pathComponents[2]; - String id = fullyQualifiedId.replaceAll(".*:[a-zA-Z]*",""); - url = createUrl(prefix,id); + String id = fullyQualifiedId.replaceAll(".*:[a-zA-Z]*",""); + if ( TreebaseUtil.isEmpty(req.getParameter("format")) ) { + url = createUrl(prefix,id); + } + else { + url = createDownloadUrl(prefix,id,req.getParameter("format")); + } } catch ( NumberFormatException e ) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string: " + e.getMessage()); } catch ( ObjectNotFoundException e ) { @@ -89,6 +94,60 @@ return null; } + private String createDownloadUrl(String prefix, String objectId, String format) throws Exception { + String url = ""; + StringBuffer base = new StringBuffer("/treebase-web/search"); + if ( prefix.equalsIgnoreCase("study") ) { + Long studyId = Long.parseLong(objectId); + Study study = getStudyService().findByID(studyId); + if ( study == null ) { + throw new ObjectNotFoundException("Can't find study " + studyId); + } + //return base + "/summary.html?id=" + objectId; + return base + .append("/downloadAStudy.html?id=") + .append(objectId) + .append("&format=") + .append(format) + .toString(); + } + else if ( prefix.equalsIgnoreCase("matrix") ) { + Long matrixId = Long.parseLong(objectId); + Matrix matrix = getMatrixService().findByID(matrixId); + if ( matrix == null ) { + throw new ObjectNotFoundException("Can't find matrix " + matrixId); + } + Study study = matrix.getStudy(); + //http://localhost:8080/treebase-web/search/downloadAMatrix.html?id=830&matrixid=263 + return base + .append("/downloadAMatrix.html?id=") + .append(study.getId()) + .append("&matrixid=") + .append(objectId) + .append("&format=") + .append(format) + .toString(); + } + else if ( prefix.equalsIgnoreCase("tree") ) { + Long treeId = Long.parseLong(objectId); + PhyloTree phyloTree = getPhyloTreeService().findByID(treeId); + if ( phyloTree == null ) { + throw new ObjectNotFoundException("Can't find tree " + treeId); + } + Study study = phyloTree.getStudy(); + //http://localhost:8080/treebase-web/search/downloadATree.html?id=830&treeid=3983 + return base + .append("/downloadATree.html?id=") + .append(study.getId()) + .append("&treeid=") + .append(objectId) + .append("&format=") + .append(format) + .toString(); + } + return url; + } + public MatrixService getMatrixService() { return mMatrixService; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-25 02:48:13
|
Revision: 111 http://treebase.svn.sourceforge.net/treebase/?rev=111&view=rev Author: rvos Date: 2009-06-25 02:48:12 +0000 (Thu, 25 Jun 2009) Log Message: ----------- Refactored to use TreebaseIDString and NamespacedGUID classes as opposed to direct ID string manipulation Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-25 02:45:59 UTC (rev 110) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-25 02:48:12 UTC (rev 111) @@ -6,7 +6,10 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +import org.cipres.treebase.NamespacedGUID; +import org.cipres.treebase.TreebaseIDString; import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.matrix.MatrixService; import org.cipres.treebase.domain.study.Study; @@ -20,31 +23,28 @@ private PhyloTreeService mPhyloTreeService; private StudyService mStudyService; - private String createUrl(String prefix, String objectId) throws Exception { + private String createUrl(String prefix, Long objectId) throws Exception { String url = ""; String base = "/treebase-web/search/study"; - if ( prefix.equalsIgnoreCase("study") ) { - Long studyId = Long.parseLong(objectId); - Study study = getStudyService().findByID(studyId); + if ( prefix.equals(TreebaseIDString.getPrefixForClass(Study.class)) ) { + Study study = getStudyService().findByID(objectId); if ( study == null ) { - throw new ObjectNotFoundException("Can't find study " + studyId); + throw new ObjectNotFoundException("Can't find study " + objectId); } return base + "/summary.html?id=" + objectId; } - else if ( prefix.equalsIgnoreCase("matrix") ) { - Long matrixId = Long.parseLong(objectId); - Matrix matrix = getMatrixService().findByID(matrixId); + else if ( prefix.equals(TreebaseIDString.getPrefixForClass(Matrix.class)) ) { + Matrix matrix = getMatrixService().findByID(objectId); if ( matrix == null ) { - throw new ObjectNotFoundException("Can't find matrix " + matrixId); + throw new ObjectNotFoundException("Can't find matrix " + objectId); } Study study = matrix.getStudy(); return base + "/matrix.html?id=" + study.getId() + "&matrixid=" + objectId; } - else if ( prefix.equalsIgnoreCase("tree") ) { - Long treeId = Long.parseLong(objectId); - PhyloTree phyloTree = getPhyloTreeService().findByID(treeId); + else if ( prefix.equals(TreebaseIDString.getPrefixForClass(PhyloTree.class)) ) { + PhyloTree phyloTree = getPhyloTreeService().findByID(objectId); if ( phyloTree == null ) { - throw new ObjectNotFoundException("Can't find tree " + treeId); + throw new ObjectNotFoundException("Can't find tree " + objectId); } Study study = phyloTree.getStudy(); return base + "/tree.html?id=" + study.getId() + "&treeid=" + objectId; @@ -62,25 +62,28 @@ throw new InvalidRequestException( "Invalid request '" + pathInfo - + "', should be /${class}/${id}"); + + "', should be /${NamespacedGUID}"); } String[] pathComponents = pathInfo.split("/"); - if ( pathComponents.length != 3 ) { + if ( pathComponents.length != 2 ) { throw new InvalidRequestException( "Invalid request '" + pathInfo - + "', should be /${class}/${id}"); + + "', should be /${NamespacedGUID}"); } - String prefix = pathComponents[1]; - String fullyQualifiedId = pathComponents[2]; - String id = fullyQualifiedId.replaceAll(".*:[a-zA-Z]*",""); - if ( TreebaseUtil.isEmpty(req.getParameter("format")) ) { - url = createUrl(prefix,id); + String[] idComponents = pathComponents[1].split("\\."); + NamespacedGUID namespacedGUID = new NamespacedGUID(idComponents[0]); + TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); + if ( idComponents.length >= 2 && idComponents[1].equals("html") ) { + url = createUrl(tbID.getTypePrefix(),tbID.getId()); } + else if ( idComponents.length >= 2 ) { + url = createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),idComponents[1]); + } else { - url = createDownloadUrl(prefix,id,req.getParameter("format")); + url = "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); } - } catch ( NumberFormatException e ) { + } catch ( MalformedTreebaseIDString e ) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string: " + e.getMessage()); } catch ( ObjectNotFoundException e ) { res.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); @@ -93,32 +96,31 @@ } return null; } - - private String createDownloadUrl(String prefix, String objectId, String format) throws Exception { + + private String createDownloadUrl(String prefix, Long objectId, String format) throws Exception { + if ( format.equals("xml") ) { + format = "nexml"; + } String url = ""; StringBuffer base = new StringBuffer("/treebase-web/search"); - if ( prefix.equalsIgnoreCase("study") ) { - Long studyId = Long.parseLong(objectId); - Study study = getStudyService().findByID(studyId); + if ( prefix.equals(TreebaseIDString.getPrefixForClass(Study.class)) ) { + Study study = getStudyService().findByID(objectId); if ( study == null ) { - throw new ObjectNotFoundException("Can't find study " + studyId); + throw new ObjectNotFoundException("Can't find study " + objectId); } - //return base + "/summary.html?id=" + objectId; return base .append("/downloadAStudy.html?id=") .append(objectId) .append("&format=") .append(format) - .toString(); + .toString(); } - else if ( prefix.equalsIgnoreCase("matrix") ) { - Long matrixId = Long.parseLong(objectId); - Matrix matrix = getMatrixService().findByID(matrixId); + else if ( prefix.equals(TreebaseIDString.getPrefixForClass(Matrix.class)) ) { + Matrix matrix = getMatrixService().findByID(objectId); if ( matrix == null ) { - throw new ObjectNotFoundException("Can't find matrix " + matrixId); + throw new ObjectNotFoundException("Can't find matrix " + objectId); } Study study = matrix.getStudy(); - //http://localhost:8080/treebase-web/search/downloadAMatrix.html?id=830&matrixid=263 return base .append("/downloadAMatrix.html?id=") .append(study.getId()) @@ -126,16 +128,14 @@ .append(objectId) .append("&format=") .append(format) - .toString(); + .toString(); } - else if ( prefix.equalsIgnoreCase("tree") ) { - Long treeId = Long.parseLong(objectId); - PhyloTree phyloTree = getPhyloTreeService().findByID(treeId); + else if ( prefix.equals(TreebaseIDString.getPrefixForClass(PhyloTree.class)) ) { + PhyloTree phyloTree = getPhyloTreeService().findByID(objectId); if ( phyloTree == null ) { - throw new ObjectNotFoundException("Can't find tree " + treeId); + throw new ObjectNotFoundException("Can't find tree " + objectId); } Study study = phyloTree.getStudy(); - //http://localhost:8080/treebase-web/search/downloadATree.html?id=830&treeid=3983 return base .append("/downloadATree.html?id=") .append(study.getId()) @@ -143,7 +143,7 @@ .append(objectId) .append("&format=") .append(format) - .toString(); + .toString(); } return url; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-28 10:18:04
|
Revision: 142 http://treebase.svn.sourceforge.net/treebase/?rev=142&view=rev Author: rvos Date: 2009-06-28 10:17:15 +0000 (Sun, 28 Jun 2009) Log Message: ----------- Added redirect for uBio and NCBI namespaced GUIDs Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-28 10:15:53 UTC (rev 141) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-28 10:17:15 UTC (rev 142) @@ -18,10 +18,14 @@ import org.cipres.treebase.domain.tree.PhyloTreeService; public class PhyloWSController implements Controller { + private static String ncbiBaseUrl = "http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id="; + private static String uBioBaseUrl = "http://www.ubio.org/browser/details.php?namebankID="; private static final long serialVersionUID = 1L; private MatrixService mMatrixService; private PhyloTreeService mPhyloTreeService; private StudyService mStudyService; + private static String format = "format"; + private static String[] classesWithPages = { "tree", "study", "matrix" }; private String createUrl(String prefix, Long objectId) throws Exception { String url = ""; @@ -62,26 +66,33 @@ throw new InvalidRequestException( "Invalid request '" + pathInfo - + "', should be /${NamespacedGUID}"); + + "', should be /${class}/${NamespacedGUID}"); } String[] pathComponents = pathInfo.split("/"); - if ( pathComponents.length != 2 ) { - throw new InvalidRequestException( - "Invalid request '" - + pathInfo - + "', should be /${NamespacedGUID}"); + String rawNamespacedGUID = pathComponents[pathComponents.length-1]; + if ( rawNamespacedGUID.startsWith("uBio:") ) { + url = uBioBaseUrl + rawNamespacedGUID.substring("uBio:".length()); } - String[] idComponents = pathComponents[1].split("\\."); - NamespacedGUID namespacedGUID = new NamespacedGUID(idComponents[0]); - TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); - if ( idComponents.length >= 2 && idComponents[1].equals("html") ) { - url = createUrl(tbID.getTypePrefix(),tbID.getId()); - } - else if ( idComponents.length >= 2 ) { - url = createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),idComponents[1]); - } + else if ( rawNamespacedGUID.startsWith("NCBI:") ) { + url = ncbiBaseUrl + rawNamespacedGUID.substring("NCBI:".length()); + } else { - url = "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + NamespacedGUID namespacedGUID = new NamespacedGUID(rawNamespacedGUID); + TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); + if ( hasWebPage(pathComponents) ) { + if ( TreebaseUtil.isEmpty(req.getParameter(format)) ) { + url = "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + } + else if ( req.getParameter(format).equals("html") ) { + url = createUrl(tbID.getTypePrefix(),tbID.getId()); + } + else { + url = createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),req.getParameter(format)); + } + } + else { + url = "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + } } } catch ( MalformedTreebaseIDString e ) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string: " + e.getMessage()); @@ -91,11 +102,22 @@ res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } if ( ! TreebaseUtil.isEmpty(url) ) { - res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + res.setStatus(HttpServletResponse.SC_FOUND); res.setHeader("Location", url); } return null; } + + private boolean hasWebPage(String[] pathComponents) { + for ( int i = ( pathComponents.length - 1 ); i >= 0; i-- ) { + for ( int j = 0; j < classesWithPages.length; j++ ) { + if ( pathComponents[i].equals(classesWithPages[j]) ) { + return true; + } + } + } + return false; + } private String createDownloadUrl(String prefix, Long objectId, String format) throws Exception { if ( format.equals("xml") ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-28 11:56:32
|
Revision: 153 http://treebase.svn.sourceforge.net/treebase/?rev=153&view=rev Author: rvos Date: 2009-06-28 11:56:30 +0000 (Sun, 28 Jun 2009) Log Message: ----------- Changed redirect response code to SEE OTHER (303) Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-28 11:49:36 UTC (rev 152) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-06-28 11:56:30 UTC (rev 153) @@ -103,7 +103,7 @@ res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } if ( ! TreebaseUtil.isEmpty(url) ) { - res.setStatus(HttpServletResponse.SC_FOUND); + res.setStatus(HttpServletResponse.SC_SEE_OTHER); res.setHeader("Location", url); } return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-07-06 08:41:03
|
Revision: 175 http://treebase.svn.sourceforge.net/treebase/?rev=175&view=rev Author: rvos Date: 2009-07-06 08:41:02 +0000 (Mon, 06 Jul 2009) Log Message: ----------- Now throws 404 instead of NPE when study not found Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-07-06 08:37:02 UTC (rev 174) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-07-06 08:41:02 UTC (rev 175) @@ -162,6 +162,9 @@ throw new ObjectNotFoundException("Can't find matrix " + objectId); } Study study = matrix.getStudy(); + if ( study == null ) { + throw new ObjectNotFoundException("Can't find study for matrix "+objectId); + } return base .append("/downloadAMatrix.html?id=") .append(study.getId()) @@ -177,6 +180,9 @@ throw new ObjectNotFoundException("Can't find tree " + objectId); } Study study = phyloTree.getStudy(); + if ( study == null ) { + throw new ObjectNotFoundException("Can't find study for tree "+objectId); + } return base .append("/downloadATree.html?id=") .append(study.getId()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-01-12 17:28:36
|
Revision: 418 http://treebase.svn.sourceforge.net/treebase/?rev=418&view=rev Author: rvos Date: 2010-01-12 17:28:29 +0000 (Tue, 12 Jan 2010) Log Message: ----------- The PhyloWSController now stores the x-access-granted QUERY_STRING parameter as a session variable so that it can be referred to by other pages in the same session. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-01-12 17:23:04 UTC (rev 417) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-01-12 17:28:29 UTC (rev 418) @@ -16,6 +16,7 @@ import org.cipres.treebase.domain.study.StudyService; import org.cipres.treebase.domain.tree.PhyloTree; import org.cipres.treebase.domain.tree.PhyloTreeService; +import org.cipres.treebase.web.Constants; public class PhyloWSController implements Controller { private static String ncbiBaseUrl = "http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id="; @@ -61,6 +62,11 @@ res.setContentType("text/plain"); String url = null; String domain = "http://" + req.getServerName() + ":" + req.getServerPort(); + if ( ! TreebaseUtil.isEmpty(req.getParameter(Constants.X_ACCESS_CODE)) ) { + req.getSession().setAttribute( + Constants.X_ACCESS_CODE, + req.getParameter(Constants.X_ACCESS_CODE)); + } try { String pathInfo = req.getPathInfo(); if ( TreebaseUtil.isEmpty(pathInfo) ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-01-15 12:41:39
|
Revision: 443 http://treebase.svn.sourceforge.net/treebase/?rev=443&view=rev Author: rvos Date: 2010-01-15 12:41:32 +0000 (Fri, 15 Jan 2010) Log Message: ----------- Added x-access-code parameter to phylows redirect Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-01-15 12:18:59 UTC (rev 442) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-01-15 12:41:32 UTC (rev 443) @@ -28,15 +28,30 @@ private static String format = "format"; private static String[] classesWithPages = { "tree", "study", "matrix" }; - private String createUrl(String prefix, Long objectId) throws Exception { + private String createUrl(String prefix, Long objectId,HttpServletRequest request) throws Exception { String url = ""; - String base = "/treebase-web/search/study"; + StringBuffer base = new StringBuffer("/treebase-web/search/study"); if ( prefix.equals(TreebaseIDString.getPrefixForClass(Study.class)) ) { Study study = getStudyService().findByID(objectId); if ( study == null ) { throw new ObjectNotFoundException("Can't find study " + objectId); - } - return base + "/summary.html?id=" + objectId; + } + if ( ! TreebaseUtil.isEmpty(request.getParameter(Constants.X_ACCESS_CODE))) { + return base + .append("/summary.html?id=") + .append(objectId) + .append('&') + .append(Constants.X_ACCESS_CODE) + .append('=') + .append(request.getParameter(Constants.X_ACCESS_CODE)) + .toString(); + } + else { + return base + .append("/summary.html?id=") + .append(objectId) + .toString(); + } } else if ( prefix.equals(TreebaseIDString.getPrefixForClass(Matrix.class)) ) { Matrix matrix = getMatrixService().findByID(objectId); @@ -44,7 +59,12 @@ throw new ObjectNotFoundException("Can't find matrix " + objectId); } Study study = matrix.getStudy(); - return base + "/matrix.html?id=" + study.getId() + "&matrixid=" + objectId; + return base + .append("/matrix.html?id=") + .append(study.getId()) + .append("&matrixid=") + .append(objectId) + .toString(); } else if ( prefix.equals(TreebaseIDString.getPrefixForClass(PhyloTree.class)) ) { PhyloTree phyloTree = getPhyloTreeService().findByID(objectId); @@ -52,7 +72,12 @@ throw new ObjectNotFoundException("Can't find tree " + objectId); } Study study = phyloTree.getStudy(); - return base + "/tree.html?id=" + study.getId() + "&treeid=" + objectId; + return base + .append("/tree.html?id=") + .append(study.getId()) + .append("&treeid=") + .append(objectId) + .toString(); } return url; } @@ -94,7 +119,7 @@ url = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); } else if ( req.getParameter(format).equals("html") ) { - url = domain + createUrl(tbID.getTypePrefix(),tbID.getId()); + url = domain + createUrl(tbID.getTypePrefix(),tbID.getId(),req); } else { url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),req.getParameter(format)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-02-12 07:22:00
|
Revision: 496 http://treebase.svn.sourceforge.net/treebase/?rev=496&view=rev Author: rvos Date: 2010-02-12 07:21:53 +0000 (Fri, 12 Feb 2010) Log Message: ----------- Added placeholder method for content-negotiation Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-02-12 04:41:13 UTC (rev 495) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-02-12 07:21:53 UTC (rev 496) @@ -106,24 +106,25 @@ url = domain + createSearchUrl(pathComponents[pathComponents.length-2],req); } else { String rawNamespacedGUID = pathComponents[pathComponents.length-1]; - if ( rawNamespacedGUID.startsWith("uBio:") ) { + if ( rawNamespacedGUID.startsWith("uBio:") ) { // XXX be polite, use real URL url = uBioBaseUrl + rawNamespacedGUID.substring("uBio:".length()); } - else if ( rawNamespacedGUID.startsWith("NCBI:") ) { + else if ( rawNamespacedGUID.startsWith("NCBI:") ) { // XXX be polite, use real URL url = ncbiBaseUrl + rawNamespacedGUID.substring("NCBI:".length()); } else { NamespacedGUID namespacedGUID = new NamespacedGUID(rawNamespacedGUID); TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); if ( hasWebPage(pathComponents) ) { - if ( TreebaseUtil.isEmpty(req.getParameter(format)) ) { + String serializationFormat = createSerializationFormat(req); + if ( TreebaseUtil.isEmpty(serializationFormat) ) { url = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); } - else if ( req.getParameter(format).equals("html") ) { + else if ( serializationFormat.equals("html") ) { url = domain + createUrl(tbID.getTypePrefix(),tbID.getId(),req); } else { - url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),req.getParameter(format)); + url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),serializationFormat); } } else { @@ -145,6 +146,16 @@ return null; } + /** + * This is a placeholder method that might parse accept headers for content-negotiation + * one day + * @param request + * @return + */ + private String createSerializationFormat(HttpServletRequest request) { + return request.getParameter(format); + } + private String createSearchUrl(String path,HttpServletRequest request) { StringBuilder sb = new StringBuilder(); sb This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-03-12 23:29:59
|
Revision: 562 http://treebase.svn.sourceforge.net/treebase/?rev=562&view=rev Author: rvos Date: 2010-03-12 23:29:53 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Removed runtime-computed domain name and server port, which no longer work with the new tomcat configuration (would now compute "localhost"). Using relative URLs instead. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-03-12 23:27:28 UTC (rev 561) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2010-03-12 23:29:53 UTC (rev 562) @@ -26,11 +26,28 @@ private PhyloTreeService mPhyloTreeService; private StudyService mStudyService; private static String format = "format"; + + /* + * this array is used to identify whether a path fragment maps to an object + * for which web pages are available. Maybe this should be an enum or a map + * instead. + */ private static String[] classesWithPages = { "tree", "study", "matrix" }; + /** + * Given an object prefix ("tree", "study" or "matrix") and an object ID, constructs + * a relative URL to an HTML page about that object. + * @param prefix identifies either studies, matrices or trees + * @param objectId is the primary key for the requested object + * @param request is the servlet request, which we need to check for reviewer access + * @return a relative URL to an HTML page, or an empty string + * @throws Exception + */ private String createUrl(String prefix, Long objectId,HttpServletRequest request) throws Exception { String url = ""; StringBuffer base = new StringBuffer("/treebase-web/search/study"); + + // requested object is a study if ( prefix.equals(TreebaseIDString.getPrefixForClass(Study.class)) ) { Study study = getStudyService().findByID(objectId); if ( study == null ) { @@ -54,6 +71,8 @@ .toString(); } } + + // requested object is a matrix else if ( prefix.equals(TreebaseIDString.getPrefixForClass(Matrix.class)) ) { Matrix matrix = getMatrixService().findByID(objectId); if ( matrix == null ) { @@ -67,6 +86,8 @@ .append(objectId) .toString(); } + + // requested object is a tree else if ( prefix.equals(TreebaseIDString.getPrefixForClass(PhyloTree.class)) ) { PhyloTree phyloTree = getPhyloTreeService().findByID(objectId); if ( phyloTree == null ) { @@ -87,7 +108,7 @@ throws Exception { res.setContentType("text/plain"); String url = null; - String domain = "http://" + req.getServerName() + ":" + req.getServerPort(); + //String domain = "http://" + req.getServerName() + ":" + req.getServerPort(); if ( ! TreebaseUtil.isEmpty(req.getParameter(Constants.X_ACCESS_CODE)) ) { req.getSession().setAttribute( Constants.X_ACCESS_CODE, @@ -103,7 +124,8 @@ } String[] pathComponents = pathInfo.split("/"); if ( pathComponents[pathComponents.length-1].equals("find") ) { - url = domain + createSearchUrl(pathComponents[pathComponents.length-2],req); + //url = domain + createSearchUrl(pathComponents[pathComponents.length-2],req); + url = createSearchUrl(pathComponents[pathComponents.length-2],req); } else { String rawNamespacedGUID = pathComponents[pathComponents.length-1]; if ( rawNamespacedGUID.startsWith("uBio:") ) { // XXX be polite, use real URL @@ -118,17 +140,17 @@ if ( hasWebPage(pathComponents) ) { String serializationFormat = createSerializationFormat(req); if ( TreebaseUtil.isEmpty(serializationFormat) ) { - url = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + url = "/treebase-web/search/study/anyObjectAsRDF.rdf?namespacedGUID=" + namespacedGUID.toString(); } else if ( serializationFormat.equals("html") ) { - url = domain + createUrl(tbID.getTypePrefix(),tbID.getId(),req); + url = createUrl(tbID.getTypePrefix(),tbID.getId(),req); } else { - url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),serializationFormat); + url = createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),serializationFormat); } } else { - url = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + url = "/treebase-web/search/study/anyObjectAsRDF.rdf?namespacedGUID=" + namespacedGUID.toString(); } } } @@ -157,9 +179,8 @@ } private String createSearchUrl(String path,HttpServletRequest request) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder("/treebase-web/search/"); sb - .append("/treebase-web/search/") .append(path) .append("Search.html?query=") .append(request.getParameter("query")) @@ -170,6 +191,12 @@ return sb.toString(); } + /** + * Given an array of path fragments, returns whether an HTML web page + * exists for the type of object the fragments map onto + * @param pathComponents + * @return true of web page exists, false otherwise + */ private boolean hasWebPage(String[] pathComponents) { for ( int i = ( pathComponents.length - 1 ); i >= 0; i-- ) { for ( int j = 0; j < classesWithPages.length; j++ ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-04-25 22:15:25
|
Revision: 803 http://treebase.svn.sourceforge.net/treebase/?rev=803&view=rev Author: rvos Date: 2011-04-25 22:15:19 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Added more descriptive id parsing error message; not adding null parameters to new redirect string; only pruning one character from query string. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-25 21:54:29 UTC (rev 802) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-25 22:15:19 UTC (rev 803) @@ -75,7 +75,7 @@ url = createResourceUrl(namespacedGUID, req); } } catch ( MalformedTreebaseIDString e ) { - res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string: " + e.getMessage()); + res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string from path info '" + pathInfo + "' message: " + e.getMessage()); } catch ( ObjectNotFoundException e ) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Object not found: " + e.getMessage()); } @@ -127,9 +127,18 @@ StringBuffer sb = new StringBuffer(searchBase); sb.append(getSearchPage()); Map<String,String> params = new HashMap<String,String>(); - params.put("query", request.getParameter("query")); - params.put("format", createSerializationFormat(request)); - params.put("recordSchema", request.getParameter("recordSchema")); + String query = request.getParameter("query"); + if ( ! TreebaseUtil.isEmpty(query) ) { + params.put("query", query); + } + String format = createSerializationFormat(request); + if ( ! TreebaseUtil.isEmpty(format) ) { + params.put("format", format); + } + String recordSchema = request.getParameter("recordSchema"); + if ( ! TreebaseUtil.isEmpty(recordSchema) ) { + params.put("recordSchema", recordSchema); + } return createUrl(sb,params,request); } @@ -168,7 +177,7 @@ base.append(key).append('=').append(params.get(key)).append('&'); } String url = base.toString(); - return url.substring(0, url.length() - 2 ); + return url.substring(0, url.length() - 1 ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-04-25 22:28:05
|
Revision: 804 http://treebase.svn.sourceforge.net/treebase/?rev=804&view=rev Author: rvos Date: 2011-04-25 22:27:59 +0000 (Mon, 25 Apr 2011) Log Message: ----------- More pre-processing of the id string Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-25 22:15:19 UTC (rev 803) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-25 22:27:59 UTC (rev 804) @@ -53,8 +53,9 @@ url = createSearchUrl(req); } else { + String substr = pathInfo.replaceAll(".*/", ""); try { - NamespacedGUID namespacedGUID = new NamespacedGUID(pathInfo); + NamespacedGUID namespacedGUID = new NamespacedGUID(substr); TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); String serializationFormat = createSerializationFormat(req); if ( hasWebPage(tbID.getClass()) && ! TreebaseUtil.isEmpty(serializationFormat) ) { @@ -75,7 +76,7 @@ url = createResourceUrl(namespacedGUID, req); } } catch ( MalformedTreebaseIDString e ) { - res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string from path info '" + pathInfo + "' message: " + e.getMessage()); + res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad ID string from path info '" + substr + "' message: " + e.getMessage()); } catch ( ObjectNotFoundException e ) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Object not found: " + e.getMessage()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |