From: <rv...@us...> - 2009-06-23 14:21:02
|
Revision: 82 http://treebase.svn.sourceforge.net/treebase/?rev=82&view=rev Author: rvos Date: 2009-06-23 11:10:17 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Refactored to take advantage of AbstractDownloadController superclass. Commented out (but kept in place) all now superfluous code. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java Added Paths: ----------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -20,25 +20,26 @@ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.matrix.MatrixService; +import org.cipres.treebase.domain.nexus.NexusDataSet; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.study.StudyService; import org.cipres.treebase.domain.taxon.TaxonLabelSet; import org.cipres.treebase.web.util.ControllerUtil; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; /** * DownloadAMatrixController.java @@ -52,8 +53,8 @@ * */ -public class DownloadAMatrixController implements Controller { - private static final Logger LOGGER = Logger.getLogger(DownloadAMatrixController.class); +public class DownloadAMatrixController extends AbstractDownloadController implements Controller { + //private static final Logger LOGGER = Logger.getLogger(DownloadAMatrixController.class); private MatrixService mMatrixService; private StudyService mStudyService; @@ -103,7 +104,6 @@ // + request.getSession().getServletContext().getRealPath("/NexusFileDownload")); // System.out.println("PATH INFO: " + request.getPathInfo()); // - // TODO: if (request.getParameter("matrixid") == null) { return null; @@ -113,40 +113,29 @@ //Study s = getStudyService().findByID(studyId); long matrixId = Long.parseLong(request.getParameter("matrixid")); - String fileName = getFileName(matrixId); +// String fileName = getFileName(matrixId,request); - String downloadDir = request.getSession().getServletContext().getRealPath( - TreebaseUtil.FILESEP + "NexusFileDownload") - + TreebaseUtil.FILESEP + request.getRemoteUser(); +// String downloadDir = request.getSession().getServletContext().getRealPath( +// TreebaseUtil.FILESEP + "NexusFileDownload") +// + TreebaseUtil.FILESEP + request.getRemoteUser(); +// String downloadDir = getDownloadDir(request); - long start = System.currentTimeMillis(); +// long start = System.currentTimeMillis(); - generateAFileDynamically(request, matrixId, downloadDir); - WebUtil.downloadFile(response, downloadDir, fileName); + generateAFileDynamically(request, response, matrixId); +// WebUtil.downloadFile(response, downloadDir, fileName); - long end = System.currentTimeMillis(); +// long end = System.currentTimeMillis(); +// +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE IN DOWNLOAD A MATRIX CONTROLLER: " +// + (end - start)); +// } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE IN DOWNLOAD A MATRIX CONTROLLER: " - + (end - start)); - } - return null; // new ModelAndView("treeList", Constants.TREE_LIST, phyloTrees); } /** - * This method adds "M" as Prefix to the matrix ID and ".nex" as Suffix. - * - * @param id (Matrix id) - * @return returns the file name to be used for down loading - */ - - private String getFileName(long id) { - - return "M" + id + ".nex"; - } - - /** * This method is responsible for generating a Matrix file in a particular down load directory. * But first It should get All the Taxa associated with a Matrix id and get the max length of * the Taxon Labels and put Taxa and remaining matrix information in a separate ArrayLists @@ -155,7 +144,7 @@ * @param pMatrixId It is Matrix id. * @param downloadDirName down load directory where files will be created */ - + /* private void generateAFileDynamically(HttpServletRequest request, long pMatrixId, String downloadDirName) { Study pStudy = ControllerUtil.findStudy(request, mStudyService); @@ -183,7 +172,7 @@ matrix.generateNexusBlock(matrixContent); // matrixContent.append("END;\n"); // Not Needed - String tmp = getFileName(pMatrixId); + String tmp = getFileName(pMatrixId,request); try { @@ -203,5 +192,36 @@ } } + */ + @Override + protected String getFileNamePrefix() { + return "M"; + } + + @Override + protected String getFileContent(long objectId, HttpServletRequest request) { + Study pStudy = ControllerUtil.findStudy(request, getStudyService()); + Matrix matrix = getMatrixService().findByID(objectId); + TaxonLabelSet taxa = matrix.getTaxa(); + + if ( getFormat(request) == FORMAT_NEXML ) { + NexusDataSet pNexusDataSet = new NexusDataSet(); + pNexusDataSet.getTaxonLabelSets().add(taxa); + pNexusDataSet.getMatrices().add(matrix); + return getNexmlService().serialize(pNexusDataSet); + } + else { // FORMAT_NEXUS or none + StringBuilder matrixContent = new StringBuilder(); + matrixContent.append("#NEXUS\n"); + TreebaseUtil.attachStudyHeader(pStudy, matrixContent); + if (taxa != null) { + //one taxon per line, no line number: + taxa.buildNexusBlockTaxa(matrixContent, true, false); + } + matrix.generateNexusBlock(matrixContent); + return matrixContent.toString(); + } + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -22,17 +22,17 @@ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; import java.sql.Clob; -import java.sql.SQLException; +//import java.sql.SQLException; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; @@ -42,7 +42,7 @@ import org.cipres.treebase.domain.study.StudyService; import org.cipres.treebase.domain.tree.PhyloTreeService; import org.cipres.treebase.web.util.ControllerUtil; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; /** * @@ -54,9 +54,9 @@ * @author madhu * */ -public class DownloadANexusFileController implements Controller { +public class DownloadANexusFileController extends AbstractDownloadController implements Controller { - private static final Logger LOGGER = Logger.getLogger(DownloadANexusFileController.class); +// private static final Logger LOGGER = Logger.getLogger(DownloadANexusFileController.class); private PhyloTreeService mPhyloTreeService; private StudyService mStudyService; @@ -109,39 +109,40 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - // TODO Auto-generated method stub - String sep = System.getProperty("file.separator"); - String downloadDir = request.getSession().getServletContext().getRealPath( - "/NexusFileDownload") - + sep + request.getRemoteUser(); +// String sep = System.getProperty("file.separator"); +// String downloadDir = request.getSession().getServletContext().getRealPath( +// "/NexusFileDownload") +// + sep + request.getRemoteUser(); +// String downloadDir = getDownloadDir(request); +// +// String treeId = request.getParameter("treeid"); +// String matrixId = request.getParameter("matrixid"); +// String nexusFile = request.getParameter("nexusfile"); +// +// if (treeId == null && matrixId == null && nexusFile == null) { +// return null; +// } +// long clickedParameterId = 0L; +// String nexusFileName = null; +// +// if (treeId != null) { +// clickedParameterId = Long.parseLong(treeId); +// nexusFileName = getPhyloTreeService().findByID(clickedParameterId).getNexusFileName(); +// } else if (matrixId != null) { +// clickedParameterId = Long.parseLong(matrixId); +// nexusFileName = getMatrixService().findByID(clickedParameterId).getNexusFileName(); +// } else if (nexusFile != null) { +// nexusFileName = (nexusFile).replaceAll("%20", "_"); +// } +// +// if (nexusFileName == null) { +// return null; +// } + + generateAFileDynamically(request,response,0L); +// generateAFileDynamically(request, downloadDir, nexusFileName); +// WebUtil.downloadFile(response, downloadDir, nexusFileName + org); - String treeId = request.getParameter("treeid"); - String matrixId = request.getParameter("matrixid"); - String nexusFile = request.getParameter("nexusfile"); - - if (treeId == null && matrixId == null && nexusFile == null) { - return null; - } - long clickedParameterId = 0L; - String nexusFileName = null; - - if (treeId != null) { - clickedParameterId = Long.parseLong(treeId); - nexusFileName = getPhyloTreeService().findByID(clickedParameterId).getNexusFileName(); - } else if (matrixId != null) { - clickedParameterId = Long.parseLong(matrixId); - nexusFileName = getMatrixService().findByID(clickedParameterId).getNexusFileName(); - } else if (nexusFile != null) { - nexusFileName = (nexusFile).replaceAll("%20", "_"); - } - - if (nexusFileName == null) { - return null; - } - - generateAFileDynamically(request, downloadDir, nexusFileName); - WebUtil.downloadFile(response, downloadDir, nexusFileName + org); - return null; } @@ -149,7 +150,8 @@ * @param req HttpServletRequest * @param downloadDirName String Name of the directory where file(s) will be downloaded * @param fileName String name of the download file - */ + */ + /* private void generateAFileDynamically( HttpServletRequest req, String downloadDirName, @@ -199,6 +201,72 @@ sqle.printStackTrace(); } + } + */ + + @Override + protected String getFileName(long objectId,HttpServletRequest req) { + String treeId = req.getParameter("treeid"); + String matrixId = req.getParameter("matrixid"); + String nexusFile = req.getParameter("nexusfile"); + + if (treeId == null && matrixId == null && nexusFile == null) { + return null; + } + long clickedParameterId = 0L; + String nexusFileName = null; + if (treeId != null) { + clickedParameterId = Long.parseLong(treeId); + nexusFileName = getPhyloTreeService().findByID(clickedParameterId).getNexusFileName(); + } else if (matrixId != null) { + clickedParameterId = Long.parseLong(matrixId); + nexusFileName = getMatrixService().findByID(clickedParameterId).getNexusFileName(); + } else if (nexusFile != null) { + nexusFileName = (nexusFile).replaceAll("%20", "_"); + } + return ( nexusFileName + org ).replaceAll(TreebaseUtil.ANEMPTYSPACE, "_"); + } + + @Override + protected String getFileNamePrefix() { + // Not necessary because we override getFileName + return null; + } + + @Override + protected String getFileContent(long objectId, HttpServletRequest req) { + String nexusFileName = null; + String treeId = req.getParameter("treeid"); + String matrixId = req.getParameter("matrixid"); + String nexusFile = req.getParameter("nexusfile"); + long clickedParameterId = 0L; + if (treeId != null) { + clickedParameterId = Long.parseLong(treeId); + nexusFileName = getPhyloTreeService().findByID(clickedParameterId).getNexusFileName(); + } else if (matrixId != null) { + clickedParameterId = Long.parseLong(matrixId); + nexusFileName = getMatrixService().findByID(clickedParameterId).getNexusFileName(); + } else if (nexusFile != null) { + nexusFileName = (nexusFile).replaceAll("%20", "_"); + } + if (nexusFileName == null) { + return null; + } + Study study = ControllerUtil.findStudy(req, mStudyService); + Map<String, Clob> nexusMap = study.getNexusFiles(); + Clob clob = nexusMap.get(nexusFileName); + String clobStr = "File Not Found. File Name is: " + nexusFileName; + if (clob != null) { + try { + int clobLength = (int) clob.length(); + char[] clobchars = new char[clobLength]; + clob.getCharacterStream().read(clobchars); + clobStr = new String(clobchars); + } catch ( Exception e ) { + e.printStackTrace(); + } + } + return clobStr; } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -21,8 +21,8 @@ */ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; +//import java.io.File; +//import java.io.FileWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -36,7 +36,7 @@ import org.cipres.treebase.domain.study.StudyService; import org.cipres.treebase.domain.study.Submission; import org.cipres.treebase.web.util.ControllerUtil; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; /** * @author madhu @@ -46,7 +46,7 @@ * Modified on April 28, 2008 * */ -public class DownloadANexusRCTFileController implements Controller { +public class DownloadANexusRCTFileController extends AbstractDownloadController implements Controller { Logger LOGGER = Logger.getLogger(DownloadANexusRCTFileController.class); @@ -78,52 +78,91 @@ Long study_id = ControllerUtil.getStudyId(pRequest); Study study = mStudyService.findByID(study_id); Submission submission = study.getSubmission(); + generateAFileDynamically(pRequest, pResponse, submission.getId()); + return null; - String fileName = pRequest.getParameter("nexusfile"); +// String fileName = pRequest.getParameter("nexusfile"); +// if (fileName == null) { +// return null; +// } +// +// String nexFileName = (fileName + "rct").replaceAll(TreebaseUtil.ANEMPTYSPACE, "_"); +// +// if (LOGGER.isInfoEnabled()) { +// LOGGER.info("Submission id: " + submission.getId() + ", FileName: " + nexFileName); +// } + +// String downloadDir = pRequest.getSession().getServletContext().getRealPath( +// TreebaseUtil.FILESEP + "NexusFileDownload") +// + TreebaseUtil.FILESEP + pRequest.getRemoteUser(); +// String downloadDir = getDownloadDir(pRequest); +// +// long start = System.currentTimeMillis(); +// +// File dirPath = new File(downloadDir); +// if (!dirPath.exists()) { +// dirPath.mkdirs(); +// } +// +// String pathName = downloadDir + TreebaseUtil.FILESEP + nexFileName; +// File file = new File(pathName); +// +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("path=" + pathName); +// } +// +// FileWriter fwriter = new FileWriter(file); +// StringBuilder bldr = new StringBuilder("#NEXUS"); +// bldr.append(TreebaseUtil.getLineSeparators(2)); +// bldr +// .append(getStudyService().generateReconstructedNexusFile(submission.getId(), fileName)); +// +// fwriter.write(bldr.toString()); +// fwriter.close(); +// WebUtil.downloadFile(pResponse, downloadDir, nexFileName); +// +// if (LOGGER.isDebugEnabled()) { +// long end = System.currentTimeMillis(); +// LOGGER.debug(" file download time=" + (end-start)); +// } +// +// return null; + } + + @Override + protected String getFileName(long objectId,HttpServletRequest req) { + String fileName = req.getParameter("nexusfile"); if (fileName == null) { return null; } + return (fileName + "rct").replaceAll(TreebaseUtil.ANEMPTYSPACE, "_"); + } - String nexFileName = (fileName + "rct").replaceAll(TreebaseUtil.ANEMPTYSPACE, "_"); + @Override + protected String getFileNamePrefix() { + // Not necessary because we override getFileName + return null; + } - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Submission id: " + submission.getId() + ", FileName: " + nexFileName); + @Override + protected String getFileContent(long submisionId, HttpServletRequest request) { + if ( getFormat(request) == FORMAT_NEXML ) { + Long study_id = ControllerUtil.getStudyId(request); + Study study = mStudyService.findByID(study_id); + return getNexmlService().serialize(study); } - - String downloadDir = pRequest.getSession().getServletContext().getRealPath( - TreebaseUtil.FILESEP + "NexusFileDownload") - + TreebaseUtil.FILESEP + pRequest.getRemoteUser(); - - long start = System.currentTimeMillis(); - - File dirPath = new File(downloadDir); - if (!dirPath.exists()) { - dirPath.mkdirs(); + else { + String fileName = request.getParameter("nexusfile"); + if (fileName == null) { + return null; + } + StringBuilder bldr = new StringBuilder("#NEXUS"); + bldr + .append(TreebaseUtil.getLineSeparators(2)) + .append(getStudyService() + .generateReconstructedNexusFile(submisionId, fileName)); + return bldr.toString(); } - - String pathName = downloadDir + TreebaseUtil.FILESEP + nexFileName; - File file = new File(pathName); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("path=" + pathName); - } - - FileWriter fwriter = new FileWriter(file); - StringBuilder bldr = new StringBuilder("#NEXUS"); - bldr.append(TreebaseUtil.getLineSeparators(2)); - bldr - .append(getStudyService().generateReconstructedNexusFile(submission.getId(), fileName)); - - fwriter.write(bldr.toString()); - fwriter.close(); - WebUtil.downloadFile(pResponse, downloadDir, nexFileName); - - if (LOGGER.isDebugEnabled()) { - long end = System.currentTimeMillis(); - LOGGER.debug(" file download time=" + (end-start)); - } - - return null; } } Added: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java (rev 0) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -0,0 +1,92 @@ +/** + * + */ +package org.cipres.treebase.web.controllers; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.cipres.treebase.TreebaseIDString; +import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.domain.matrix.Matrix; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.study.StudyService; +import org.cipres.treebase.domain.taxon.TaxonLabelSet; +import org.cipres.treebase.domain.tree.TreeBlock; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.Controller; + +/** + * @author rvosa + * + */ +public class DownloadAStudyController extends AbstractDownloadController + implements Controller { + private StudyService mStudyService; + + public StudyService getStudyService() { + return mStudyService; + } + + public void setStudyService(StudyService studyService) { + mStudyService = studyService; + } + + /* (non-Javadoc) + * @see org.cipres.treebase.web.controllers.AbstractDownloadController#getFileContent(long, javax.servlet.http.HttpServletRequest) + */ + @Override + protected String getFileContent(long pStudyID, HttpServletRequest request) { + Study study = getStudyService().findByID(pStudyID); + if ( getFormat(request) == FORMAT_NEXML ) { + return getNexmlService().serialize(study); + } + else { + StringBuilder builder = new StringBuilder(); + builder.append("#NEXUS\n\n"); + + // header: + TreebaseUtil.attachStudyHeader(study, builder); + + // taxa: + for ( TaxonLabelSet tls : study.getTaxonLabelSets() ) { + // one taxon label per line, no line number. + tls.buildNexusBlockTaxa(builder, true, false); + } + + // matrices:: + for ( Matrix m : study.getMatrices() ) { + m.generateNexusBlock(builder); + } + + //tree blocks: + for ( TreeBlock tb : study.getTreeBlocks() ) { + tb.generateAFileDynamically(builder); + } + + return builder.toString(); + } + } + + /* (non-Javadoc) + * @see org.cipres.treebase.web.controllers.AbstractDownloadController#getFileNamePrefix() + */ + @Override + protected String getFileNamePrefix() { + return TreebaseIDString.getPrefixForClass(Study.class); + } + + /* (non-Javadoc) + * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + public ModelAndView handleRequest(HttpServletRequest request, + HttpServletResponse response) throws Exception { + if (request.getParameter("id") == null) { + return null; + } + long pStudyId = Long.parseLong(request.getParameter("id")); + generateAFileDynamically(request, response, pStudyId); + return null; + } + +} Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -20,19 +20,21 @@ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; +//import java.io.File; +//import java.io.FileWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; +//import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.domain.nexus.NexusDataSet; import org.cipres.treebase.domain.tree.PhyloTreeHome; import org.cipres.treebase.domain.tree.TreeBlock; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; /** * @@ -40,8 +42,8 @@ * */ -public class DownloadATreeBlockController implements Controller { - private static final Logger LOGGER = Logger.getLogger(DownloadATreeBlockController.class); +public class DownloadATreeBlockController extends AbstractDownloadController implements Controller { +// private static final Logger LOGGER = Logger.getLogger(DownloadATreeBlockController.class); private PhyloTreeHome mPhyloTreeHome; @@ -67,53 +69,66 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - // TODO: - String sep = System.getProperty("file.separator"); +// String sep = System.getProperty("file.separator"); if (request.getParameter("treeblockid") == null) { return null; } long blockid = Long.parseLong(request.getParameter("treeblockid")); - String fileName = getFileName(blockid); + generateAFileDynamically(request, response, blockid); + return null; + //String fileName = getFileName(blockid,request); - String downloadDir = request.getSession().getServletContext().getRealPath( - "/NexusFileDownload") - + sep + request.getRemoteUser(); +// String downloadDir = request.getSession().getServletContext().getRealPath( +// "/NexusFileDownload") +// + sep + request.getRemoteUser(); +// String downloadDir = getDownloadDir(request); +// +// long start = System.currentTimeMillis(); +// +// TreeBlock treeBlock = getPhyloTreeHome().findTreeBlockById(blockid); +// +// File dirPath = new File(downloadDir); +// if (!dirPath.exists()) { +// dirPath.mkdirs(); +// } +// File file = new File(downloadDir + System.getProperty("file.separator") +// + getFileName(blockid,request)); +// FileWriter fwriter = new FileWriter(file); +// StringBuilder bldr = new StringBuilder("#NEXUS\n\n"); +// treeBlock.generateAFileDynamically(bldr); +// fwriter.write(bldr.toString()); +// fwriter.close(); +// generateAFileDynamically(request, blockid); +// WebUtil.downloadFile(response, downloadDir, getFileName(blockid,request)); +// +// long end = System.currentTimeMillis(); +// +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE: " + (end - start)); +// } +// +// return null; + } - long start = System.currentTimeMillis(); + @Override + protected String getFileNamePrefix() { + return "TB"; + } - TreeBlock element = getPhyloTreeHome().findTreeBlockById(blockid); - - File dirPath = new File(downloadDir); - if (!dirPath.exists()) { - dirPath.mkdirs(); + @Override + protected String getFileContent(long blockid, HttpServletRequest request) { + TreeBlock treeBlock = getPhyloTreeHome().findTreeBlockById(blockid); + if ( getFormat(request) == FORMAT_NEXML ) { + NexusDataSet nexusDataSet = new NexusDataSet(); + nexusDataSet.getTaxonLabelSets().add(treeBlock.getTaxonLabelSet()); + nexusDataSet.getTreeBlocks().add(treeBlock); + return getNexmlService().serialize(nexusDataSet); } - File file = new File(downloadDir + System.getProperty("file.separator") - + getFileName(blockid)); - FileWriter fwriter = new FileWriter(file); - StringBuilder bldr = new StringBuilder("#NEXUS\n\n"); - element.generateAFileDynamically(bldr); - fwriter.write(bldr.toString()); - fwriter.close(); - WebUtil.downloadFile(response, downloadDir, fileName); - - long end = System.currentTimeMillis(); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE: " + (end - start)); + else { + StringBuilder bldr = new StringBuilder("#NEXUS\n\n"); + treeBlock.generateAFileDynamically(bldr); + return bldr.toString(); } - - return null; } - /** - * This method adds "TB" as Prefix to the tree block ID and ".tre" as Suffix. - * - * @param id (TreeBlock id) - * @return returns the file name to be used for down loading - */ - private String getFileName(long id) { - - return "TB" + id + ".tre"; - } - } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -20,24 +20,26 @@ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.domain.nexus.NexusDataSet; import org.cipres.treebase.domain.study.Study; 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.domain.tree.TreeBlock; import org.cipres.treebase.web.util.ControllerUtil; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; import org.cipres.treebase.domain.taxon.TaxonLabelSet; @@ -53,8 +55,8 @@ * */ -public class DownloadATreeController implements Controller { - private static final Logger LOGGER = Logger.getLogger(DownloadATreeController.class); +public class DownloadATreeController extends AbstractDownloadController implements Controller { +// private static final Logger LOGGER = Logger.getLogger(DownloadATreeController.class); private PhyloTreeService mPhyloTreeService; private StudyService mStudyService; @@ -94,50 +96,42 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - // TODO: - String sep = System.getProperty("file.separator"); +// String sep = System.getProperty("file.separator"); if (request.getParameter("treeid") == null) { return null; } long treeid = Long.parseLong(request.getParameter("treeid")); - String fileName = getFileName(treeid); - - String downloadDir = request.getSession().getServletContext().getRealPath( - "/NexusFileDownload") - + sep + request.getRemoteUser(); - - long start = System.currentTimeMillis(); - - generateAFileDynamically(request, treeid, downloadDir); - WebUtil.downloadFile(response, downloadDir, fileName); - - long end = System.currentTimeMillis(); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE: " + (end - start)); - } - - return null; // new ModelAndView("treeList", Constants.TREE_LIST, phyloTrees); + generateAFileDynamically(request, response, treeid); + return null; +// String fileName = getFileName(treeid,request); +// +// String downloadDir = request.getSession().getServletContext().getRealPath( +// "/NexusFileDownload") +// + sep + request.getRemoteUser(); +// String downloadDir = getDownloadDir(request); +// +// long start = System.currentTimeMillis(); +// +// generateAFileDynamically(request, treeid, downloadDir); +// WebUtil.downloadFile(response, downloadDir, fileName); +// +// long end = System.currentTimeMillis(); +// +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("TIME DIFFERENCE FOR A SINGAL FILE: " + (end - start)); +// } +// +// return null; // new ModelAndView("treeList", Constants.TREE_LIST, phyloTrees); } /** - * This method adds "T" as Prefix to the tree ID and ".tre" as Suffix. * - * @param id (Tree id) - * @return returns the file name to be used for downloading - */ - private String getFileName(long id) { - - return "T" + id + ".tre"; - } - - /** - * * @param request * @param pTreeId It is tree id. * @param downloadDirName download directory where files will be created */ + /* private void generateAFileDynamically( HttpServletRequest request, long pTreeId, @@ -145,15 +139,15 @@ Study study = ControllerUtil.findStudy(request, mStudyService); - File dirPath = new File(downloadDirName); - if (!dirPath.exists()) { - dirPath.mkdirs(); - } +// File dirPath = new File(downloadDirName); +// if (!dirPath.exists()) { +// dirPath.mkdirs(); +// } PhyloTree tree = getPhyloTreeService().findByID(pTreeId); TaxonLabelSet tbnlblSet = tree.getTreeBlock().getTaxonLabelSet(); - String tmp = getFileName(pTreeId); +// String tmp = getFileName(pTreeId,request); StringBuilder builder = new StringBuilder(); @@ -168,19 +162,60 @@ //tree block: tree.buildNexusBlock(builder); + + generateAFileDynamically(request, pTreeId); - try { +// try { +// +// File file = new File(downloadDirName + TreebaseUtil.FILESEP + tmp); +// FileWriter out = new FileWriter(file); +// +// out.write(builder.toString()); +// +// out.close(); +// +// } catch (IOException e) { +// e.printStackTrace(); +// } + } +*/ + @Override + protected String getFileNamePrefix() { + return "T"; + } - File file = new File(downloadDirName + TreebaseUtil.FILESEP + tmp); - FileWriter out = new FileWriter(file); - - out.write(builder.toString()); - - out.close(); - - } catch (IOException e) { - e.printStackTrace(); + @Override + protected String getFileContent(long pTreeId, HttpServletRequest request) { + Study study = ControllerUtil.findStudy(request, mStudyService); + PhyloTree tree = getPhyloTreeService().findByID(pTreeId); + tree = getPhyloTreeService().resurrect(tree); + TreeBlock enclosingTreeBlock = getPhyloTreeService().resurrect(tree.getTreeBlock()); + TaxonLabelSet tls = getPhyloTreeService().resurrect(enclosingTreeBlock.getTaxonLabelSet()); + if ( getFormat(request) == FORMAT_NEXML ) { + NexusDataSet nds = new NexusDataSet(); + nds.getTaxonLabelSets().add(tls); + TreeBlock treeBlock = new TreeBlock(); + treeBlock.setTaxonLabelSet(tls); + treeBlock.addPhyloTree(tree); + nds.getTreeBlocks().add(treeBlock); + return getNexmlService().serialize(nds); } + else { + StringBuilder builder = new StringBuilder(); + builder.append("#NEXUS\n\n"); + + // header: + TreebaseUtil.attachStudyHeader(study, builder); + + // taxa: + // one taxon label per line, no line number. + tls.buildNexusBlockTaxa(builder, true, false); + + //tree block: + tree.buildNexusBlock(builder); + + return builder.toString(); + } } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2009-06-23 11:08:34 UTC (rev 81) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2009-06-23 11:10:17 UTC (rev 82) @@ -20,9 +20,9 @@ package org.cipres.treebase.web.controllers; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -39,7 +39,7 @@ import org.cipres.treebase.domain.taxon.TaxonLabelSet; import org.cipres.treebase.domain.tree.PhyloTree; import org.cipres.treebase.domain.tree.PhyloTreeService; -import org.cipres.treebase.web.util.WebUtil; +//import org.cipres.treebase.web.util.WebUtil; /** * @@ -49,7 +49,7 @@ * @author rvosa * */ -public class DownloadAnAnalysisStepController implements Controller { +public class DownloadAnAnalysisStepController extends AbstractDownloadController implements Controller { private MatrixService mMatrixService; private PhyloTreeService mPhyloTreeService; private AnalysisStepService mAnalysisStepService; @@ -117,14 +117,15 @@ } long analysisId = Long.parseLong(request.getParameter("analysisid")); - String fileName = getFileName(analysisId); +// String fileName = getFileName(analysisId,request); - String downloadDir = request.getSession().getServletContext().getRealPath( - TreebaseUtil.FILESEP + "NexusFileDownload") - + TreebaseUtil.FILESEP + request.getRemoteUser(); +// String downloadDir = request.getSession().getServletContext().getRealPath( +// TreebaseUtil.FILESEP + "NexusFileDownload") +// + TreebaseUtil.FILESEP + request.getRemoteUser(); +// String downloadDir = getDownloadDir(request); - generateAFileDynamically(request, analysisId, downloadDir); - WebUtil.downloadFile(response, downloadDir, fileName); + generateAFileDynamically(request, response, analysisId); +// WebUtil.downloadFile(response, downloadDir, fileName); return null; } @@ -136,6 +137,7 @@ * @param analysisId * @param downloadDirName */ + /* private void generateAFileDynamically(HttpServletRequest request, long analysisId, String downloadDirName) { AnalysisStep step = getAnalysisStepService().findByID(analysisId); @@ -187,7 +189,7 @@ } } - String tmp = getFileName(analysisId); + String tmp = getFileName(analysisId,request); try { File file = new File(downloadDirName + TreebaseUtil.FILESEP + tmp); FileWriter out = new FileWriter(file); @@ -198,9 +200,57 @@ } } - - private String getFileName(long id) { - return "AnalysisStep" + id + ".nex"; + */ + + @Override + protected String getFileNamePrefix() { + return "AnalysisStep"; } + @Override + protected String getFileContent(long analysisId, HttpServletRequest request) { + AnalysisStep step = getAnalysisStepService().findByID(analysisId); + StringBuilder stepContent = new StringBuilder(); + stepContent.append("#NEXUS\n"); + + //header: + TreebaseUtil.attachStudyHeader(step.getAnalysis().getStudy(), stepContent); + stepContent.append("[ The following blocks are input data for analysis step " + analysisId + " ]\n"); + TaxonLabelSet inputLabelSet = step.getInputTaxonLabelSet(); + inputLabelSet.buildNexusBlockTaxa(stepContent, true, false); + for ( AnalyzedData data : step.getDataSetReadOnly() ) { + if ( data.isInputData() ) { + PhyloTree tree = data.getTreeData(); + Matrix matrix = data.getMatrixData(); + if ( tree != null ) { + tree.getTreeBlock().setTaxonLabelSet(inputLabelSet); + tree.buildNexusBlock(stepContent); + } + if ( matrix != null ) { + matrix.setTaxa(inputLabelSet); + matrix.generateNexusBlock(stepContent); + } + } + } + + stepContent.append("[ The following blocks are output data for analysis step " + analysisId + " ]\n"); + TaxonLabelSet outputLabelSet = step.getOutputTaxonLabelSet(); + outputLabelSet.buildNexusBlockTaxa(stepContent, true, false); + for ( AnalyzedData data : step.getDataSetReadOnly() ) { + if ( ! data.isInputData() ) { + PhyloTree tree = data.getTreeData(); + Matrix matrix = data.getMatrixData(); + if ( tree != null ) { + tree.getTreeBlock().setTaxonLabelSet(outputLabelSet); + tree.buildNexusBlock(stepContent); + } + if ( matrix != null ) { + matrix.setTaxa(outputLabelSet); + matrix.generateNexusBlock(stepContent); + } + } + } + return stepContent.toString(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-25 14:56:44
|
Revision: 125 http://treebase.svn.sourceforge.net/treebase/?rev=125&view=rev Author: rvos Date: 2009-06-25 13:41:20 +0000 (Thu, 25 Jun 2009) Log Message: ----------- Changed base URI handling Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -2,6 +2,7 @@ import java.io.File; import java.io.FileWriter; +import java.util.Properties; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -21,6 +22,18 @@ private static String mNexmlContentType = "application/xml"; private static String mRdfContentType = "application/rdf+xml"; + protected Properties getDefaultProperties(HttpServletRequest request) { + Properties properties = new Properties(); + StringBuffer baseURI = new StringBuffer("http://"); + baseURI + .append(request.getServerName()) + .append(':') + .append(request.getServerPort()) + .append("/treebase-web/PhyloWS/"); + properties.setProperty("nexml.uri.base", baseURI.toString()); + return properties; + } + /** * * @param request @@ -54,6 +67,9 @@ if ( getFormat(request) == FORMAT_NEXML ) { return getFileNamePrefix() + id + ".xml"; } + if ( getFormat(request) == FORMAT_RDF ) { + return getFileNamePrefix() + id + ".rdf"; + } return getFileNamePrefix() + id + ".nex"; } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -113,13 +113,13 @@ NexusDataSet pNexusDataSet = new NexusDataSet(); pNexusDataSet.getTaxonLabelSets().add(taxa); pNexusDataSet.getMatrices().add(matrix); - return getNexmlService().serialize(pNexusDataSet); + return getNexmlService().serialize(pNexusDataSet,getDefaultProperties(request)); } else if ( getFormat(request) == FORMAT_RDF ) { NexusDataSet pNexusDataSet = new NexusDataSet(); pNexusDataSet.getTaxonLabelSets().add(taxa); pNexusDataSet.getMatrices().add(matrix); - return getRdfaService().serialize(pNexusDataSet); + return getRdfaService().serialize(pNexusDataSet,getDefaultProperties(request)); } else { // FORMAT_NEXUS or none StringBuilder matrixContent = new StringBuilder(); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -98,12 +98,12 @@ if ( getFormat(request) == FORMAT_NEXML ) { Long study_id = ControllerUtil.getStudyId(request); Study study = mStudyService.findByID(study_id); - return getNexmlService().serialize(study); + return getNexmlService().serialize(study,getDefaultProperties(request)); } else if ( getFormat(request) == FORMAT_RDF ) { Long study_id = ControllerUtil.getStudyId(request); Study study = mStudyService.findByID(study_id); - return getRdfaService().serialize(study); + return getRdfaService().serialize(study,getDefaultProperties(request)); } else { String fileName = request.getParameter("nexusfile"); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -39,10 +39,10 @@ protected String getFileContent(long pStudyID, HttpServletRequest request) { Study study = getStudyService().findByID(pStudyID); if ( getFormat(request) == FORMAT_NEXML ) { - return getNexmlService().serialize(study); + return getNexmlService().serialize(study,getDefaultProperties(request)); } else if ( getFormat(request) == FORMAT_RDF ) { - return getRdfaService().serialize(study); + return getRdfaService().serialize(study,getDefaultProperties(request)); } else { StringBuilder builder = new StringBuilder(); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -81,13 +81,13 @@ NexusDataSet nexusDataSet = new NexusDataSet(); nexusDataSet.getTaxonLabelSets().add(treeBlock.getTaxonLabelSet()); nexusDataSet.getTreeBlocks().add(treeBlock); - return getNexmlService().serialize(nexusDataSet); + return getNexmlService().serialize(nexusDataSet,getDefaultProperties(request)); } else if ( getFormat(request) == FORMAT_RDF ) { NexusDataSet nexusDataSet = new NexusDataSet(); nexusDataSet.getTaxonLabelSets().add(treeBlock.getTaxonLabelSet()); nexusDataSet.getTreeBlocks().add(treeBlock); - return getRdfaService().serialize(nexusDataSet); + return getRdfaService().serialize(nexusDataSet,getDefaultProperties(request)); } else { StringBuilder bldr = new StringBuilder("#NEXUS\n\n"); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -20,6 +20,8 @@ package org.cipres.treebase.web.controllers; +import java.util.Properties; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -113,7 +115,7 @@ treeBlock.setTaxonLabelSet(tls); treeBlock.addPhyloTree(tree); nds.getTreeBlocks().add(treeBlock); - return getNexmlService().serialize(nds); + return getNexmlService().serialize(nds,getDefaultProperties(request)); } else if ( getFormat(request) == FORMAT_RDF ) { NexusDataSet nds = new NexusDataSet(); @@ -122,7 +124,7 @@ treeBlock.setTaxonLabelSet(tls); treeBlock.addPhyloTree(tree); nds.getTreeBlocks().add(treeBlock); - return getRdfaService().serialize(nds); + return getRdfaService().serialize(nds,getDefaultProperties(request)); } else { StringBuilder builder = new StringBuilder(); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2009-06-25 13:40:41 UTC (rev 124) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2009-06-25 13:41:20 UTC (rev 125) @@ -111,97 +111,14 @@ */ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - if ( request.getParameter("analysisid") == null ) { return null; } - - long analysisId = Long.parseLong(request.getParameter("analysisid")); -// String fileName = getFileName(analysisId,request); - -// String downloadDir = request.getSession().getServletContext().getRealPath( -// TreebaseUtil.FILESEP + "NexusFileDownload") -// + TreebaseUtil.FILESEP + request.getRemoteUser(); -// String downloadDir = getDownloadDir(request); - + long analysisId = Long.parseLong(request.getParameter("analysisid")); generateAFileDynamically(request, response, analysisId); -// WebUtil.downloadFile(response, downloadDir, fileName); - return null; } - /** - * - * - * @param request - * @param analysisId - * @param downloadDirName - */ - /* - private void generateAFileDynamically(HttpServletRequest request, long analysisId, String downloadDirName) { - - AnalysisStep step = getAnalysisStepService().findByID(analysisId); - - File dirPath = new File(downloadDirName); - if (!dirPath.exists()) { - dirPath.mkdirs(); - } - - StringBuilder stepContent = new StringBuilder(); - stepContent.append("#NEXUS\n"); - - //header: - TreebaseUtil.attachStudyHeader(step.getAnalysis().getStudy(), stepContent); - - stepContent.append("[ The following blocks are input data for analysis step " + analysisId + " ]\n"); - TaxonLabelSet inputLabelSet = step.getInputTaxonLabelSet(); - inputLabelSet.buildNexusBlockTaxa(stepContent, true, false); - for ( AnalyzedData data : step.getDataSetReadOnly() ) { - if ( data.isInputData() ) { - PhyloTree tree = data.getTreeData(); - Matrix matrix = data.getMatrixData(); - if ( tree != null ) { - tree.getTreeBlock().setTaxonLabelSet(inputLabelSet); - tree.buildNexusBlock(stepContent); - } - if ( matrix != null ) { - matrix.setTaxa(inputLabelSet); - matrix.generateNexusBlock(stepContent); - } - } - } - - stepContent.append("[ The following blocks are output data for analysis step " + analysisId + " ]\n"); - TaxonLabelSet outputLabelSet = step.getOutputTaxonLabelSet(); - outputLabelSet.buildNexusBlockTaxa(stepContent, true, false); - for ( AnalyzedData data : step.getDataSetReadOnly() ) { - if ( ! data.isInputData() ) { - PhyloTree tree = data.getTreeData(); - Matrix matrix = data.getMatrixData(); - if ( tree != null ) { - tree.getTreeBlock().setTaxonLabelSet(outputLabelSet); - tree.buildNexusBlock(stepContent); - } - if ( matrix != null ) { - matrix.setTaxa(outputLabelSet); - matrix.generateNexusBlock(stepContent); - } - } - } - - String tmp = getFileName(analysisId,request); - try { - File file = new File(downloadDirName + TreebaseUtil.FILESEP + tmp); - FileWriter out = new FileWriter(file); - out.write(stepContent.toString()); - out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - */ - @Override protected String getFileNamePrefix() { return "AnalysisStep"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-07-02 10:43:55
|
Revision: 159 http://treebase.svn.sourceforge.net/treebase/?rev=159&view=rev Author: rvos Date: 2009-07-02 10:43:46 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Major refactoring to facilitate CQL queries and RSS1.0 result sets Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2009-07-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -20,13 +20,16 @@ package org.cipres.treebase.web.controllers; +import java.io.IOException; import java.util.Collection; import java.util.HashSet; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; +import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.RangeExpression.MalformedRangeExpression; import org.cipres.treebase.domain.matrix.CharacterMatrix; import org.cipres.treebase.domain.matrix.Matrix; @@ -34,11 +37,21 @@ import org.cipres.treebase.domain.search.MatrixSearchResults; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; +import org.cipres.treebase.domain.search.TreeSearchResults; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.util.RequestMessageSetter; import org.cipres.treebase.web.util.SearchMessageSetter; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; +import org.z3950.zing.cql.CQLAndNode; +import org.z3950.zing.cql.CQLBooleanNode; +import org.z3950.zing.cql.CQLNode; +import org.z3950.zing.cql.CQLNotNode; +import org.z3950.zing.cql.CQLOrNode; +import org.z3950.zing.cql.CQLParseException; +import org.z3950.zing.cql.CQLParser; +import org.z3950.zing.cql.CQLRelation; +import org.z3950.zing.cql.CQLTermNode; /** * MatrixSearchController.java @@ -72,50 +85,162 @@ clearMessages(request); String formName = request.getParameter("formName"); + String query = request.getParameter("query"); LOGGER.info("formName is '" + formName + "'"); - + if ( ! TreebaseUtil.isEmpty(query) ) { + /* + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Matrix> queryResults = doCQLQuery(root, new HashSet<Matrix>(),request, response, errors); + MatrixSearchResults tsr = new MatrixSearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, tsr); + } + else { + return this.searchResultsAsRDF(tsr, request, root); + } + */ + return this.handleQueryRequest(request, response, errors); + } + if (formName.equals("matrixSimple")) { String buttonName = request.getParameter("searchButton"); - + Set<Matrix> matches = new HashSet<Matrix>(); + String searchTerm = convertStars(request.getParameter("searchTerm")); + SearchMessageSetter mSetter = new RequestMessageSetter(request); + MatrixSearchResults oldRes; + { + SearchResults<?> sr = searchResults(request); + if (sr != null) { + oldRes = (MatrixSearchResults) sr.convertToMatrices(); + } else { + oldRes = new MatrixSearchResults (); // TODO: Convert existing search results to new type + } + } if (buttonName.equals("matrixID")) { - return doSearch(request, response, SearchType.byID, errors); + matches.addAll(doSearch(request, response, SearchType.byID, errors,searchTerm)); } else if (buttonName.equals("matrixTitle")) { - return doSearch(request, response, SearchType.byTitle, errors); + matches.addAll(doSearch(request, response, SearchType.byTitle, errors,searchTerm)); } else if (buttonName.equals("matrixType")) { - return doSearch(request, response, SearchType.byType, errors); + matches.addAll(doSearch(request, response, SearchType.byType, errors,searchTerm)); } else if (buttonName.equals("matrixNTAX")) { - return doSearch(request, response, SearchType.byNTAX, errors); + matches.addAll(doSearch(request, response, SearchType.byNTAX, errors,searchTerm)); } else if (buttonName.equals("matrixNCHAR")) { - return doSearch(request, response, SearchType.byNCHAR, errors); + matches.addAll(doSearch(request, response, SearchType.byNCHAR, errors,searchTerm)); } else { throw new Error("Unknown search button name '" + buttonName + "'"); } - } else { + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + SearchResults<Matrix> newRes = intersectSearchResults(oldRes, + new MatrixSearchResults(matches), mSetter, "No matching matrices found"); + saveSearchResults(request, newRes); + return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, newRes); + } + else { + return this.searchResultsAsRDF(new MatrixSearchResults(matches), request, null, "matrix", "matrix"); + } + } + + else { return super.onSubmit(request, response, command, errors); } } - private ModelAndView doSearch( + private Set<Matrix> doCQLQuery( + CQLNode node, + Set<Matrix> results, + HttpServletRequest request, + HttpServletResponse response, + BindException errors + ) throws InstantiationException { + if ( node instanceof CQLBooleanNode ) { + Set<Matrix> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request, response, errors); + Set<Matrix> resultsRight = doCQLQuery(((CQLBooleanNode)node).right,results, request, response, errors); + if ( node instanceof CQLNotNode ) { + for ( Matrix rightMatrix : resultsRight ) { + if ( resultsLeft.contains(rightMatrix) ) + resultsLeft.remove(rightMatrix); + } + } + else if ( node instanceof CQLOrNode ) { + resultsLeft.addAll(resultsRight); + } + else if ( node instanceof CQLAndNode ) { + Set<Matrix> resultsUnion = new HashSet<Matrix>(); + for ( Matrix leftMatrix : resultsLeft ) { + if ( resultsRight.contains(leftMatrix) ) + resultsUnion.add(leftMatrix); + } + resultsLeft = resultsUnion; + } + results = resultsLeft; + } + else if ( node instanceof CQLTermNode ) { + CQLTermNode term = (CQLTermNode)node; + String index = term.getIndex(); + if ( index.startsWith("tb.title") ) { + results.addAll(doSearch(request, response, SearchType.byTitle, errors, term.getTerm())); + } else if ( index.startsWith("tb.identifier") ) { + results.addAll(doSearch(request, response, SearchType.byID, errors, term.getTerm())); + } else if ( index.startsWith("tb.type") ) { + results.addAll(doSearch(request, response, SearchType.byType, errors, term.getTerm())); + } else if ( index.startsWith("tb.ntax") ) { + results.addAll(doSearch(request, response, SearchType.byNTAX, errors, term.getTerm())); + } else if ( index.startsWith("tb.nchar") ) { + results.addAll(doSearch(request, response, SearchType.byNTAX, errors, term.getTerm())); + } else { + // issue warnings + addMessage(request, "Unsupported index: " + index); + } + } + logger.debug(node); + return results; + } + + private CQLNode normalizeParseTree(CQLNode node) { + if ( node instanceof CQLBooleanNode ) { + ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); + ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); + return node; + } + else if ( node instanceof CQLTermNode ) { + String index = ((CQLTermNode)node).getIndex(); + String term = ((CQLTermNode)node).getTerm(); + CQLRelation relation = ((CQLTermNode)node).getRelation(); + index = index.replaceAll("dcterms.title", "tb.title.matrix"); + index = index.replaceAll("dcterms.identifier", "tb.identifier.matrix"); + index = index.replaceAll("dcterms.extent", "tb.ntax.matrix"); + return new CQLTermNode(index,relation,term); + } + logger.debug(node); + return node; + } + + @SuppressWarnings("unchecked") + private Collection<Matrix> doSearch( HttpServletRequest request, HttpServletResponse response, SearchType searchType, - BindException errors) throws InstantiationException { + BindException errors, + String searchTerm) throws InstantiationException { - String searchTerm = convertStars(request.getParameter("searchTerm")); - String keywordSearchTerm = "%" + searchTerm + "%"; - SearchMessageSetter mSetter = new RequestMessageSetter(request); +// String searchTerm = convertStars(request.getParameter("searchTerm")); +// String keywordSearchTerm = "%" + searchTerm + "%"; +// SearchMessageSetter mSetter = new RequestMessageSetter(request); - MatrixSearchResults oldRes; - { - SearchResults<?> sr = searchResults(request); - if (sr != null) { - oldRes = (MatrixSearchResults) sr.convertToMatrices(); - } else { - oldRes = new MatrixSearchResults (); // TODO: Convert existing search results to new type - } - } +// MatrixSearchResults oldRes; +// { +// SearchResults<?> sr = searchResults(request); +// if (sr != null) { +// oldRes = (MatrixSearchResults) sr.convertToMatrices(); +// } else { +// oldRes = new MatrixSearchResults (); // TODO: Convert existing search results to new type +// } +// } Collection<Matrix> matches = null; MatrixService matrixService = getSearchService().getMatrixService(); @@ -164,13 +289,14 @@ } } matches.removeAll(orphanedMatrices); - - SearchResults<Matrix> newRes = intersectSearchResults(oldRes, - new MatrixSearchResults(matches), mSetter, "No matching matrices found"); - - saveSearchResults(request, newRes); + return matches; - return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, newRes); +// SearchResults<Matrix> newRes = intersectSearchResults(oldRes, +// new MatrixSearchResults(matches), mSetter, "No matching matrices found"); +// +// saveSearchResults(request, newRes); +// +// return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, newRes); } @@ -183,4 +309,36 @@ return "matrixSearch.html"; } + @Override + protected ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors) throws CQLParseException, IOException, InstantiationException { + String query = request.getParameter("query"); + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Matrix> queryResults = doCQLQuery(root, new HashSet<Matrix>(),request, response, errors); + MatrixSearchResults tsr = new MatrixSearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, tsr); + } + else { + SearchResults<?> res = tsr; + String schema = null, original = "matrix"; + if ( ! TreebaseUtil.isEmpty(request.getParameter("recordSchema")) ) { + schema = request.getParameter("recordSchema"); + if ( schema.equals("tree") ) { + res = tsr.convertToTrees(); + } + else if ( schema.equals("taxon") ) { + res = tsr.convertToTaxa(); + } + else if ( schema.equals("study") ) { + res = tsr.convertToStudies(); + } + } + this.saveSearchResults(request, res); + return this.searchResultsAsRDF(res, request, root, schema, original); + } + } + } 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-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -70,29 +70,33 @@ + "', should be /${class}/${NamespacedGUID}"); } String[] pathComponents = pathInfo.split("/"); - String rawNamespacedGUID = pathComponents[pathComponents.length-1]; - if ( rawNamespacedGUID.startsWith("uBio:") ) { - url = uBioBaseUrl + rawNamespacedGUID.substring("uBio:".length()); - } - else if ( rawNamespacedGUID.startsWith("NCBI:") ) { - 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)) ) { - 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()); - } - else { - url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),req.getParameter(format)); - } + if ( pathComponents[pathComponents.length-1].equals("find") ) { + url = domain + createSearchUrl(pathComponents[pathComponents.length-2],req); + } else { + String rawNamespacedGUID = pathComponents[pathComponents.length-1]; + if ( rawNamespacedGUID.startsWith("uBio:") ) { + url = uBioBaseUrl + rawNamespacedGUID.substring("uBio:".length()); } + else if ( rawNamespacedGUID.startsWith("NCBI:") ) { + url = ncbiBaseUrl + rawNamespacedGUID.substring("NCBI:".length()); + } else { - url = domain + "/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 = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + } + else if ( req.getParameter(format).equals("html") ) { + url = domain + createUrl(tbID.getTypePrefix(),tbID.getId()); + } + else { + url = domain + createDownloadUrl(tbID.getTypePrefix(),tbID.getId(),req.getParameter(format)); + } + } + else { + url = domain + "/treebase-web/search/study/anyObjectAsRDF.html?namespacedGUID=" + namespacedGUID.toString(); + } } } } catch ( MalformedTreebaseIDString e ) { @@ -109,6 +113,20 @@ return null; } + private String createSearchUrl(String path,HttpServletRequest request) { + StringBuilder sb = new StringBuilder(); + sb + .append("/treebase-web/search/") + .append(path) + .append("Search.html?query=") + .append(request.getParameter("query")) + .append("&format=") + .append(request.getParameter("format")) + .append("&recordSchema=") + .append(request.getParameter("recordSchema")); + return sb.toString(); + } + private boolean hasWebPage(String[] pathComponents) { for ( int i = ( pathComponents.length - 1 ); i >= 0; i-- ) { for ( int j = 0; j < classesWithPages.length; j++ ) { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java 2009-07-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -22,6 +22,9 @@ package org.cipres.treebase.web.controllers; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -50,6 +53,8 @@ import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; +import org.z3950.zing.cql.CQLNode; +import org.z3950.zing.cql.CQLParseException; /** @@ -65,6 +70,8 @@ protected String formView; private TaxonLabelService mTaxonLabelService; + + protected abstract ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors) throws CQLParseException, IOException, InstantiationException; protected ModelAndView onSubmit( HttpServletRequest request, @@ -110,6 +117,33 @@ return selectResultsView(request); } + protected ModelAndView searchResultsAsRDF (SearchResults<?> searchResults,HttpServletRequest request,CQLNode root, String schema, String original) throws UnsupportedEncodingException { + //${baseURL} + //${phyloWSPath} + //${normalizedCQLQuery} + //${searchResults} + //${domainAddress} + String phyloWSPath = "find/" + original; + request.getSession().setAttribute("searchResultsThawed", searchResults); + StringBuffer domainAddress = new StringBuffer("http://"); + domainAddress + .append(request.getServerName()) + .append(':') + .append(request.getServerPort()); + StringBuffer baseURL = new StringBuffer(domainAddress); + baseURL.append("/treebase-web/phylows"); + request.getSession().setAttribute("recordSchema", schema); + request.getSession().setAttribute("format", request.getParameter("format")); + request.getSession().setAttribute("baseURL", baseURL.toString()); + request.getSession().setAttribute("domainAddress", domainAddress.toString()); + request.getSession().setAttribute("phyloWSPath", phyloWSPath); + request.getSession().setAttribute("originalSection", original); + if ( null != root ) { + request.getSession().setAttribute("normalizedCQLQuery", URLEncoder.encode(root.toCQL(),"UTF-8")); + } + return new ModelAndView(new RedirectView("searchResultsAsRDF.html")); + } + protected <E extends TBPersistable> SearchResults<E> intersectSearchResults( SearchResults<E> oldRes, SearchResults<E> newRes, @@ -380,6 +414,10 @@ protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException bindException, Map model) throws Exception { + String query = request.getParameter("query"); + if ( query != null ) { + return this.handleQueryRequest(request, response, bindException); + } String action = request.getParameter("action"); if (action != null && action.equals("discard") && request.getMethod().equals("GET")) { discardSearchResults(request); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2009-07-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -20,27 +20,36 @@ package org.cipres.treebase.web.controllers; +import java.io.IOException; import java.util.Collection; -import java.util.LinkedList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.cipres.treebase.TreebaseIDString; +import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.domain.search.StudySearchResults; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.study.StudyService; -import org.cipres.treebase.domain.taxon.TaxonLabel; -import org.cipres.treebase.domain.taxon.TaxonVariant; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.util.RequestMessageSetter; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; +import org.z3950.zing.cql.CQLAndNode; +import org.z3950.zing.cql.CQLBooleanNode; +import org.z3950.zing.cql.CQLNode; +import org.z3950.zing.cql.CQLNotNode; +import org.z3950.zing.cql.CQLOrNode; +import org.z3950.zing.cql.CQLParseException; +import org.z3950.zing.cql.CQLParser; +import org.z3950.zing.cql.CQLRelation; +import org.z3950.zing.cql.CQLTermNode; /** * StudySearchController.java @@ -99,13 +108,41 @@ clearMessages(request); String formName = request.getParameter("formName"); + String query = request.getParameter("query"); LOGGER.info("formName is '" + formName + "'"); + if ( ! TreebaseUtil.isEmpty(query) ) { + /* + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Study> queryResults = doCQLQuery(root, new HashSet<Study>(),request, response, errors); + StudySearchResults tsr = new StudySearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/studySearch", Constants.RESULT_SET, tsr); + } + else { + return this.searchResultsAsRDF(tsr, request, root); + } + */ + return this.handleQueryRequest(request, response, errors); + } + if (formName.equals("searchKeyword")) { SearchType searchType; String buttonName = request.getParameter("searchButton"); - + String searchTerm = convertStars(request.getParameter("searchTerm")); + StudySearchResults oldRes; + { + SearchResults<?> sr = searchResults(request); + if (sr != null) { + oldRes = (StudySearchResults) sr.convertToStudies(); + } else { + oldRes = new StudySearchResults (); // TODO: Convert existing search results to new type + } + } if (buttonName.equals("authorKeyword")) { searchType = SearchType.byAuthorName; } else if (buttonName.equals("studyID")) { @@ -123,84 +160,171 @@ } else { throw new Error("Unknown search button name '" + buttonName + "'"); } - - return doSearch(request, response, searchType, errors); + Collection<Study> matches = doSearch(request, response, searchType, errors,searchTerm); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), + new RequestMessageSetter(request), "No matching studies found"); + saveSearchResults(request, newRes); + return new ModelAndView("search/studySearch", Constants.RESULT_SET, newRes); + } + else { + return this.searchResultsAsRDF(new StudySearchResults(matches), request, null,"study","study"); + } } else { return super.onSubmit(request, response, command, errors); } } - protected ModelAndView doSearch( + private Set<Study> doCQLQuery( + CQLNode node, + Set<Study> results, + HttpServletRequest request, + HttpServletResponse response, + BindException errors + ) throws InstantiationException { + if ( node instanceof CQLBooleanNode ) { + Set<Study> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request, response, errors); + Set<Study> resultsRight = doCQLQuery(((CQLBooleanNode)node).right,results, request, response, errors); + if ( node instanceof CQLNotNode ) { + Set<Study> resultsDifference = new HashSet<Study>(); + for ( Study leftStudy : resultsLeft ) { + if ( ! resultsRight.contains(leftStudy) ) + resultsDifference.add(leftStudy); + } + resultsLeft = resultsDifference; + } + else if ( node instanceof CQLOrNode ) { + resultsLeft.addAll(resultsRight); + } + else if ( node instanceof CQLAndNode ) { + Set<Study> resultsUnion = new HashSet<Study>(); + for ( Study leftStudy : resultsLeft ) { + if ( resultsRight.contains(leftStudy) ) + resultsUnion.add(leftStudy); + } + resultsLeft = resultsUnion; + } + results = resultsLeft; + } + else if ( node instanceof CQLTermNode ) { + CQLTermNode term = (CQLTermNode)node; + String index = term.getIndex(); + if ( index.startsWith("tb.title") ) { + results.addAll(doSearch(request, response, SearchType.byTitle, errors, term.getTerm())); + } else if ( index.equals("tb.identifier.study") ) { + results.addAll(doSearch(request, response, SearchType.byID, errors, term.getTerm())); + } else if ( index.startsWith("dcterms.contributor") ) { + results.addAll(doSearch(request, response, SearchType.byAuthorName, errors, term.getTerm())); + } else if ( index.startsWith("dcterms.abstract") ) { + results.addAll(doSearch(request, response, SearchType.inAbstract, errors, term.getTerm())); + } else if ( index.startsWith("dcterms.subject") ) { + results.addAll(doSearch(request, response, SearchType.byKeyword, errors, term.getTerm())); + } else if ( index.startsWith("dcterms.bibliographicCitation") ) { + results.addAll(doSearch(request, response, SearchType.inCitation, errors, term.getTerm())); + } else if ( index.equals("tb.identifier.study.tb1") ) { + results.addAll(doSearch(request, response, SearchType.byLegacyID, errors, term.getTerm())); + } else { + // issue warnings + addMessage(request, "Unsupported index: " + index); + } + } + logger.debug(node); + return results; + } + + private CQLNode normalizeParseTree(CQLNode node) { + if ( node instanceof CQLBooleanNode ) { + ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); + ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); + return node; + } + else if ( node instanceof CQLTermNode ) { + String index = ((CQLTermNode)node).getIndex(); + String term = ((CQLTermNode)node).getTerm(); + CQLRelation relation = ((CQLTermNode)node).getRelation(); + index = index.replaceAll("dcterms.title", "tb.title.study"); + index = index.replaceAll("dcterms.identifier", "tb.identifier.study"); + return new CQLTermNode(index,relation,term); + } + logger.debug(node); + return node; + } + + @SuppressWarnings("unchecked") + protected Collection<Study> doSearch( HttpServletRequest request, HttpServletResponse response, SearchType searchType, - BindException errors) throws InstantiationException { + BindException errors, + String searchTerm) throws InstantiationException { - String searchTerm = convertStars(request.getParameter("searchTerm")); +// String searchTerm = convertStars(request.getParameter("searchTerm")); String keywordSearchTerm = "%" + searchTerm + "%"; - StudySearchResults oldRes; - - { - SearchResults<?> sr = searchResults(request); - if (sr != null) { - oldRes = (StudySearchResults) sr.convertToStudies(); - } else { - oldRes = new StudySearchResults (); // TODO: Convert existing search results to new type - } - } - - LOGGER.info("doSearch old results contained " + oldRes.size() + " item(s)"); +// StudySearchResults oldRes; +// +// { +// SearchResults<?> sr = searchResults(request); +// if (sr != null) { +// oldRes = (StudySearchResults) sr.convertToStudies(); +// } else { +// oldRes = new StudySearchResults (); // TODO: Convert existing search results to new type +// } +// } +// +// LOGGER.info("doSearch old results contained " + oldRes.size() + " item(s)"); Collection<Study> matches; StudyService studyService = getSearchService().getStudyService(); switch (searchType) { - case byID: - matches = (Collection<Study>) doSearchByIDString(request, studyService, Study.class, searchTerm); - break; - case byLegacyID: - { - TreebaseIDString legacyID = null; - boolean malformed = false; - try { - legacyID = new TreebaseIDString(searchTerm, Study.class); - } catch (MalformedTreebaseIDString e) { - malformed = true; + case byID: + matches = (Collection<Study>) doSearchByIDString(request, studyService, Study.class, searchTerm); + break; + case byLegacyID: + { + TreebaseIDString legacyID = null; + boolean malformed = false; + try { + legacyID = new TreebaseIDString(searchTerm, Study.class); + } catch (MalformedTreebaseIDString e) { + malformed = true; + } + if (malformed || legacyID.getTBClass() != Study.class) { + addMessage(request, "Legacy ID number '" + searchTerm + "' is not valid; try S#### or just ####"); + matches = null; + break; + } + matches = (Collection<Study>) studyService.findByTBStudyID("S" + legacyID.getId().toString()); + break; } - if (malformed || legacyID.getTBClass() != Study.class) { - addMessage(request, "Legacy ID number '" + searchTerm + "' is not valid; try S#### or just ####"); - matches = null; + case inAbstract: + matches = studyService.findByAbstract(keywordSearchTerm); break; - } - matches = (Collection<Study>) studyService.findByTBStudyID("S" + legacyID.getId().toString()); - break; + case inCitation: + matches = studyService.findByCitation(keywordSearchTerm); + break; + case byAuthorName: + matches = studyService.findByAuthor(searchTerm); + break; + case byTitle: + matches = studyService.findByTitle(keywordSearchTerm); + break; + case byKeyword: + matches = studyService.findByKeyword(keywordSearchTerm); + break; + default: + throw new Error ("Unknown search type '" + searchType + "'"); } - case inAbstract: - matches = studyService.findByAbstract(keywordSearchTerm); - break; - case inCitation: - matches = studyService.findByCitation(keywordSearchTerm); - break; - case byAuthorName: - matches = studyService.findByAuthor(searchTerm); - break; - case byTitle: - matches = studyService.findByTitle(keywordSearchTerm); - break; - case byKeyword: - matches = studyService.findByKeyword(keywordSearchTerm); - break; - default: - throw new Error ("Unknown search type '" + searchType + "'"); - } - SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), - new RequestMessageSetter(request), "No matching studies found"); - - saveSearchResults(request, newRes); - - return new ModelAndView("search/studySearch", Constants.RESULT_SET, newRes); + return matches; +// SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), +// new RequestMessageSetter(request), "No matching studies found"); +// +// saveSearchResults(request, newRes); +// +// return new ModelAndView("search/studySearch", Constants.RESULT_SET, newRes); } + /* private void validateTaxonSet(HttpServletRequest request, HttpServletResponse response, String searchTerm, BindException errors) { @@ -256,6 +380,7 @@ private String titleCase(String s) { return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); } + */ @Override SearchResultsType currentSearchType() { @@ -266,4 +391,38 @@ public String getDefaultViewURL() { return "studySearch.html"; } + + @Override + protected ModelAndView handleQueryRequest(HttpServletRequest request, + HttpServletResponse response, BindException errors) + throws CQLParseException, IOException, InstantiationException { + String query = request.getParameter("query"); + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Study> queryResults = doCQLQuery(root, new HashSet<Study>(),request, response, errors); + StudySearchResults tsr = new StudySearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/studySearch", Constants.RESULT_SET, tsr); + } + else { + SearchResults<?> res = tsr; + String schema = null; + if ( ! TreebaseUtil.isEmpty(request.getParameter("recordSchema")) ) { + schema = request.getParameter("recordSchema"); + if ( schema.equals("tree") ) { + res = tsr.convertToTrees(); + } + else if ( schema.equals("matrix") ) { + res = tsr.convertToMatrices(); + } + else if ( schema.equals("taxon") ) { + res = tsr.convertToTaxa(); + } + } + this.saveSearchResults(request, res); + return this.searchResultsAsRDF(res, request, root, schema, "study"); + } + } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2009-07-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -1,17 +1,20 @@ package org.cipres.treebase.web.controllers; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.cipres.treebase.TreebaseIDString; +import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; +import org.cipres.treebase.domain.search.MatrixSearchResults; +import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.domain.search.SearchService; import org.cipres.treebase.domain.search.TaxonSearchResults; @@ -19,16 +22,29 @@ import org.cipres.treebase.domain.taxon.TaxonHome; import org.cipres.treebase.domain.taxon.TaxonLabel; import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.cipres.treebase.domain.taxon.TaxonLabelService; import org.cipres.treebase.domain.taxon.TaxonVariant; import org.cipres.treebase.web.model.SearchCommand; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; +import org.z3950.zing.cql.CQLAndNode; +import org.z3950.zing.cql.CQLBooleanNode; +import org.z3950.zing.cql.CQLNode; +import org.z3950.zing.cql.CQLNotNode; +import org.z3950.zing.cql.CQLOrNode; +import org.z3950.zing.cql.CQLParseException; +import org.z3950.zing.cql.CQLParser; +import org.z3950.zing.cql.CQLRelation; +import org.z3950.zing.cql.CQLTermNode; public class TaxonSearchController extends SearchController { - static final Logger LOGGER = Logger.getLogger(TreeSearchController.class); + static final Logger LOGGER = Logger.getLogger(TaxonSearchController.class); private TaxonHome mTaxonHome; private TaxonLabelHome mTaxonLabelHome; + private enum SearchIndex { LABEL, ID }; + private enum SearchTable { TAXON, TAXONLABEL, TAXONVARIANT }; + private enum NamingAuthority { TREEBASE, UBIO, NCBI }; @Override protected ModelAndView onSubmit(HttpServletRequest request, @@ -36,10 +52,56 @@ throws Exception { clearMessages(request); String formName = request.getParameter("formName"); + String query = request.getParameter("query"); + if ( ! TreebaseUtil.isEmpty(query) ) { + /* + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Taxon> queryResults = doCQLQuery(root, new HashSet<Taxon>(),request); + TaxonSearchResults tsr = new TaxonSearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return samePage(request); + } + else { + return this.searchResultsAsRDF(tsr, request, root); + } + */ + return this.handleQueryRequest(request, response, errors); + } if (formName.equals("searchByTaxonLabel")) { SearchCommand newSearchCommand = (SearchCommand)searchCommand; - ModelAndView modelAndView = doTaxonSearch(request, response, newSearchCommand, errors); - return modelAndView; + String searchOn = request.getParameter("searchOn"); + String searchTerm = convertStars(request.getParameter("searchTerm")); + String[] searchTerms = searchTerm.split("\\r\\n"); + Collection<Taxon> taxa = new HashSet<Taxon>(); + for ( int i = 0; i < searchTerms.length; i++ ) { + if ( searchOn.equals("TextSearch") ) { + taxa.addAll(doTaxonSearch(request, newSearchCommand, searchTerms[i], SearchIndex.LABEL, null)); + } + else if ( searchOn.equals("Identifiers") ) { + String objectIdentifier = request.getParameter("objectIdentifier"); + if ( objectIdentifier.equals("TreeBASE") ) { + taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.TREEBASE)); + } + else if ( objectIdentifier.equals("NCBI") ) { + taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.NCBI)); + } + else if ( objectIdentifier.equals("uBio") ) { + taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.UBIO)); + } + } + } + TaxonSearchResults tsr = new TaxonSearchResults(taxa); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return samePage(request); + } + else { + return this.searchResultsAsRDF(tsr, request, null,"taxon","taxon"); + } + } else if (formName.equals("taxonResultsAction")) { return modifySearchResults(request, response, errors); } else { @@ -47,13 +109,99 @@ } } + private CQLNode normalizeParseTree(CQLNode node) { + if ( node instanceof CQLBooleanNode ) { + ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); + ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); + return node; + } + else if ( node instanceof CQLTermNode ) { + String index = ((CQLTermNode)node).getIndex(); + String term = ((CQLTermNode)node).getTerm(); + CQLRelation relation = ((CQLTermNode)node).getRelation(); + index = index.replaceAll("dcterms.title", "tb.title.taxon"); + index = index.replaceAll("dcterms.identifier", "tb.identifier.taxon"); + return new CQLTermNode(index,relation,term); + } + logger.debug(node); + return node; + } + + private Set<Taxon> doCQLQuery(CQLNode node, Set<Taxon> results, HttpServletRequest request) { + if ( node instanceof CQLBooleanNode ) { + Set<Taxon> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request); + Set<Taxon> resultsRight = doCQLQuery(((CQLBooleanNode)node).right,results, request); + if ( node instanceof CQLNotNode ) { + for ( Taxon rightTaxon : resultsRight ) { + if ( resultsLeft.contains(rightTaxon) ) { + resultsLeft.remove(rightTaxon); + } + } + } + else if ( node instanceof CQLOrNode ) { + resultsLeft.addAll(resultsRight); + } + else if ( node instanceof CQLAndNode ) { + Set<Taxon> resultsUnion = new HashSet<Taxon>(); + for ( Taxon leftTaxon : resultsLeft ) { + if ( resultsRight.contains(leftTaxon) ) { + resultsUnion.add(leftTaxon); + } + } + resultsLeft = resultsUnion; + } + results = resultsLeft; + } + else if ( node instanceof CQLTermNode ) { + CQLTermNode term = (CQLTermNode)node; + String index = term.getIndex(); + if ( index.startsWith("tb.title") ) { + boolean exactMatch = term.getRelation().getBase().equals("=="); + SearchTable searchTable = null; + if ( index.endsWith("taxonLabel") ) { + searchTable = SearchTable.TAXONLABEL; + } + else if ( index.endsWith("taxonVariant") ) { + searchTable = SearchTable.TAXONVARIANT; + } + else if ( index.endsWith("taxon") ) { + searchTable = SearchTable.TAXON; + } + boolean caseSensitive = true; + if ( ! term.getRelation().getModifiers().isEmpty() ) { + caseSensitive = ! term.getRelation().getModifiers().firstElement().getType().equalsIgnoreCase("ignoreCase"); + } + results.addAll(doTextSearch(term.getTerm(), caseSensitive, exactMatch, searchTable)); + } + else if ( index.startsWith("tb.identifier") ) { + NamingAuthority namingAuthority = null; + if ( index.endsWith("ncbi") ) { + namingAuthority = NamingAuthority.NCBI; + } + else if ( index.endsWith("ubio") ) { + namingAuthority = NamingAuthority.UBIO; + } + else { + namingAuthority = NamingAuthority.TREEBASE; + } + results.addAll(doIdentifierSearch(request, term.getTerm(), namingAuthority)); + } else { + // issue warnings + addMessage(request, "Unsupported index: " + index); + } + + } + logger.debug(node); + return results; + } + private ModelAndView modifySearchResults(HttpServletRequest request, HttpServletResponse response, BindException errors) throws InstantiationException { TaxonSearchResults results = searchResults(request).convertToTaxa(); String buttonName = request.getParameter("taxonResultsaction"); if (buttonName.equals("addCheckedToResults")) { - Map<String,String> parameterMap = request.getParameterMap(); +// Map<String,String> parameterMap = request.getParameterMap(); Collection<Taxon> newTaxa = new HashSet<Taxon> (); for (String taxonIdString : request.getParameterValues("selection")) { Taxon tx; @@ -72,36 +220,40 @@ return samePage(request); } - protected ModelAndView doTaxonSearch(HttpServletRequest request, - HttpServletResponse response, - SearchCommand searchCommand, BindException errors) throws Exception { - String searchTerm = convertStars(request.getParameter("searchTerm")); - String[] searchTerms = searchTerm.split("\\r\\n"); - String searchOn = request.getParameter("searchOn"); - //Collection<TaxonVariant> tvs = new ArrayList<TaxonVariant>(); + protected Collection<Taxon> doTaxonSearch(HttpServletRequest request, + SearchCommand searchCommand, String searchTerm, SearchIndex searchIndex, NamingAuthority namingAuthority) throws Exception { + Collection<Taxon> taxa = new HashSet<Taxon> (); - if ( searchOn.equals("TextSearch") ) { - taxa = doTextSearch(request,searchTerms); + switch(searchIndex) { + case LABEL: + String[] stringModifiers = request.getParameterValues("stringModifier"); + boolean caseSensitive = false; + boolean exactMatch = false; + if ( stringModifiers != null ) { + for ( int i = 0; i < stringModifiers.length; i++ ) { + if ( stringModifiers[i].equals("caseSensitive") ) { + caseSensitive = true; + } + if ( stringModifiers[i].equals("exactMatch") ) { + exactMatch = true; + } + } + } + for ( SearchTable searchTable : createSearchTableEnum(request) ) { + taxa.addAll(doTextSearch(searchTerm, caseSensitive, exactMatch, searchTable)); + } + break; + case ID: + taxa.addAll(doIdentifierSearch(request,searchTerm, namingAuthority)); + break; } - else if ( searchOn.equals("Identifiers") ) { - taxa = doIdentifierSearch(request,searchTerms); - } - /* - tvs = getTaxonLabelService().findTaxonVariantByFullName(searchTerm); - LOGGER.debug("Found " + tvs.size() + " tvs"); - for (TaxonVariant tv : tvs) { - if (tv.getTaxon() != null) taxa.add(tv.getTaxon()); - } - */ - getTaxonLabelService().resurrectAll(taxa); LOGGER.debug("Found " + taxa.size() + " taxa"); - - TaxonSearchResults tsr = new TaxonSearchResults(taxa); - //saveTempSearchResults(request, tsr); - saveSearchResults(request, tsr); - return samePage(request); + return taxa; +// TaxonSearchResults tsr = new TaxonSearchResults(taxa); +// saveSearchResults(request, tsr); +// return samePage(request); } /** @@ -110,44 +262,60 @@ * @param request * @param results */ - private Collection<Taxon> doIdentifierSearch(HttpServletRequest request,String[] identifiers) { - String objectIdentifier = request.getParameter("objectIdentifier"); + private Collection<Taxon> doIdentifierSearch(HttpServletRequest request, String identifier, NamingAuthority namingAuthority) { Collection<Taxon> taxaFound = new ArrayList<Taxon>(); - if ( objectIdentifier.equals("TreeBASE") ) { - LOGGER.debug("Going to search for TreeBASE IDs"); - for ( int i = 0; i < identifiers.length; i++ ) { + switch(namingAuthority) { + case TREEBASE : + LOGGER.debug("Going to search for TreeBASE IDs"); TreebaseIDString idstr; try { - idstr = new TreebaseIDString(identifiers[i], Taxon.class, true); + idstr = new TreebaseIDString(identifier, Taxon.class, true); + Taxon match = getTaxonHome().findPersistedObjectByID(idstr.getTBClass(), idstr.getId()); + if ( match != null ) { + taxaFound.add(match); + } } catch (MalformedTreebaseIDString e) { - addMessage(request, "Ignoring malformed taxon ID string '" + identifiers[i] + "'; try 'Tx####' or just a number"); - continue; + addMessage(request, "Ignoring malformed taxon ID string '" + identifier + "'; try 'Tx####' or just a number"); } - Taxon match = getTaxonHome().findPersistedObjectByID(idstr.getTBClass(), idstr.getId()); + break; + case NCBI : + LOGGER.debug("Going to search for NCBI taxon ids"); + Taxon match = getTaxonHome().findByNcbiTaxId(Integer.parseInt(identifier)); if ( match != null ) { taxaFound.add(match); } - } + break; + case UBIO : + LOGGER.debug("Going to search for uBio nameBankIDs"); + Taxon match1 = getTaxonHome().findByUBIOTaxId(Long.parseLong(identifier)); + if ( match1 != null ) { + taxaFound.add(match1); + } + break; } - else if ( objectIdentifier.equals("NCBI") ) { - LOGGER.debug("Going to search for NCBI taxon ids"); - for ( int i = 0; i < identifiers.length; i++ ) { - Taxon match = getTaxonHome().findByNcbiTaxId(Integer.parseInt(identifiers[i])); - if ( match != null ) { - taxaFound.add(match); - } + return taxaFound; + } + + /** + * + * @param request + * @return + */ + private Set<SearchTable> createSearchTableEnum(HttpServletRequest request) { + Set<SearchTable> results = new HashSet<SearchTable>(); + String[] stringProperties = request.getParameterValues("stringProperty"); + for ( int i = 0; i < stringProperties.length; i++ ) { + if ( stringProperties[i].equals("taxonLabel") ) { + results.add(SearchTable.TAXONLABEL); } - } - else if ( objectIdentifier.equals("uBio") ) { - LOGGER.debug("Going to search for uBio nameBankIDs"); - for ( int i = 0; i < identifiers.length; i++ ) { - Taxon match = getTaxonHome().findByUBIOTaxId(Long.parseLong(identifiers[i])); - if ( match != null ) { - taxaFound.add(match); - } + else if ( stringProperties[i].equals("taxonVariant") ) { + results.add(SearchTable.TAXONVARIANT); + } + else if ( stringProperties[i].equals("taxon") ) { + results.add(SearchTable.TAXON); } } - return taxaFound; + return results; } /** @@ -156,88 +324,50 @@ * @param request * @param results */ - private Collection<Taxon> doTextSearch(HttpServletRequest request, String[] stringPatterns) { + private Collection<Taxon> doTextSearch(String pattern, boolean caseSensitive, boolean exactMatch, SearchTable searchTable) { LOGGER.debug("Going to search for strings"); + LOGGER.debug("Case sensitive? " + caseSensitive); + LOGGER.debug("Exact match? " + exactMatch); + TaxonLabelService tls = getTaxonLabelService(); Collection<Taxon> taxaFound = new ArrayList<Taxon>(); - String[] stringProperties = request.getParameterValues("stringProperty"); - String[] stringModifiers = request.getParameterValues("stringModifier"); - boolean caseSensitive = false; - boolean exactMatch = false; - if ( stringModifiers != null ) { - for ( int i = 0; i < stringModifiers.length; i++ ) { - if ( stringModifiers[i].equals("caseSensitive") ) { - caseSensitive = true; + switch(searchTable) { + case TAXONLABEL : + LOGGER.debug("Will search taxon labels"); + Collection<TaxonLabel> labelsFound = exactMatch + ? tls.findByExactString(pattern) + : tls.findBySubstring(pattern, caseSensitive); + for ( TaxonLabel label : labelsFound ) { + if ( label.getTaxonVariant() != null && label.getTaxonVariant().getTaxon() != null ) { + taxaFound.add(label.getTaxonVariant().getTaxon()); + } } - if ( stringModifiers[i].equals("exactMatch") ) { - exactMatch = true; - } - } - } - LOGGER.debug("Case sensitive? " + caseSensitive); - LOGGER.debug("Exact match? " + exactMatch); - if ( stringProperties != null ) { - for ( int i = 0; i < stringProperties.length; i++ ) { - for ( int j = 0; j < stringPatterns.length; j++ ) { - if ( stringProperties[i].equals("taxonLabel") ) { - LOGGER.debug("Will search taxon labels"); - Collection<TaxonLabel> labelsFound = new ArrayList<TaxonLabel>(); - if ( exactMatch ) { - labelsFound = getTaxonLabelService().findByExactString(stringPatterns[j]); - } - else { - labelsFound = getTaxonLabelService().findBySubstring(stringPatterns[j], caseSensitive); - } - Iterator<TaxonLabel> labelsIterator = labelsFound.iterator(); - while ( labelsIterator.hasNext() ) { - TaxonLabel label = labelsIterator.next(); - TaxonVariant variant = label.getTaxonVariant(); - if ( variant != null ) { - Taxon taxon = variant.getTaxon(); - if ( taxon != null ) { - taxaFound.add(taxon); - } - } - } + break; + case TAXONVARIANT : + LOGGER.debug("Will search taxon variants"); + Collection<TaxonVariant> variantsFound = exactMatch + ? tls.findTaxonVariantByFullName(pattern) + : tls.findTaxonVariantWithSubstring(pattern, caseSensitive); + for ( TaxonVariant variant : variantsFound ) { + if ( variant.getTaxon() != null ) { + taxaFound.add(variant.getTaxon()); } - if ( stringProperties[i].equals("taxonVariant") ) { - LOGGER.debug("Will search taxon variants"); - Collection<TaxonVariant> variantsFound = new ArrayList<TaxonVariant>(); - if ( exactMatch ) { - variantsFound = getTaxonLabelService().findTaxonVariantByFullName(stringPatterns[j]); - } - else { - variantsFound = getTaxonLabelService().findTaxonVariantWithSubstring(stringPatterns[j], caseSensitive); - } - Iterator<TaxonVariant> variantsIterator = variantsFound.iterator(); - while ( variantsIterator.hasNext() ) { - TaxonVariant variant = variantsIterator.next(); - Taxon taxon = variant.getTaxon(); - if ( taxon != null ) { - taxaFound.add(taxon); - } - } - } - if ( stringProperties[i].equals("taxon") ) { - LOGGER.debug("Will search taxa"); - Collection<Taxon> tmpTaxaFound = new ArrayList<Taxon>(); - if ( exactMatch ) { - tmpTaxaFound = getTaxonLabelService().findTaxaByName(stringPatterns[j]); - } - else { - tmpTaxaFound = getTaxonLabelService().findTaxaBySubstring(stringPatterns[j], caseSensitive); - } - taxaFound.addAll(tmpTaxaFound); - } } - } + break; + case TAXON : + LOGGER.debug("Will search taxa"); + Collection<Taxon> tmpTaxaFound = exactMatch + ? tls.findTaxaByName(pattern) + : tls.findTaxaBySubstring(pattern, caseSensitive); + taxaFound.addAll(tmpTaxaFound); + break; } return taxaFound; } - private void saveTempSearchResults(HttpServletRequest request, - TaxonSearchResults taxonSearchResults) { - request.getSession().setAttribute("taxonSearchResults", taxonSearchResults); - } +// private void saveTempSearchResults(HttpServletRequest request, +// TaxonSearchResults taxonSearchResults) { +// request.getSession().setAttribute("taxonSearchResults", taxonSearchResults); +// } public void setSearchService(SearchService searchService) { this.searchService = searchService; @@ -268,4 +398,38 @@ public void setTaxonLabelHome(TaxonLabelHome taxonLabelHome) { mTaxonLabelHome = taxonLabelHome; } + + @Override + protected ModelAndView handleQueryRequest(HttpServletRequest request, + HttpServletResponse response, BindException errors) + throws CQLParseException, IOException, InstantiationException { + String query = request.getParameter("query"); + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<Taxon> queryResults = doCQLQuery(root, new HashSet<Taxon>(),request); + TaxonSearchResults tsr = new TaxonSearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return samePage(request); + } + else { + SearchResults<?> res = tsr; + String schema = null; + if ( ! TreebaseUtil.isEmpty(request.getParameter("recordSchema")) ) { + schema = request.getParameter("recordSchema"); + if ( schema.equals("tree" ) ) { + res = tsr.convertToTrees(); + } + else if ( schema.equals("matrix") ) { + res = tsr.convertToMatrices(); + } + else if ( schema.equals("study") ) { + res = tsr.convertToStudies(); + } + } + this.saveSearchResults(request, res); + return this.searchResultsAsRDF(res, request, root,schema,"taxon"); + } + } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2009-07-02 10:41:25 UTC (rev 158) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2009-07-02 10:43:46 UTC (rev 159) @@ -20,25 +20,35 @@ package org.cipres.treebase.web.controllers; -import java.util.ArrayList; +import java.io.IOException; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; +import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.RangeExpression.MalformedRangeExpression; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; -import org.cipres.treebase.domain.search.StudySearchResults; import org.cipres.treebase.domain.search.TreeSearchResults; -import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.tree.PhyloTree; import org.cipres.treebase.domain.tree.PhyloTreeService; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.util.RequestMessageSetter; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; +import org.z3950.zing.cql.CQLAndNode; +import org.z3950.zing.cql.CQLBooleanNode; +import org.z3950.zing.cql.CQLNode; +import org.z3950.zing.cql.CQLNotNode; +import org.z3950.zing.cql.CQLOrNode; +import org.z3950.zing.cql.CQLParseException; +import org.z3950.zing.cql.CQLParser; +import org.z3950.zing.cql.CQLRelation; +import org.z3950.zing.cql.CQLTermNode; /** * TreeSearchController.java @@ -73,50 +83,161 @@ clearMessages(request); String formName = request.getParameter("formName"); + String query = request.getParameter("query"); LOGGER.info("formName is '" + formName + "'"); - + if ( ! TreebaseUtil.isEmpty(query) ) { + /* + CQLParser parser = new CQLParser(); + CQLNode root = parser.parse(query); + root = normalizeParseTree(root); + Set<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request, response, errors); + TreeSearchResults tsr = new TreeSearchResults(queryResults); + saveSearchResults(request, tsr); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/treeSearch", Constants.RESULT_SET, tsr); + } + else { + return this.searchResultsAsRDF(tsr, request, root); + } + */ + return this.handleQueryRequest(request, response, errors); + } + if (formName.equals("treeSimple")) { String buttonName = request.getParameter("searchButton"); - + String searchTerm = convertStars(request.getParameter("searchTerm")); + Collection<PhyloTree> matches = null; + TreeSearchResults oldRes; + { + SearchResults<?> sr = searchResults(request); + if (sr != null) { + oldRes = (TreeSearchResults) sr.convertToTrees(); + } else { + oldRes = new TreeSearchResults (); // TODO: Convert existing search results to new type + } + } if (buttonName.equals("treeID")) { - return doSearch(request, response, SearchType.byID, errors); + matches = doSearch(request, response, SearchType.byID, errors, searchTerm); } else if (buttonName.equals("treeTitle")) { - return doSearch(request, response, SearchType.byTitle, errors); + matches = doSearch(request, response, SearchType.byTitle, errors, searchTerm); } else if (buttonName.equals("treeType")) { - return doSearch(request, response, SearchType.byType, errors); + matches = doSearch(request, response, SearchType.byType, errors, searchTerm); } else if (buttonName.equals("treeKind")) { - return doSearch(request, response, SearchType.byKind, errors); + matches = doSearch(request, response, SearchType.byKind, errors, searchTerm); } else if (buttonName.equals("treeQuality")) { - return doSearch(request, response, SearchType.byQuality, errors); + matches = doSearch(request, response, SearchType.byQuality, errors, searchTerm); } else if (buttonName.equals("treeNTAX")) { - return doSearch(request, response, SearchType.byNTAX, errors); + matches = doSearch(request, response, SearchType.byNTAX, errors, searchTerm); } else { throw new Error("Unknown search button name '" + buttonName + "'"); } + SearchResults<PhyloTree> newRes = intersectSearchResults(oldRes, new TreeSearchResults(matches), + new RequestMessageSetter(request), "No matching trees found"); + saveSearchResults(request, newRes); + if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { + return new ModelAndView("search/treeSearch", Constants.RESULT_SET, newRes); + } + else { + return this.searchResultsAsRDF(newRes, request, null,"tree","tree"); + } } else { return super.onSubmit(request, response, command, errors); } } - private ModelAndView doSearch( + private Set<PhyloTree> doCQLQuery( + CQLNode node, + Set<PhyloTree> results, + HttpServletRequest request, + HttpServletResponse response, + BindException errors + ) throws InstantiationException { + if ( node instanceof CQLBooleanNode ) { + Set<PhyloTree> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request, response, erro... [truncated message content] |
From: <rv...@us...> - 2010-01-14 14:28:27
|
Revision: 433 http://treebase.svn.sourceforge.net/treebase/?rev=433&view=rev Author: rvos Date: 2010-01-14 14:28:21 +0000 (Thu, 14 Jan 2010) Log Message: ----------- Added more logging messages. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AddAnalyzedDataController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisFormController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisStepFormController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTreeController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SummaryController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AddAnalyzedDataController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AddAnalyzedDataController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AddAnalyzedDataController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -9,6 +9,7 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; +import org.apache.log4j.Logger; import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.domain.admin.UserRole.TBPermission; import org.cipres.treebase.domain.matrix.Matrix; @@ -31,6 +32,7 @@ import org.cipres.treebase.web.util.ControllerUtil; public class AddAnalyzedDataController extends BaseFormController { + private static final Logger LOGGER = Logger.getLogger(AddAnalyzedDataController.class); private AnalysisService mAnalysisService; private StudyService mStudyService; private AnalysisStepService mAnalysisStepService; @@ -241,6 +243,7 @@ Study study; if (TreebaseUtil.isEmpty(submission_id)) { study = ControllerUtil.findStudy(request, mStudyService); + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true);// This is needed in case one is clicking at Summary // link at the bottom of the menu list on the right hand // side. @@ -255,8 +258,10 @@ Long.parseLong(submission_id)); if (perm2 == TBPermission.WRITE || perm2 == TBPermission.READ_ONLY || perm2 == TBPermission.SUBMITTED_WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return new ArticleCitation(); } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisFormController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisFormController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisFormController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -176,9 +176,11 @@ if (TreebaseUtil.isEmpty(analysis_id)) { if (perm == TBPermission.WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); return new Analysis(); } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return null; } @@ -195,11 +197,12 @@ // FIXME set a session variable to hide the edit buttons. } - + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); return analysis; } else { LOGGER.debug("NULL CONDITION SATISFIED"); + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return new Analysis(); } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisStepFormController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisStepFormController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AnalysisStepFormController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -326,9 +326,11 @@ if (TreebaseUtil.isEmpty(analysisStep_id)) { if (perm == TBPermission.WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); return analysisStepCommand; } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return null; } @@ -360,14 +362,14 @@ // FIXME set a session variable to hide the edit buttons. } - + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); return analysisStepCommand; } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("NULL CONDITION SATISFIED"); } - + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return analysisStepCommand; } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteStudyController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteStudyController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -135,8 +135,10 @@ TBPermission perm = getSubmissionService().getPermission(username, Long.parseLong(subid)); if (perm == TBPermission.WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTreeController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTreeController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -171,6 +171,7 @@ request.getRemoteUser(), submission_id); if (perm2 == TBPermission.WRITE || perm2 == TBPermission.SUBMITTED_WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); Collection<PhyloTree> phyloTreeList = treeblock.getTreeList(); ControllerUtil.setTreeBlockId(TBID, request); @@ -178,6 +179,7 @@ // This ID has to be saved for success/cancel view. return new AGenericList<Collection<PhyloTree>>(phyloTreeList); } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return new AGenericList<Collection<PhyloTree>>(new ArrayList<PhyloTree>()); } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SummaryController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SummaryController.java 2010-01-14 14:04:24 UTC (rev 432) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SummaryController.java 2010-01-14 14:28:21 UTC (rev 433) @@ -108,6 +108,7 @@ Study study; if (TreebaseUtil.isEmpty(submission_id)) { study = ControllerUtil.findStudy(request, mStudyService); + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true);// This is needed in case one is clicking at Summary // link at the bottom of the menu list on the right hand // side. @@ -122,8 +123,10 @@ Long.parseLong(submission_id)); if (perm2 == TBPermission.WRITE || perm2 == TBPermission.READ_ONLY || perm2 == TBPermission.SUBMITTED_WRITE) { + LOGGER.info("setAuthorizationChecked(true)"); setAuthorizationChecked(true); } else { + LOGGER.info("setAuthorizationChecked(false)"); setAuthorizationChecked(false); return new ArticleCitation(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-01-19 18:07:58
|
Revision: 477 http://treebase.svn.sourceforge.net/treebase/?rev=477&view=rev Author: rvos Date: 2010-01-19 18:07:52 +0000 (Tue, 19 Jan 2010) Log Message: ----------- Implemented getStudy in the download controllers. Each controller has its own way of reconstructing the focal study, but they all need to return it somehow so that access rights to the study can be established, either by it having been published or access having been granted to it explicitly through the reviewer access control system. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAMatrixController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -115,4 +115,10 @@ } } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + Matrix matrix = getMatrixService().findByID(objectId); + return matrix.getStudy(); + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusFileController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -140,6 +140,11 @@ return nexusString != null ? nexusString : "File Not Found. File Name is: " + nexusFileName; + } + + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + return ControllerUtil.findStudy(request, mStudyService); } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadANexusRCTFileController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -98,4 +98,9 @@ } } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + return ControllerUtil.findStudy(request, mStudyService); + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAStudyController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -89,4 +89,9 @@ return null; } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + return getStudyService().findByID(objectId); + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeBlockController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -8,6 +8,10 @@ import org.springframework.web.servlet.mvc.Controller; import org.cipres.treebase.domain.nexus.NexusDataSet; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.study.StudyService; +import org.cipres.treebase.domain.study.Submission; +import org.cipres.treebase.domain.study.SubmissionHome; import org.cipres.treebase.domain.tree.PhyloTreeHome; import org.cipres.treebase.domain.tree.TreeBlock; @@ -20,8 +24,44 @@ public class DownloadATreeBlockController extends AbstractDownloadController implements Controller { private PhyloTreeHome mPhyloTreeHome; + private StudyService mStudyService; + private SubmissionHome mSubmissionHome; + + /** + * Return the SubmissionHome field + * + * @return + */ + public SubmissionHome getSubmissionHome() { + return mSubmissionHome; + } + + /** + * Set the SubmissionHome field + * + * @param pSubmissionHome + */ + public void setSubmissionHome(SubmissionHome pSubmissionHome) { + mSubmissionHome = pSubmissionHome; + } /** + * Return the StudyService field. + * + * @return StudyService mStudyService + */ + public StudyService getStudyService() { + return mStudyService; + } + + /** + * Set the StudyService field. + */ + public void setStudyService(StudyService pNewStudyService) { + mStudyService = pNewStudyService; + } + + /** * @return the phyloTreeHome */ public PhyloTreeHome getPhyloTreeHome() { @@ -77,4 +117,11 @@ } } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + TreeBlock treeBlock = getPhyloTreeHome().findTreeBlockById(objectId); + Submission submission = getSubmissionHome().findByTreeBlock(treeBlock); + return submission.getStudy(); + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadATreeController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -125,4 +125,10 @@ } } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + PhyloTree tree = getPhyloTreeService().findByID(objectId); + return tree.getStudy(); + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2010-01-19 18:05:40 UTC (rev 476) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DownloadAnAnalysisStepController.java 2010-01-19 18:07:52 UTC (rev 477) @@ -17,6 +17,8 @@ import org.cipres.treebase.domain.study.AnalysisStep; import org.cipres.treebase.domain.study.AnalysisStepService; import org.cipres.treebase.domain.study.AnalyzedData; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.study.StudyService; import org.cipres.treebase.domain.taxon.TaxonLabelSet; import org.cipres.treebase.domain.tree.PhyloTree; import org.cipres.treebase.domain.tree.PhyloTreeService; @@ -34,8 +36,25 @@ private MatrixService mMatrixService; private PhyloTreeService mPhyloTreeService; private AnalysisStepService mAnalysisStepService; + private StudyService mStudyService; /** + * Return the StudyService field. + * + * @return StudyService mStudyService + */ + public StudyService getStudyService() { + return mStudyService; + } + + /** + * Set the StudyService field. + */ + public void setStudyService(StudyService pNewStudyService) { + mStudyService = pNewStudyService; + } + + /** * Return the PhyloTreeService field * * @return PhyloTreeService mPhyloTreeService @@ -95,7 +114,7 @@ if ( request.getParameter("analysisid") == null ) { return null; } - long analysisId = Long.parseLong(request.getParameter("analysisid")); + long analysisId = Long.parseLong(request.getParameter("analysisid")); generateAFileDynamically(request, response, analysisId); return null; } @@ -151,4 +170,10 @@ return stepContent.toString(); } + @Override + protected Study getStudy(long objectId, HttpServletRequest request) { + AnalysisStep step = getAnalysisStepService().findByID(objectId); + return step.getAnalysis().getStudy(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-06-02 14:42:52
|
Revision: 708 http://treebase.svn.sourceforge.net/treebase/?rev=708&view=rev Author: rvos Date: 2010-06-02 14:42:42 +0000 (Wed, 02 Jun 2010) Log Message: ----------- Fixes for issue 2992932 Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeTopSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -3,7 +3,9 @@ import java.io.IOException; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -71,21 +73,7 @@ LOGGER.info("formName is '" + formName + "'"); if ( ! TreebaseUtil.isEmpty(query) ) { - /* - CQLParser parser = new CQLParser(); - CQLNode root = parser.parse(query); - root = normalizeParseTree(root); - Set<Matrix> queryResults = doCQLQuery(root, new HashSet<Matrix>(),request, response, errors); - MatrixSearchResults tsr = new MatrixSearchResults(queryResults); - saveSearchResults(request, tsr); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, tsr); - } - else { - return this.searchResultsAsRDF(tsr, request, root); - } - */ - return this.handleQueryRequest(request, response, errors); + return this.handleQueryRequest(request, response, errors, query); } if (formName.equals("matrixSimple")) { @@ -180,27 +168,8 @@ } logger.debug(node); return results; - } + } - private CQLNode normalizeParseTree(CQLNode node) { - if ( node instanceof CQLBooleanNode ) { - ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); - ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); - return node; - } - else if ( node instanceof CQLTermNode ) { - String index = ((CQLTermNode)node).getIndex(); - String term = ((CQLTermNode)node).getTerm(); - CQLRelation relation = ((CQLTermNode)node).getRelation(); - index = index.replaceAll("dcterms.title", "tb.title.matrix"); - index = index.replaceAll("dcterms.identifier", "tb.identifier.matrix"); - index = index.replaceAll("dcterms.extent", "tb.ntax.matrix"); - return new CQLTermNode(index,relation,term); - } - logger.debug(node); - return node; - } - @SuppressWarnings("unchecked") private Collection<Matrix> doSearch( HttpServletRequest request, @@ -209,20 +178,6 @@ BindException errors, String searchTerm) throws InstantiationException { -// String searchTerm = convertStars(request.getParameter("searchTerm")); -// String keywordSearchTerm = "%" + searchTerm + "%"; -// SearchMessageSetter mSetter = new RequestMessageSetter(request); - -// MatrixSearchResults oldRes; -// { -// SearchResults<?> sr = searchResults(request); -// if (sr != null) { -// oldRes = (MatrixSearchResults) sr.convertToMatrices(); -// } else { -// oldRes = new MatrixSearchResults (); // TODO: Convert existing search results to new type -// } -// } - Collection<Matrix> matches = null; MatrixService matrixService = getSearchService().getMatrixService(); @@ -271,13 +226,6 @@ } matches.removeAll(orphanedMatrices); return matches; - -// SearchResults<Matrix> newRes = intersectSearchResults(oldRes, -// new MatrixSearchResults(matches), mSetter, "No matching matrices found"); -// -// saveSearchResults(request, newRes); -// -// return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, newRes); } @@ -291,8 +239,8 @@ } @Override - protected ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors) throws CQLParseException, IOException, InstantiationException { - String query = request.getParameter("query"); + protected ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors, String query) throws CQLParseException, IOException, InstantiationException { + //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); @@ -322,4 +270,13 @@ } } + @Override + protected Map<String, String> getPredicateMapping() { + Map<String,String> mapping = new HashMap<String,String>(); + mapping.put("dcterms.title", "tb.title.matrix"); + mapping.put("dcterms.identifier", "tb.identifier.matrix"); + mapping.put("dcterms.extent", "tb.ntax.matrix"); + return mapping; + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/SearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -35,8 +35,11 @@ import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; +import org.z3950.zing.cql.CQLBooleanNode; import org.z3950.zing.cql.CQLNode; import org.z3950.zing.cql.CQLParseException; +import org.z3950.zing.cql.CQLRelation; +import org.z3950.zing.cql.CQLTermNode; /** @@ -46,14 +49,51 @@ /** * Logger for this class */ - private static final Logger LOGGER = Logger.getLogger(SearchController.class); - + private static final Logger LOGGER = Logger.getLogger(SearchController.class); protected SearchService searchService; protected String formView; - private TaxonLabelService mTaxonLabelService; - protected abstract ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors) throws CQLParseException, IOException, InstantiationException; + protected abstract ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors,String query) throws CQLParseException, IOException, InstantiationException; + + /** + * Recursively traverses a CQL parse tree (presumably starting from its + * root node), replacing the observed indices with ones suggested by the map + * returned by getPredicateMapping(). The function of this is to allow concrete + * subclasses to create specific mappings from more general ones, e.g. when a + * study search query refers to the index "dcterms.identifier", the StudySearchController + * can specify that within its context this index is understood to mean "tb.identifier.study", + * i.e. the study ID. + * @param node + * @return + */ + protected CQLNode normalizeParseTree(CQLNode node) { + if ( node instanceof CQLBooleanNode ) { + ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); + ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); + return node; + } + else if ( node instanceof CQLTermNode ) { + String index = ((CQLTermNode)node).getIndex(); + String term = ((CQLTermNode)node).getTerm(); + CQLRelation relation = ((CQLTermNode)node).getRelation(); + Map<String,String> mapping = getPredicateMapping(); + for ( String key : mapping.keySet() ) { + index = index.replaceAll(key, mapping.get(key)); + } + return new CQLTermNode(index,relation,term); + } + logger.debug(node); + return node; + } + + /** + * Returns a mapping between more general search indices (e.g. "dcterms.identifier") + * and the specific indices (e.g. "tb.identifier.study") that are understood to be used + * by the concrete subclass + * @return + */ + protected abstract Map<String,String> getPredicateMapping(); protected ModelAndView onSubmit( HttpServletRequest request, @@ -399,7 +439,7 @@ String query = request.getParameter("query"); if ( query != null && ! TreebaseUtil.isEmpty(query) ) { LOGGER.info("query is '"+ query +"'"); - return this.handleQueryRequest(request, response, bindException); + return this.handleQueryRequest(request, response, bindException, query); } String action = request.getParameter("action"); if (action != null && action.equals("discard") && request.getMethod().equals("GET")) { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -3,7 +3,9 @@ import java.io.IOException; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -96,7 +98,7 @@ if ( ! TreebaseUtil.isEmpty(query) && ! query.equals("")) { LOGGER.info("query is '" + query + "'"); - return this.handleQueryRequest(request, response, errors); + return this.handleQueryRequest(request, response, errors, query); } if (formName.equals("searchKeyword")) { @@ -129,7 +131,9 @@ } else { throw new Error("Unknown search button name '" + buttonName + "'"); } - Collection<Study> matches = doSearch(request, response, searchType, errors,searchTerm); + // XXX we now never do an exact match with terms provided through the web app. We can change + // this, e.g. by adding a check box whose value is the boolean argument of doSearch() + Collection<Study> matches = doSearch(request, response, searchType, errors,searchTerm,false); if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), new RequestMessageSetter(request), "No matching studies found"); @@ -139,7 +143,8 @@ else { return this.searchResultsAsRDF(new StudySearchResults(matches), request, null,"study","study"); } - } else { + } + else { return super.onSubmit(request, response, command, errors); } } @@ -177,23 +182,24 @@ } else if ( node instanceof CQLTermNode ) { CQLTermNode term = (CQLTermNode)node; + boolean exactMatch = term.getRelation().getBase().equals("=="); String index = term.getIndex(); if ( index.startsWith("tb.title") ) { - results.addAll(doSearch(request, response, SearchType.byTitle, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byTitle, errors, term.getTerm(),exactMatch)); } else if ( index.equals("tb.identifier.study") ) { - results.addAll(doSearch(request, response, SearchType.byID, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byID, errors, term.getTerm(),exactMatch)); } else if ( index.startsWith("dcterms.contributor") ) { - results.addAll(doSearch(request, response, SearchType.byAuthorName, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byAuthorName, errors, term.getTerm(),exactMatch)); } else if ( index.startsWith("dcterms.abstract") ) { - results.addAll(doSearch(request, response, SearchType.inAbstract, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.inAbstract, errors, term.getTerm(),exactMatch)); } else if ( index.startsWith("dcterms.subject") ) { - results.addAll(doSearch(request, response, SearchType.byKeyword, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byKeyword, errors, term.getTerm(),exactMatch)); } else if ( index.startsWith("dcterms.bibliographicCitation") ) { - results.addAll(doSearch(request, response, SearchType.inCitation, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.inCitation, errors, term.getTerm(),exactMatch)); } else if ( index.equals("tb.identifier.study.tb1") ) { - results.addAll(doSearch(request, response, SearchType.byLegacyID, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byLegacyID, errors, term.getTerm(),exactMatch)); } else if ( index.startsWith("prism.publicationName") ) { - results.addAll(doSearch(request, response, SearchType.byJournal, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byJournal, errors, term.getTerm(),exactMatch)); } else { // issue warnings addMessage(request, "Unsupported index: " + index); @@ -201,48 +207,18 @@ } logger.debug(node); return results; - } + } - private CQLNode normalizeParseTree(CQLNode node) { - if ( node instanceof CQLBooleanNode ) { - ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); - ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); - return node; - } - else if ( node instanceof CQLTermNode ) { - String index = ((CQLTermNode)node).getIndex(); - String term = ((CQLTermNode)node).getTerm(); - CQLRelation relation = ((CQLTermNode)node).getRelation(); - index = index.replaceAll("dcterms.title", "tb.title.study"); - index = index.replaceAll("dcterms.identifier", "tb.identifier.study"); - return new CQLTermNode(index,relation,term); - } - logger.debug(node); - return node; - } - @SuppressWarnings("unchecked") protected Collection<Study> doSearch( HttpServletRequest request, HttpServletResponse response, SearchType searchType, BindException errors, - String searchTerm) throws InstantiationException { + String searchTerm, + boolean exactMatch) throws InstantiationException { -// String searchTerm = convertStars(request.getParameter("searchTerm")); String keywordSearchTerm = "%" + searchTerm + "%"; -// StudySearchResults oldRes; -// -// { -// SearchResults<?> sr = searchResults(request); -// if (sr != null) { -// oldRes = (StudySearchResults) sr.convertToStudies(); -// } else { -// oldRes = new StudySearchResults (); // TODO: Convert existing search results to new type -// } -// } -// -// LOGGER.info("doSearch old results contained " + oldRes.size() + " item(s)"); Collection<Study> matches; StudyService studyService = getSearchService().getStudyService(); @@ -283,79 +259,21 @@ matches = studyService.findByKeyword(keywordSearchTerm); break; case byJournal: - matches = studyService.findByJournal(keywordSearchTerm, false); + { + if ( exactMatch ) { + matches = studyService.findByJournal(searchTerm, exactMatch); + } else { + matches = studyService.findByJournal(keywordSearchTerm, exactMatch); + } break; + } default: throw new Error ("Unknown search type '" + searchType + "'"); } return matches; -// SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), -// new RequestMessageSetter(request), "No matching studies found"); -// -// saveSearchResults(request, newRes); -// -// return new ModelAndView("search/studySearch", Constants.RESULT_SET, newRes); } - /* - private void validateTaxonSet(HttpServletRequest request, - HttpServletResponse response, String searchTerm, - BindException errors) { - String[] taxonStrings = getTaxonStrings(searchTerm); - List<String> unrecognizedTaxa = new LinkedList<String> (); - List<String> recognizedTaxa = new LinkedList<String> (); - - Collection<TaxonLabel> taxonLabels = stringsToTaxonLabels(taxonStrings); - request.setAttribute("taxonLabelSetOverride", taxonLabels); - - for (TaxonLabel tl : taxonLabels) { - TaxonVariant variant = getTaxonLabelService().findTaxonVariant(tl); - if (variant == null) { - variant = getTaxonLabelService().createFromUBIOService(tl); - if (variant == null) { - unrecognizedTaxa.add(tl.getTaxonLabel()); - } else { - recognizedTaxa.add(tl.getTaxonLabel()); - } - } else { - recognizedTaxa.add(variant.getName()); - } - } - - LOGGER.info("validateTaxonSet: of " - + taxonStrings.length - + " entered taxa, " - + unrecognizedTaxa.size() - + " was/were unrecognized: " - + unrecognizedTaxa.toString()); - - request.setAttribute("unrecognizedTaxa", unrecognizedTaxa); - request.setAttribute("taxonLabels", joinStrings(recognizedTaxa)); - return; - } - - private String joinStrings(Collection<String> strings) { - String result = ""; - for (String s : strings) { - result = result + s + "\n"; - } - return result; - } - - private Collection<TaxonLabel> stringsToTaxonLabels(String[] taxonStrings) { - Collection<TaxonLabel> tls = new LinkedList<TaxonLabel>(); - for (String s : taxonStrings) { - tls.add(new TaxonLabel(titleCase(s))); - } - return tls; - } - - private String titleCase(String s) { - return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); - } - */ - @Override SearchResultsType currentSearchType() { return SearchResultsType.STUDY; @@ -368,9 +286,9 @@ @Override protected ModelAndView handleQueryRequest(HttpServletRequest request, - HttpServletResponse response, BindException errors) + HttpServletResponse response, BindException errors,String query) throws CQLParseException, IOException, InstantiationException { - String query = request.getParameter("query"); + //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); @@ -399,4 +317,12 @@ return this.searchResultsAsRDF(res, request, root, schema, "study"); } } + + @Override + protected Map<String, String> getPredicateMapping() { + Map<String,String> mapping = new HashMap<String,String>(); + mapping.put("dcterms.title", "tb.title.study"); + mapping.put("dcterms.identifier", "tb.identifier.study"); + return mapping; + } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -3,7 +3,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -54,21 +56,7 @@ String formName = request.getParameter("formName"); String query = request.getParameter("query"); if ( ! TreebaseUtil.isEmpty(query) ) { - /* - CQLParser parser = new CQLParser(); - CQLNode root = parser.parse(query); - root = normalizeParseTree(root); - Set<Taxon> queryResults = doCQLQuery(root, new HashSet<Taxon>(),request); - TaxonSearchResults tsr = new TaxonSearchResults(queryResults); - saveSearchResults(request, tsr); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - return samePage(request); - } - else { - return this.searchResultsAsRDF(tsr, request, root); - } - */ - return this.handleQueryRequest(request, response, errors); + return this.handleQueryRequest(request, response, errors, query); } if (formName.equals("searchByTaxonLabel")) { SearchCommand newSearchCommand = (SearchCommand)searchCommand; @@ -109,24 +97,6 @@ } } - private CQLNode normalizeParseTree(CQLNode node) { - if ( node instanceof CQLBooleanNode ) { - ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); - ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); - return node; - } - else if ( node instanceof CQLTermNode ) { - String index = ((CQLTermNode)node).getIndex(); - String term = ((CQLTermNode)node).getTerm(); - CQLRelation relation = ((CQLTermNode)node).getRelation(); - index = index.replaceAll("dcterms.title", "tb.title.taxon"); - index = index.replaceAll("dcterms.identifier", "tb.identifier.taxon"); - return new CQLTermNode(index,relation,term); - } - logger.debug(node); - return node; - } - private Set<Taxon> doCQLQuery(CQLNode node, Set<Taxon> results, HttpServletRequest request) { if ( node instanceof CQLBooleanNode ) { Set<Taxon> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request); @@ -401,9 +371,9 @@ @Override protected ModelAndView handleQueryRequest(HttpServletRequest request, - HttpServletResponse response, BindException errors) + HttpServletResponse response, BindException errors, String query) throws CQLParseException, IOException, InstantiationException { - String query = request.getParameter("query"); + //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); @@ -432,4 +402,12 @@ return this.searchResultsAsRDF(res, request, root,schema,"taxon"); } } + + @Override + protected Map<String, String> getPredicateMapping() { + Map<String,String> mapping = new HashMap<String,String>(); + mapping.put("dcterms.title", "tb.title.taxon"); + mapping.put("dcterms.identifier", "tb.identifier.taxon"); + return mapping; + } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -3,7 +3,9 @@ import java.io.IOException; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -69,21 +71,7 @@ LOGGER.info("formName is '" + formName + "'"); if ( ! TreebaseUtil.isEmpty(query) ) { - /* - CQLParser parser = new CQLParser(); - CQLNode root = parser.parse(query); - root = normalizeParseTree(root); - Set<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request, response, errors); - TreeSearchResults tsr = new TreeSearchResults(queryResults); - saveSearchResults(request, tsr); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - return new ModelAndView("search/treeSearch", Constants.RESULT_SET, tsr); - } - else { - return this.searchResultsAsRDF(tsr, request, root); - } - */ - return this.handleQueryRequest(request, response, errors); + return this.handleQueryRequest(request, response, errors, query); } if (formName.equals("treeSimple")) { @@ -180,25 +168,6 @@ logger.debug(node); return results; } - - private CQLNode normalizeParseTree(CQLNode node) { - if ( node instanceof CQLBooleanNode ) { - ((CQLBooleanNode)node).left = normalizeParseTree(((CQLBooleanNode)node).left); - ((CQLBooleanNode)node).right = normalizeParseTree(((CQLBooleanNode)node).right); - return node; - } - else if ( node instanceof CQLTermNode ) { - String index = ((CQLTermNode)node).getIndex(); - String term = ((CQLTermNode)node).getTerm(); - CQLRelation relation = ((CQLTermNode)node).getRelation(); - index = index.replaceAll("dcterms.title", "tb.title.tree"); - index = index.replaceAll("dcterms.identifier", "tb.identifier.tree"); - index = index.replaceAll("dcterms.extent", "tb.ntax.tree"); - return new CQLTermNode(index,relation,term); - } - logger.debug(node); - return node; - } @SuppressWarnings("unchecked") private Collection<PhyloTree> doSearch( @@ -208,18 +177,6 @@ BindException errors, String searchTerm) throws InstantiationException { -// String searchTerm = convertStars(request.getParameter("searchTerm")); -// String keywordSearchTerm = "%" + searchTerm + "%"; -// TreeSearchResults oldRes; -// { -// SearchResults<?> sr = searchResults(request); -// if (sr != null) { -// oldRes = (TreeSearchResults) sr.convertToTrees(); -// } else { -// oldRes = new TreeSearchResults (); // TODO: Convert existing search results to new type -// } -// } - Collection<PhyloTree> matches = null; PhyloTreeService phyloTreeService = getSearchService().getPhyloTreeService(); @@ -279,9 +236,9 @@ @Override protected ModelAndView handleQueryRequest(HttpServletRequest request, - HttpServletResponse response, BindException errors) + HttpServletResponse response, BindException errors, String query) throws CQLParseException, IOException, InstantiationException { - String query = request.getParameter("query"); + //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); @@ -311,4 +268,13 @@ } } + @Override + protected Map<String, String> getPredicateMapping() { + Map<String,String> mapping = new HashMap<String,String>(); + mapping.put("dcterms.title", "tb.title.tree"); + mapping.put("dcterms.identifier", "tb.identifier.tree"); + mapping.put("dcterms.extent", "tb.ntax.tree"); + return mapping; + } + } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeTopSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeTopSearchController.java 2010-06-02 13:27:57 UTC (rev 707) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeTopSearchController.java 2010-06-02 14:42:42 UTC (rev 708) @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -20,6 +21,7 @@ import org.cipres.treebase.web.Constants; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; +import org.z3950.zing.cql.CQLNode; import org.z3950.zing.cql.CQLParseException; /** @@ -189,10 +191,22 @@ @Override protected ModelAndView handleQueryRequest(HttpServletRequest request, - HttpServletResponse response, BindException errors) + HttpServletResponse response, BindException errors, String query) throws CQLParseException, IOException, InstantiationException { // TODO Auto-generated method stub return null; } + @Override + protected CQLNode normalizeParseTree(CQLNode node) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Map<String, String> getPredicateMapping() { + // TODO Auto-generated method stub + return null; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2011-04-08 17:53:24
|
Revision: 781 http://treebase.svn.sourceforge.net/treebase/?rev=781&view=rev Author: hshyket Date: 2011-04-08 17:53:18 +0000 (Fri, 08 Apr 2011) Log Message: ----------- Fixed bug where the Dryad import was not populating the study_nexusfile nexus text field. Added a Unix timestamp to file uploads so that each name is unique. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java 2011-03-30 18:58:25 UTC (rev 780) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java 2011-04-08 17:53:18 UTC (rev 781) @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; @@ -91,10 +92,24 @@ study.setCitation(citation); citation.setStudy(study); Submission submission = mSubmissionService.createSubmission(user, study); + long unixTime = System.currentTimeMillis() / 1000L; List<File> files = DryadUtil.getDataFiles(dataPath); - for(int i=0; i<files.size(); i++ ) - submission.getStudy().addNexusFile(files.get(i).getName(), "NEXUS"); + for(int i=0; i<files.size(); i++ ) { + String copyDir = request.getSession().getServletContext() + .getRealPath(TreebaseUtil.FILESEP + "NexusFileUpload") + + TreebaseUtil.FILESEP + request.getRemoteUser(); + + File originalFile = new File(files.get(i).getAbsolutePath()); + File copyFile = new File(copyDir + TreebaseUtil.FILESEP + unixTime + "_" + files.get(i).getName()); + + FileUtils.copyFile(originalFile, copyFile); + + files.remove(i); + files.add(i,copyFile); + + submission.getStudy().addNexusFile(files.get(i).getName(), TreebaseUtil.readFileToString(files.get(i))); + } MyProgressionListener listener = new MyProgressionListener(); getSubmissionService().addNexusFilesJDBC(submission, files, listener); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java 2011-03-30 18:58:25 UTC (rev 780) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java 2011-04-08 17:53:18 UTC (rev 781) @@ -167,13 +167,19 @@ List<File> files = new ArrayList<File>(); String firstFile = null; + + long unixTime = System.currentTimeMillis() / 1000L; + for (FileBean file : getFiles(request)) { if (LOGGER.isDebugEnabled()) { LOGGER .debug("Uploading file to =>" + uploadDir + TreebaseUtil.FILESEP + file.getName()); //$NON-NLS-1$ } + + file.setName(unixTime + "_" + file.getName()); File uploadedFile = new File(uploadDir + TreebaseUtil.FILESEP + file.getName()); + FileCopyUtils.copy(file.getData(), uploadedFile); files.add(uploadedFile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2011-04-11 19:01:11
|
Revision: 782 http://treebase.svn.sourceforge.net/treebase/?rev=782&view=rev Author: hshyket Date: 2011-04-11 19:01:05 +0000 (Mon, 11 Apr 2011) Log Message: ----------- Prefixing a number to the timestamp to avoid the issue of duplicate file uploads Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java 2011-04-08 17:53:18 UTC (rev 781) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java 2011-04-11 19:01:05 UTC (rev 782) @@ -4,7 +4,9 @@ import java.io.FileFilter; import java.util.Collection; import java.util.List; +import java.util.HashMap; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -94,15 +96,39 @@ Submission submission = mSubmissionService.createSubmission(user, study); long unixTime = System.currentTimeMillis() / 1000L; - List<File> files = DryadUtil.getDataFiles(dataPath); - for(int i=0; i<files.size(); i++ ) { + List<File> files = DryadUtil.getDataFiles(dataPath); + HashMap<String, Integer> filenamesHash = new HashMap<String, Integer>(); + for(int i=0; i<files.size(); i++ ) { + + int filecount = 1; + + File originalFile = new File(files.get(i).getAbsolutePath()); + + /* This keeps a hashmap of the files so that going through it knows the count of each file + * Each file then has a prefix of the count and unix timestamp of the upload + */ + + if (filenamesHash.containsKey(originalFile.getName())) { + filecount = filenamesHash.get(originalFile.getName()) + 1; + filenamesHash.put(originalFile.getName(), filecount); + } + else { + filenamesHash.put(originalFile.getName(), filecount); + } + String copyDir = request.getSession().getServletContext() .getRealPath(TreebaseUtil.FILESEP + "NexusFileUpload") + TreebaseUtil.FILESEP + request.getRemoteUser(); - File originalFile = new File(files.get(i).getAbsolutePath()); - File copyFile = new File(copyDir + TreebaseUtil.FILESEP + unixTime + "_" + files.get(i).getName()); + File copyFile = new File(copyDir + + TreebaseUtil.FILESEP + + filenamesHash.get(originalFile.getName()) + + "_" + + unixTime + + "_" + + files.get(i).getName()); + FileUtils.copyFile(originalFile, copyFile); files.remove(i); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java 2011-04-08 17:53:18 UTC (rev 781) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/UploadFileController.java 2011-04-11 19:01:05 UTC (rev 782) @@ -3,6 +3,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -169,14 +170,29 @@ String firstFile = null; long unixTime = System.currentTimeMillis() / 1000L; - + HashMap<String, Integer> filenamesHash = new HashMap<String, Integer>(); + for (FileBean file : getFiles(request)) { if (LOGGER.isDebugEnabled()) { LOGGER .debug("Uploading file to =>" + uploadDir + TreebaseUtil.FILESEP + file.getName()); //$NON-NLS-1$ } - file.setName(unixTime + "_" + file.getName()); + /* This keeps a hashmap of the files so that going through it knows the count of each file + * Each file then has a prefix of the count and unix timestamp of the upload + */ + + int filecount = 1; + + if (filenamesHash.containsKey(file.getName())) { + filecount = filenamesHash.get(file.getName()) + 1; + filenamesHash.put(file.getName(), filecount); + } + else { + filenamesHash.put(file.getName(), filecount); + } + + file.setName(filecount + "_" + unixTime + "_" + file.getName()); File uploadedFile = new File(uploadDir + TreebaseUtil.FILESEP + file.getName()); 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:45:43
|
Revision: 805 http://treebase.svn.sourceforge.net/treebase/?rev=805&view=rev Author: rvos Date: 2011-04-25 22:45:37 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Changed hasWebPage method to use type prefix instead of class (which perhaps needs to be coerced first?) Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.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:27:59 UTC (rev 804) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-25 22:45:37 UTC (rev 805) @@ -58,7 +58,7 @@ NamespacedGUID namespacedGUID = new NamespacedGUID(substr); TreebaseIDString tbID = namespacedGUID.getTreebaseIDString(); String serializationFormat = createSerializationFormat(req); - if ( hasWebPage(tbID.getClass()) && ! TreebaseUtil.isEmpty(serializationFormat) ) { + if ( hasWebPage(tbID.getTypePrefix()) && ! TreebaseUtil.isEmpty(serializationFormat) ) { // output format is html, re-direct to display services if ( serializationFormat.equals("html") ) { @@ -149,7 +149,7 @@ * @param pathComponents * @return true of web page exists, false otherwise */ - abstract boolean hasWebPage(Class<?> theClass); + abstract boolean hasWebPage(String prefix); /** * Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2011-04-25 22:27:59 UTC (rev 804) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2011-04-25 22:45:37 UTC (rev 805) @@ -43,8 +43,8 @@ } @Override - boolean hasWebPage(Class<?> theClass) { - return Matrix.class.isAssignableFrom(theClass); + boolean hasWebPage(String prefix) { + return "M".equals(prefix); } public MatrixService getMatrixService() { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2011-04-25 22:27:59 UTC (rev 804) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2011-04-25 22:45:37 UTC (rev 805) @@ -37,8 +37,8 @@ } @Override - boolean hasWebPage(Class<?> theClass) { - return Study.class.isAssignableFrom(theClass); + boolean hasWebPage(String prefix) { + return "S".equals(prefix); } public StudyService getStudyService() { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java 2011-04-25 22:27:59 UTC (rev 804) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java 2011-04-25 22:45:37 UTC (rev 805) @@ -3,8 +3,6 @@ import java.util.HashMap; import java.util.Map; -import org.cipres.treebase.domain.taxon.TaxonLabel; - public class PhyloWSTaxonController extends PhyloWSController { @Override @@ -30,8 +28,8 @@ } @Override - boolean hasWebPage(Class<?> theClass) { - return TaxonLabel.class.isAssignableFrom(theClass); + boolean hasWebPage(String prefix) { + return false; } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2011-04-25 22:27:59 UTC (rev 804) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2011-04-25 22:45:37 UTC (rev 805) @@ -43,8 +43,8 @@ } @Override - boolean hasWebPage(Class<?> theClass) { - return PhyloTree.class.isAssignableFrom(theClass); + boolean hasWebPage(String prefix) { + return "Tr".equals(prefix); } public PhyloTreeService getPhyloTreeService() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-04-26 00:28:57
|
Revision: 806 http://treebase.svn.sourceforge.net/treebase/?rev=806&view=rev Author: rvos Date: 2011-04-26 00:28:51 +0000 (Tue, 26 Apr 2011) Log Message: ----------- Added documentation. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.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:45:37 UTC (rev 805) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2011-04-26 00:28:51 UTC (rev 806) @@ -16,19 +16,59 @@ import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; import org.cipres.treebase.web.Constants; +/** + * This class re-directs clients to one of a number of other controllers depending + * on the provided URL pattern. Here are the patterns. Where it says 'study' in the + * example patterns, it can equally say 'matrix', 'tree' or 'taxon'. The part that + * says 'TB2:S1787' is supposed to be a valid NamespacedGUID: + * <ul> + * <li> + * - /phylows/study/TB2:S1787 - this is the general pattern for stable resource + * URLs, without a query string. URLs of this kind are sent on to the AnyObjectAsRDFController. + * If you want to work on content-negotiation, go there. The re-direct URL is generated by + * the method createResourceUrl + * </li> + * + * <li> + * - /phylows/study/TB2:S1787?format=html - this is the pattern for the web page + * version of a resource. URLs of this kind are sent on to the SearchSummaryController, except + * for trees, which are sent to the SearchMapToPhyloWidgetController. The re-direct URL is + * generated by the method createDisplayUrl + * </li> + * + * <li> + * - /phylows/study/TB2:S1787?format=nexml - this is the pattern for any other available + * serialization of the resource (i.e. nexml|nexus|rdf). URLs of this kind are sent to the + * downloadA*Controller controller (e.g. Matrix|Study|Tree). If an output format isn't + * working as it should, look in the download controllers (and the core services that ultimately + * produce the output). The re-direct URL is generated by the method createDownloadUrl + * </li> + * + * <li> + * - /phylows/study/find?query=... - this is the pattern for search queries. URLs of this + * kind are sent to the *SearchController controllers (e.g. Matrix|Study|Tree). To debug + * CQL queries, look in those controllers, as the class you are looking at now doesn't + * process CQL at all. The re-direct URL is generated by the method createSearchUrl + * </li> + * </ul> + * @author rvosa + * + */ + public abstract class PhyloWSController implements Controller { private static final long serialVersionUID = 1L; private static String searchBase = "/treebase-web/search/"; /** - * + * Child classes return the display page for the focal type + * of objects, e.g. for matrices, this returns "matrix.html" * @return */ abstract String getDisplayPage(); /** * Given an object ID and a servlet request object, constructs - * a relative URL to an HTML page about that object. + * a relative URL to an HTML display page about that object. * @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 @@ -42,7 +82,8 @@ } /** - * + * Here the actual request is handled. See the class introduction at + * the top of this file for an overview of the logic implemented here. */ public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException { String url = null; @@ -91,7 +132,9 @@ } /** - * + * Given a NamespacedGUID, which is a wrapper around an ID such as TB2:S1787, and + * a request object, returns a URL for the resource description of the object identified + * by the NamespacedGUID. * @param guid * @param req * @return @@ -114,13 +157,17 @@ } /** - * + * Child classes here return the search page; e.g. for matrices, returns "matrixSearch.html" * @return */ abstract String getSearchPage(); /** - * + * Constructs the URL that re-directs to the *SearchController classes. This involves: + * the getSearchPage() output (which identifies the seach controller), the CQL query, + * the output format (either rss1, or a web page in all other cases) and the recordSchema, + * which is used to project a search result set (e.g. a set of studies) into another class + * (e.g. the set of trees for those studies). * @param request * @return */ @@ -144,15 +191,21 @@ } /** - * Given an array of path fragments, returns whether an HTML web page - * exists for the type of object the fragments map onto + * Given an ID prefix (as per those of TreebaseIDString), returns whether an HTML web page + * exists for the type of object the prefix identifies * @param pathComponents * @return true of web page exists, false otherwise */ abstract boolean hasWebPage(String prefix); /** - * + * Child classes return a map of query string parameters and their values. Typically these + * are the study id (parameter name "id") and the id of an object in that study, e.g. + * a "matrixid" or a "treeid". In the latter cases where we look for objects in a study + * (not the study per se) we first need to look up those objects, and then fetch the study + * for them. Hence we need to interact with service objects, which potentially might not + * be able to find the object identified by objectId, hence we may throw an ObjectNotFoundException + * here. * @param objectId * @return * @throws ObjectNotFoundException @@ -160,7 +213,9 @@ abstract Map<String,String> getObjectQueryParameters(Long objectId) throws ObjectNotFoundException; /** - * + * Creates a URL by concatenating the base + ? + the params as query string parameters, i.e. + * key1=value1&key2=value2 + potentially the x-access-code parameter, when dealing with + * embargoed objects * @param base * @param params * @return @@ -183,13 +238,17 @@ /** - * + * Child classes return the focal download page here, e.g. for matrices, returns + * "downloadAMatrix.html" * @return */ abstract String getDownloadPage(); /** - * + * Creates the URL that re-directs to the DownloadA*Controllers. This involves concatenating + * getDownloadPage() with the query string parameters to identify the object to download, the + * format in which to serialize it (and potentially the x-access-code parameter, for + * embargoed objects). * @param objectId * @param format * @return @@ -204,7 +263,8 @@ } /** - * + * Exceptions of this kind are thrown when a non-existent objectId somehow ends up + * in a URL. * @author rvosa * */ Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2011-04-25 22:45:37 UTC (rev 805) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2011-04-26 00:28:51 UTC (rev 806) @@ -11,16 +11,28 @@ private MatrixService mMatrixService; + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getSearchPage() + */ @Override String getSearchPage() { return "matrixSearch.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDownloadPage() + */ @Override String getDownloadPage() { return "downloadAMatrix.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getObjectQueryParameters(java.lang.Long) + */ @Override Map<String,String> getObjectQueryParameters(Long objectId) throws ObjectNotFoundException { Matrix matrix = getMatrixService().findByID(objectId); @@ -37,11 +49,19 @@ return params; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDisplayPage() + */ @Override String getDisplayPage() { return "matrix.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#hasWebPage(java.lang.String) + */ @Override boolean hasWebPage(String prefix) { return "M".equals(prefix); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2011-04-25 22:45:37 UTC (rev 805) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2011-04-26 00:28:51 UTC (rev 806) @@ -10,16 +10,28 @@ private StudyService mStudyService; + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getSearchPage() + */ @Override String getSearchPage() { return "studySearch.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDownloadPage() + */ @Override String getDownloadPage() { return "downloadAStudy.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getObjectQueryParameters(java.lang.Long) + */ @Override Map<String,String> getObjectQueryParameters(Long objectId) throws ObjectNotFoundException { Study study = getStudyService().findByID(objectId); @@ -31,11 +43,19 @@ return params; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDisplayPage() + */ @Override String getDisplayPage() { return "summary.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#hasWebPage(java.lang.String) + */ @Override boolean hasWebPage(String prefix) { return "S".equals(prefix); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java 2011-04-25 22:45:37 UTC (rev 805) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTaxonController.java 2011-04-26 00:28:51 UTC (rev 806) @@ -5,28 +5,48 @@ public class PhyloWSTaxonController extends PhyloWSController { + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getSearchPage() + */ @Override String getSearchPage() { return "taxonSearch.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDownloadPage() + */ @Override String getDownloadPage() { return "downloadATaxon.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getObjectQueryParameters(java.lang.Long) + */ @Override Map<String,String> getObjectQueryParameters(Long objectId) throws ObjectNotFoundException { // TODO Auto-generated method stub return new HashMap<String,String>(); } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDisplayPage() + */ @Override String getDisplayPage() { // TODO Auto-generated method stub return "taxon.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#hasWebPage(java.lang.String) + */ @Override boolean hasWebPage(String prefix) { return false; Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2011-04-25 22:45:37 UTC (rev 805) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2011-04-26 00:28:51 UTC (rev 806) @@ -11,16 +11,28 @@ private PhyloTreeService mPhyloTreeService; + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getSearchPage() + */ @Override String getSearchPage() { return "treeSearch.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDownloadPage() + */ @Override String getDownloadPage() { return "downloadATree.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getObjectQueryParameters(java.lang.Long) + */ @Override Map<String,String> getObjectQueryParameters(Long objectId) throws ObjectNotFoundException { PhyloTree phyloTree = getPhyloTreeService().findByID(objectId); @@ -37,11 +49,19 @@ return params; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#getDisplayPage() + */ @Override String getDisplayPage() { return "tree.html"; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.web.controllers.PhyloWSController#hasWebPage(java.lang.String) + */ @Override boolean hasWebPage(String prefix) { return "Tr".equals(prefix); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-04-29 00:21:35
|
Revision: 820 http://treebase.svn.sourceforge.net/treebase/?rev=820&view=rev Author: rvos Date: 2011-04-29 00:21:29 +0000 (Fri, 29 Apr 2011) Log Message: ----------- Reverting Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2011-04-29 00:20:39 UTC (rev 819) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2011-04-29 00:21:29 UTC (rev 820) @@ -20,7 +20,6 @@ import org.cipres.treebase.domain.search.MatrixSearchResults; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; -import org.cipres.treebase.domain.search.TreeSearchResults; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.util.RequestMessageSetter; import org.cipres.treebase.web.util.SearchMessageSetter; @@ -33,7 +32,6 @@ import org.z3950.zing.cql.CQLOrNode; import org.z3950.zing.cql.CQLParseException; import org.z3950.zing.cql.CQLParser; -import org.z3950.zing.cql.CQLRelation; import org.z3950.zing.cql.CQLTermNode; /** Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2011-04-29 00:20:39 UTC (rev 819) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2011-04-29 00:21:29 UTC (rev 820) @@ -31,7 +31,6 @@ import org.z3950.zing.cql.CQLOrNode; import org.z3950.zing.cql.CQLParseException; import org.z3950.zing.cql.CQLParser; -import org.z3950.zing.cql.CQLRelation; import org.z3950.zing.cql.CQLTermNode; /** Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2011-04-29 00:20:39 UTC (rev 819) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2011-04-29 00:21:29 UTC (rev 820) @@ -15,7 +15,6 @@ import org.cipres.treebase.TreebaseIDString; import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; -import org.cipres.treebase.domain.search.MatrixSearchResults; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.domain.search.SearchService; @@ -36,7 +35,6 @@ import org.z3950.zing.cql.CQLOrNode; import org.z3950.zing.cql.CQLParseException; import org.z3950.zing.cql.CQLParser; -import org.z3950.zing.cql.CQLRelation; import org.z3950.zing.cql.CQLTermNode; public class TaxonSearchController extends SearchController { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2011-04-29 00:20:39 UTC (rev 819) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2011-04-29 00:21:29 UTC (rev 820) @@ -30,7 +30,6 @@ import org.z3950.zing.cql.CQLOrNode; import org.z3950.zing.cql.CQLParseException; import org.z3950.zing.cql.CQLParser; -import org.z3950.zing.cql.CQLRelation; import org.z3950.zing.cql.CQLTermNode; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2011-05-04 18:02:29
|
Revision: 827 http://treebase.svn.sourceforge.net/treebase/?rev=827&view=rev Author: hshyket Date: 2011-05-04 18:02:23 +0000 (Wed, 04 May 2011) Log Message: ----------- Updating matrix search so that no matrices appear whose studies are not published. Doing the same thing for tree search with the addition of not displaying any orphaned trees. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2011-05-03 19:21:24 UTC (rev 826) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2011-05-04 18:02:23 UTC (rev 827) @@ -223,12 +223,12 @@ } - // XXX need to filter out orphaned matrices + // XXX need to filter out orphaned matrices or matrices whose studies are unpublished Collection<Matrix> orphanedMatrices = new HashSet<Matrix>(); for ( Matrix m : matches ) { - if ( m.getStudy() == null ) { + if ( m.getStudy() == null || (m.getStudy().isPublished() == false) ) { orphanedMatrices.add(m); - } + } } matches.removeAll(orphanedMatrices); return matches; Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2011-05-03 19:21:24 UTC (rev 826) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2011-05-04 18:02:23 UTC (rev 827) @@ -14,6 +14,7 @@ import org.apache.log4j.Logger; import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.RangeExpression.MalformedRangeExpression; +import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.domain.search.TreeSearchResults; @@ -101,6 +102,16 @@ } else { throw new Error("Unknown search button name '" + buttonName + "'"); } + + // XXX need to filter out orphaned matrices or matrices whose studies are unpublished + Collection<PhyloTree> orphanedTrees = new HashSet<PhyloTree>(); + for ( PhyloTree t : matches ) { + if (t.getStudy() == null || (t.getStudy().isPublished() == false)){ + orphanedTrees.add(t); + } + } + matches.removeAll(orphanedTrees); + SearchResults<PhyloTree> newRes = intersectSearchResults(oldRes, new TreeSearchResults(matches), new RequestMessageSetter(request), "No matching trees found"); saveSearchResults(request, newRes); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2011-05-27 20:02:44
|
Revision: 893 http://treebase.svn.sourceforge.net/treebase/?rev=893&view=rev Author: hshyket Date: 2011-05-27 20:02:37 +0000 (Fri, 27 May 2011) Log Message: ----------- Checks to make sure that trees exist in the analysis when displaying message before deleting. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeBlockController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeBlockController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeBlockController.java 2011-05-27 14:55:09 UTC (rev 892) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeBlockController.java 2011-05-27 20:02:37 UTC (rev 893) @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -14,6 +15,10 @@ import org.springframework.web.servlet.view.RedirectView; import org.cipres.treebase.domain.admin.UserRole.TBPermission; +import org.cipres.treebase.domain.study.Analysis; +import org.cipres.treebase.domain.study.AnalysisStep; +import org.cipres.treebase.domain.study.AnalyzedData; +import org.cipres.treebase.domain.study.AnalyzedTree; import org.cipres.treebase.domain.study.SubmissionHome; import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.domain.tree.PhyloTree; @@ -140,9 +145,9 @@ TreeBlock pTreeBlock = getPhyloTreeHome().findTreeBlockById(treeBlockID); Collection<PhyloTree> pTreeCollection = pTreeBlock.getTreeList(); - + for (PhyloTree pTree : pTreeCollection) { - if (pTree.getStudy() != null) { // It means this tree is tied to analysis step + /*if (pTree.getStudy() != null) { // It means this tree is tied to analysis step setTestVariable(true); referenceMap .put( @@ -150,6 +155,29 @@ "Either this TreeBlock or atleast one of the Tree in this Block is tied to an Analysis Step."); break; // Even if one tree of the block is ties to Analysis step, we can exit the // for loop. + }*/ + + for (Analysis analysis : pTree.getStudy().getAnalyses()) { + + List<AnalysisStep> analysisStepList = analysis.getAnalysisStepsReadOnly(); + + for (AnalysisStep analysisStep : analysisStepList) { + + List<AnalyzedData> analyzedDataSet = analysisStep.getDataSetReadOnly(); + + for (AnalyzedData analyzedData : analyzedDataSet) { + + if (analyzedData instanceof AnalyzedTree) { + + if ( pTreeCollection.contains(((AnalyzedTree) analyzedData).getTree())) { + + referenceMap.put("generalmessage", "Either this TreeBlock or at least one of the Tree in this Block is tied to an Analysis Step."); + break; // Even if one tree of the block is ties to Analysis step, we can exit the + } + } + } + + } } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeController.java 2011-05-27 14:55:09 UTC (rev 892) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/DeleteATreeController.java 2011-05-27 20:02:37 UTC (rev 893) @@ -4,6 +4,7 @@ package org.cipres.treebase.web.controllers; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -14,6 +15,10 @@ import org.springframework.web.servlet.ModelAndView; import org.cipres.treebase.domain.admin.UserRole.TBPermission; +import org.cipres.treebase.domain.study.Analysis; +import org.cipres.treebase.domain.study.AnalysisStep; +import org.cipres.treebase.domain.study.AnalyzedData; +import org.cipres.treebase.domain.study.AnalyzedTree; import org.cipres.treebase.domain.study.SubmissionHome; import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.domain.tree.PhyloTree; @@ -114,8 +119,31 @@ Long treeID = Long.parseLong(request.getParameter("treeid")); PhyloTree pTree = getPhyloTreeService().findByID(treeID); - if (pTree.getStudy() != null) { // It means this tree is tied to analysis step + /*if (pTree.getStudy() != null) { // It means this tree is tied to analysis step referenceMap.put("generalmessage", "This PhyloTree is tied to an Analysis Step."); + }*/ + + for (Analysis analysis : pTree.getStudy().getAnalyses()) { + + List<AnalysisStep> analysisStepList = analysis.getAnalysisStepsReadOnly(); + + for (AnalysisStep analysisStep : analysisStepList) { + + List<AnalyzedData> analyzedDataSet = analysisStep.getDataSetReadOnly(); + + for (AnalyzedData analyzedData : analyzedDataSet) { + + if (analyzedData instanceof AnalyzedTree) { + + if (pTree.getId() == ((AnalyzedTree) analyzedData).getTree().getId()) { + + referenceMap.put("generalmessage", "This PhyloTree is tied to an Analysis Step."); + } + } + } + + } + } referenceMap.put("deleteid", "Tree ID : " + treeID); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2012-01-06 21:20:19
|
Revision: 1009 http://treebase.svn.sourceforge.net/treebase/?rev=1009&view=rev Author: hshyket Date: 2012-01-06 21:20:13 +0000 (Fri, 06 Jan 2012) Log Message: ----------- Fixing X-Access-Code restriction Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.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 2012-01-06 16:46:50 UTC (rev 1008) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSController.java 2012-01-06 21:20:13 UTC (rev 1009) @@ -65,6 +65,7 @@ private static String searchBase = "/treebase-web/search/"; private boolean redirectDownload = true; + private Study TBStudy = null; /** * Child classes return the display page for the focal type @@ -116,8 +117,15 @@ // output format is something else, re-direct to download services else { url = createDownloadUrl(tbID.getId(),serializationFormat,req); - if (!redirectDownload && !ControllerUtil.isReviewerAccessGranted(req, tbID)) { - url = "/treebase-web/accessviolation.html"; + if (!redirectDownload ) { + if (TBStudy != null) { + if (!ControllerUtil.isReviewerAccessGranted(req, TBStudy.getTreebaseIDString())) { + url = "/treebase-web/accessviolation.html"; + } + } + else { + url = "/treebase-web/accessviolation.html"; + } } } } @@ -286,8 +294,9 @@ } } - public void checkAccess(boolean isPublished) { - redirectDownload = isPublished; + public void setStudy(Study study) { + TBStudy = study; + redirectDownload = study.isPublished(); } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2012-01-06 16:46:50 UTC (rev 1008) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSMatrixController.java 2012-01-06 21:20:13 UTC (rev 1009) @@ -45,7 +45,7 @@ throw new ObjectNotFoundException("Can't find study for matrix "+objectId); } - checkAccess(matrix.getStudy().isPublished()); + setStudy(matrix.getStudy()); Map<String,String> params = new HashMap<String,String>(); params.put("id", ""+study.getId()); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2012-01-06 16:46:50 UTC (rev 1008) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSStudyController.java 2012-01-06 21:20:13 UTC (rev 1009) @@ -40,7 +40,7 @@ throw new ObjectNotFoundException("Can't find study " + objectId); } - checkAccess(study.isPublished()); + setStudy(study); Map<String,String> params = new HashMap<String,String>(); params.put("id", ""+objectId); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2012-01-06 16:46:50 UTC (rev 1008) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PhyloWSTreeController.java 2012-01-06 21:20:13 UTC (rev 1009) @@ -44,10 +44,7 @@ if ( study == null ) { throw new ObjectNotFoundException("Can't find study for tree "+objectId); } - - //not checking access due to need for Phloywidget to access tree when in review - //checkAccess(phyloTree.getStudy().isPublished()); - + Map<String,String> params = new HashMap<String,String>(); params.put("id",""+study.getId()); params.put("treeid", ""+objectId); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-23 15:25:12
|
Revision: 1087 http://treebase.svn.sourceforge.net/treebase/?rev=1087&view=rev Author: rvos Date: 2012-02-23 15:25:03 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Removing code dealing with old-style search forms Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-22 19:24:32 UTC (rev 1086) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 15:25:03 UTC (rev 1087) @@ -62,60 +62,9 @@ HttpServletResponse response, Object command, BindException errors) throws Exception { - LOGGER.info("in matrixSearchController.onSubmit"); - clearMessages(request); - String formName = request.getParameter("formName"); - String query = request.getParameter("query"); - - LOGGER.info("formName is '" + formName + "'"); - - if ( ! TreebaseUtil.isEmpty(query) ) { - return this.handleQueryRequest(request, response, errors, query); - } - - if (formName.equals("matrixSimple")) { - String buttonName = request.getParameter("searchButton"); - Set<Matrix> matches = new HashSet<Matrix>(); - String searchTerm = convertStars(request.getParameter("searchTerm")); - SearchMessageSetter mSetter = new RequestMessageSetter(request); - MatrixSearchResults oldRes; - { - SearchResults<?> sr = searchResults(request); - if (sr != null) { - oldRes = (MatrixSearchResults) sr.convertToMatrices(); - } else { - oldRes = new MatrixSearchResults (); // TODO: Convert existing search results to new type - } - } - if (buttonName.equals("matrixID")) { - matches.addAll(doSearch(request, response, SearchType.byID, errors,searchTerm)); - } else if (buttonName.equals("matrixTitle")) { - matches.addAll(doSearch(request, response, SearchType.byTitle, errors,searchTerm)); - } else if (buttonName.equals("matrixType")) { - matches.addAll(doSearch(request, response, SearchType.byType, errors,searchTerm)); - } else if (buttonName.equals("matrixNTAX")) { - matches.addAll(doSearch(request, response, SearchType.byNTAX, errors,searchTerm)); - } else if (buttonName.equals("matrixNCHAR")) { - matches.addAll(doSearch(request, response, SearchType.byNCHAR, errors,searchTerm)); - } else { - throw new Error("Unknown search button name '" + buttonName + "'"); - } - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - SearchResults<Matrix> newRes = intersectSearchResults(oldRes, - new MatrixSearchResults(matches), mSetter, "No matching matrices found"); - saveSearchResults(request, newRes); - return new ModelAndView("search/matrixSearch", Constants.RESULT_SET, newRes); - } - else { - return this.searchResultsAsRDF(new MatrixSearchResults(matches), request, null, "matrix", "matrix"); - } - } - - else { - return super.onSubmit(request, response, command, errors); - } + return handleQueryRequest(request, response, errors, request.getParameter("query")); } protected Set<Matrix> doCQLQuery( @@ -161,7 +110,7 @@ } else if ( index.startsWith("tb.ntax") ) { results.addAll(doSearch(request, response, SearchType.byNTAX, errors, term.getTerm())); } else if ( index.startsWith("tb.nchar") ) { - results.addAll(doSearch(request, response, SearchType.byNTAX, errors, term.getTerm())); + results.addAll(doSearch(request, response, SearchType.byNCHAR, errors, term.getTerm())); } else { // issue warnings addMessage(request, "Unsupported index: " + index); @@ -246,7 +195,6 @@ @Override protected ModelAndView handleQueryRequest(HttpServletRequest request,HttpServletResponse response,BindException errors, String query) throws CQLParseException, IOException, InstantiationException { - //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-22 19:24:32 UTC (rev 1086) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-23 15:25:03 UTC (rev 1087) @@ -101,69 +101,9 @@ HttpServletResponse response, Object command, BindException errors) throws Exception { - LOGGER.info("in StudySearchController.onSubmit"); - clearMessages(request); - String formName = request.getParameter("formName"); - String query = request.getParameter("query"); - - LOGGER.info("formName is '" + formName + "'"); - - if ( ! TreebaseUtil.isEmpty(query) && ! query.equals("")) { - LOGGER.info("query is '" + query + "'"); - return this.handleQueryRequest(request, response, errors, query); - } - - if (formName.equals("searchKeyword")) { - SearchType searchType; - String buttonName = request.getParameter("searchButton"); - String searchTerm = convertStars(request.getParameter("searchTerm")); - StudySearchResults oldRes; - { - SearchResults<?> sr = searchResults(request); - if (sr != null) { - oldRes = (StudySearchResults) sr.convertToStudies(); - } else { - oldRes = new StudySearchResults (); // TODO: Convert existing search results to new type - } - } - if (buttonName.equals("authorKeyword")) { - searchType = SearchType.byAuthorName; - } else if (buttonName.equals("studyID")) { - searchType = SearchType.byID; - } else if (buttonName.equals("legacyStudyID")) { - searchType = SearchType.byLegacyID; - } else if (buttonName.equals("titleKeyword")) { - searchType = SearchType.byTitle; - } else if (buttonName.equals("textKeyword")) { - searchType = SearchType.byKeyword; - } else if (buttonName.equals("citationKeyword")) { - searchType = SearchType.inCitation; - } else if (buttonName.equals("abstractKeyword")) { - searchType = SearchType.inAbstract; - } else if (buttonName.equals("doiKeyword")) { - searchType = SearchType.byDOI; - } - else { - throw new Error("Unknown search button name '" + buttonName + "'"); - } - // XXX we now never do an exact match with terms provided through the web app. We can change - // this, e.g. by adding a check box whose value is the boolean argument of doSearch() - Collection<Study> matches = doSearch(request, response, searchType, errors,searchTerm,false,null); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - SearchResults<Study> newRes = intersectSearchResults(oldRes, new StudySearchResults(matches), - new RequestMessageSetter(request), "No matching studies found"); - saveSearchResults(request, newRes); - return new ModelAndView("search/studySearch", Constants.RESULT_SET, newRes); - } - else { - return this.searchResultsAsRDF(new StudySearchResults(matches), request, null,"study","study"); - } - } - else { - return super.onSubmit(request, response, command, errors); - } + return handleQueryRequest(request, response, errors, request.getParameter("query")); } protected Set<Study> doCQLQuery( Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-22 19:24:32 UTC (rev 1086) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-23 15:25:03 UTC (rev 1087) @@ -51,48 +51,7 @@ HttpServletResponse response, Object searchCommand, BindException errors) throws Exception { clearMessages(request); - String formName = request.getParameter("formName"); - String query = request.getParameter("query"); - if ( ! TreebaseUtil.isEmpty(query) ) { - return this.handleQueryRequest(request, response, errors, query); - } - if (formName.equals("searchByTaxonLabel")) { - SearchCommand newSearchCommand = (SearchCommand)searchCommand; - String searchOn = request.getParameter("searchOn"); - String searchTerm = convertStars(request.getParameter("searchTerm")); - String[] searchTerms = searchTerm.split("\\r\\n"); - Collection<Taxon> taxa = new HashSet<Taxon>(); - for ( int i = 0; i < searchTerms.length; i++ ) { - if ( searchOn.equals("TextSearch") ) { - taxa.addAll(doTaxonSearch(request, newSearchCommand, searchTerms[i], SearchIndex.LABEL, null)); - } - else if ( searchOn.equals("Identifiers") ) { - String objectIdentifier = request.getParameter("objectIdentifier"); - if ( objectIdentifier.equals("TreeBASE") ) { - taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.TREEBASE)); - } - else if ( objectIdentifier.equals("NCBI") ) { - taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.NCBI)); - } - else if ( objectIdentifier.equals("uBio") ) { - taxa.addAll(doTaxonSearch(request,newSearchCommand,searchTerms[i],SearchIndex.ID,NamingAuthority.UBIO)); - } - } - } - TaxonSearchResults tsr = new TaxonSearchResults(taxa); - saveSearchResults(request, tsr); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - return samePage(request); - } - else { - return this.searchResultsAsRDF(tsr, request, null,"taxon","taxon"); - } - - } else if (formName.equals("taxonResultsAction")) { - return modifySearchResults(request, response, errors); - } else { - return super.onSubmit(request, response, (SearchCommand) searchCommand, errors); - } + return handleQueryRequest(request, response, errors, request.getParameter("query")); } protected Set<Taxon> doCQLQuery(CQLNode node, Set<Taxon> results, HttpServletRequest request) { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-22 19:24:32 UTC (rev 1086) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-23 15:25:03 UTC (rev 1087) @@ -65,65 +65,7 @@ LOGGER.info("in TreeSearchController.onSubmit"); clearMessages(request); - String formName = request.getParameter("formName"); - String query = request.getParameter("query"); - - LOGGER.info("formName is '" + formName + "'"); - - if ( ! TreebaseUtil.isEmpty(query) ) { - return this.handleQueryRequest(request, response, errors, query); - } - - if (formName.equals("treeSimple")) { - String buttonName = request.getParameter("searchButton"); - String searchTerm = convertStars(request.getParameter("searchTerm")); - Collection<PhyloTree> matches = null; - TreeSearchResults oldRes; - { - SearchResults<?> sr = searchResults(request); - if (sr != null) { - oldRes = (TreeSearchResults) sr.convertToTrees(); - } else { - oldRes = new TreeSearchResults (); // TODO: Convert existing search results to new type - } - } - if (buttonName.equals("treeID")) { - matches = doSearch(request, response, SearchType.byID, errors, searchTerm); - } else if (buttonName.equals("treeTitle")) { - matches = doSearch(request, response, SearchType.byTitle, errors, searchTerm); - } else if (buttonName.equals("treeType")) { - matches = doSearch(request, response, SearchType.byType, errors, searchTerm); - } else if (buttonName.equals("treeKind")) { - matches = doSearch(request, response, SearchType.byKind, errors, searchTerm); - } else if (buttonName.equals("treeQuality")) { - matches = doSearch(request, response, SearchType.byQuality, errors, searchTerm); - } else if (buttonName.equals("treeNTAX")) { - matches = doSearch(request, response, SearchType.byNTAX, errors, searchTerm); - } else { - throw new Error("Unknown search button name '" + buttonName + "'"); - } - - // XXX need to filter out orphaned matrices or matrices whose studies are unpublished - Collection<PhyloTree> orphanedTrees = new HashSet<PhyloTree>(); - for ( PhyloTree t : matches ) { - if (t.getStudy() == null || (t.getStudy().isPublished() == false)){ - orphanedTrees.add(t); - } - } - matches.removeAll(orphanedTrees); - - SearchResults<PhyloTree> newRes = intersectSearchResults(oldRes, new TreeSearchResults(matches), - new RequestMessageSetter(request), "No matching trees found"); - saveSearchResults(request, newRes); - if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) { - return new ModelAndView("search/treeSearch", Constants.RESULT_SET, newRes); - } - else { - return this.searchResultsAsRDF(newRes, request, null,"tree","tree"); - } - } else { - return super.onSubmit(request, response, command, errors); - } + return handleQueryRequest(request, response, errors, request.getParameter("query")); } protected Set<PhyloTree> doCQLQuery( @@ -248,7 +190,6 @@ protected ModelAndView handleQueryRequest(HttpServletRequest request, HttpServletResponse response, BindException errors, String query) throws CQLParseException, IOException, InstantiationException { - //String query = request.getParameter("query"); CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-23 18:59:17
|
Revision: 1089 http://treebase.svn.sourceforge.net/treebase/?rev=1089&view=rev Author: rvos Date: 2012-02-23 18:59:11 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Correcting a bug I introduced: onSubmit() is also visited when buttons that modify the results set are pressed (i.e. there is no CQL query to run). In such cases handling the request should be delegated to super.onSubmit(). Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 15:43:14 UTC (rev 1088) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) @@ -21,8 +21,6 @@ import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.web.Constants; -import org.cipres.treebase.web.util.RequestMessageSetter; -import org.cipres.treebase.web.util.SearchMessageSetter; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.z3950.zing.cql.CQLAndNode; @@ -57,14 +55,16 @@ byTB1ID } - protected ModelAndView onSubmit( - HttpServletRequest request, - HttpServletResponse response, - Object command, - BindException errors) throws Exception { + protected ModelAndView onSubmit(HttpServletRequest req,HttpServletResponse res,Object comm,BindException err) throws Exception { LOGGER.info("in matrixSearchController.onSubmit"); - clearMessages(request); - return handleQueryRequest(request, response, errors, request.getParameter("query")); + clearMessages(req); + String query = req.getParameter("query"); + if ( null != query ) { + return handleQueryRequest(req, res, err, query); + } + else { + return super.onSubmit(req, res, comm, err); + } } protected Set<Matrix> doCQLQuery( Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-23 15:43:14 UTC (rev 1088) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-23 18:59:11 UTC (rev 1089) @@ -26,7 +26,6 @@ import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.model.Identify; -import org.cipres.treebase.web.util.RequestMessageSetter; import org.cipres.treebase.web.util.IdentifyUtil; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; @@ -40,8 +39,6 @@ import org.z3950.zing.cql.CQLRelation; import org.z3950.zing.cql.CQLTermNode; -import java.text.DateFormat; - /** * StudySearchController.java * @@ -96,14 +93,16 @@ byDOI } - protected ModelAndView onSubmit( - HttpServletRequest request, - HttpServletResponse response, - Object command, - BindException errors) throws Exception { + protected ModelAndView onSubmit(HttpServletRequest req,HttpServletResponse res,Object comm,BindException err) throws Exception { LOGGER.info("in StudySearchController.onSubmit"); - clearMessages(request); - return handleQueryRequest(request, response, errors, request.getParameter("query")); + clearMessages(req); + String query = req.getParameter("query"); + if ( null != query ) { + return handleQueryRequest(req, res, err, query); + } + else { + return super.onSubmit(req, res, comm, err); + } } protected Set<Study> doCQLQuery( Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-23 15:43:14 UTC (rev 1088) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) @@ -47,11 +47,15 @@ private enum NamingAuthority { TREEBASE, UBIO, NCBI }; @Override - protected ModelAndView onSubmit(HttpServletRequest request, - HttpServletResponse response, Object searchCommand, BindException errors) - throws Exception { - clearMessages(request); - return handleQueryRequest(request, response, errors, request.getParameter("query")); + protected ModelAndView onSubmit(HttpServletRequest req, HttpServletResponse res, Object comm, BindException err) throws Exception { + clearMessages(req); + String query = req.getParameter("query"); + if ( null != query ) { + return handleQueryRequest(req, res, err, query); + } + else { + return super.onSubmit(req, res, comm, err); + } } protected Set<Taxon> doCQLQuery(CQLNode node, Set<Taxon> results, HttpServletRequest request) { @@ -125,31 +129,6 @@ logger.debug(node); return results; } - - private ModelAndView modifySearchResults(HttpServletRequest request, - HttpServletResponse response, BindException errors) throws InstantiationException { - TaxonSearchResults results = searchResults(request).convertToTaxa(); - - String buttonName = request.getParameter("taxonResultsaction"); - if (buttonName.equals("addCheckedToResults")) { -// Map<String,String> parameterMap = request.getParameterMap(); - Collection<Taxon> newTaxa = new HashSet<Taxon> (); - for (String taxonIdString : request.getParameterValues("selection")) { - Taxon tx; - try { - tx = getTaxonLabelService().findTaxonByIDString(taxonIdString); - } catch (MalformedTreebaseIDString e) { - // This can only occur if the ID numbers in our web form are - // malformed, so it represents a programming error. 20090312 MJD - throw new Error(e); - } - if (tx != null) newTaxa.add(tx); - } - results.union(newTaxa); - saveSearchResults(request, results); - } - return samePage(request); - } protected Collection<Taxon> doTaxonSearch(HttpServletRequest request, SearchCommand searchCommand, String searchTerm, SearchIndex searchIndex, NamingAuthority namingAuthority) throws Exception { @@ -182,9 +161,6 @@ getTaxonLabelService().resurrectAll(taxa); LOGGER.debug("Found " + taxa.size() + " taxa"); return taxa; -// TaxonSearchResults tsr = new TaxonSearchResults(taxa); -// saveSearchResults(request, tsr); -// return samePage(request); } /** Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-23 15:43:14 UTC (rev 1088) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) @@ -14,14 +14,12 @@ import org.apache.log4j.Logger; import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.RangeExpression.MalformedRangeExpression; -import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.search.SearchResults; import org.cipres.treebase.domain.search.SearchResultsType; import org.cipres.treebase.domain.search.TreeSearchResults; import org.cipres.treebase.domain.tree.PhyloTree; import org.cipres.treebase.domain.tree.PhyloTreeService; import org.cipres.treebase.web.Constants; -import org.cipres.treebase.web.util.RequestMessageSetter; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.z3950.zing.cql.CQLAndNode; @@ -56,16 +54,16 @@ byNTAX } - protected ModelAndView onSubmit( - HttpServletRequest request, - HttpServletResponse response, - Object command, - BindException errors) throws Exception { - + protected ModelAndView onSubmit(HttpServletRequest req,HttpServletResponse res,Object comm,BindException err) throws Exception { LOGGER.info("in TreeSearchController.onSubmit"); - - clearMessages(request); - return handleQueryRequest(request, response, errors, request.getParameter("query")); + clearMessages(req); + String query = req.getParameter("query"); + if ( null != query ) { + return handleQueryRequest(req, res, err, query); + } + else { + return super.onSubmit(req, res, comm, err); + } } protected Set<PhyloTree> doCQLQuery( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-23 19:07:36
|
Revision: 1090 http://treebase.svn.sourceforge.net/treebase/?rev=1090&view=rev Author: rvos Date: 2012-02-23 19:07:30 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Actually, we should probably check if query is an empty string (but not null). Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 19:07:30 UTC (rev 1090) @@ -59,7 +59,7 @@ LOGGER.info("in matrixSearchController.onSubmit"); clearMessages(req); String query = req.getParameter("query"); - if ( null != query ) { + if ( ! TreebaseUtil.isEmpty(query) ) { return handleQueryRequest(req, res, err, query); } else { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-23 18:59:11 UTC (rev 1089) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudySearchController.java 2012-02-23 19:07:30 UTC (rev 1090) @@ -97,7 +97,7 @@ LOGGER.info("in StudySearchController.onSubmit"); clearMessages(req); String query = req.getParameter("query"); - if ( null != query ) { + if ( ! TreebaseUtil.isEmpty(query) ) { return handleQueryRequest(req, res, err, query); } else { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TaxonSearchController.java 2012-02-23 19:07:30 UTC (rev 1090) @@ -50,7 +50,7 @@ protected ModelAndView onSubmit(HttpServletRequest req, HttpServletResponse res, Object comm, BindException err) throws Exception { clearMessages(req); String query = req.getParameter("query"); - if ( null != query ) { + if ( ! TreebaseUtil.isEmpty(query) ) { return handleQueryRequest(req, res, err, query); } else { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-23 18:59:11 UTC (rev 1089) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/TreeSearchController.java 2012-02-23 19:07:30 UTC (rev 1090) @@ -58,7 +58,7 @@ LOGGER.info("in TreeSearchController.onSubmit"); clearMessages(req); String query = req.getParameter("query"); - if ( null != query ) { + if ( ! TreebaseUtil.isEmpty(query) ) { return handleQueryRequest(req, res, err, query); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |