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. |