From: <yo...@us...> - 2010-07-14 20:45:18
|
Revision: 733 http://treebase.svn.sourceforge.net/treebase/?rev=733&view=rev Author: youjun Date: 2010-07-14 20:45:11 +0000 (Wed, 14 Jul 2010) Log Message: ----------- handshaking controller and util 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/StudyFormController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/CitationParser.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/DryadUtil.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 2010-07-14 02:16:55 UTC (rev 732) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ProcessUserController.java 2010-07-14 20:45:11 UTC (rev 733) @@ -21,11 +21,7 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - String importKey = null; - if(request.getParameter("importKey") != null){ - importKey = (String)request.getAttribute("importKey"); - request.getSession().setAttribute("importKey",importKey); - } + String importKey = (String)request.getSession().getAttribute("importKey"); if (importKey != null && importKey.length()>0) { Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudyFormController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudyFormController.java 2010-07-14 02:16:55 UTC (rev 732) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/StudyFormController.java 2010-07-14 20:45:11 UTC (rev 733) @@ -25,6 +25,7 @@ import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.web.Constants; import org.cipres.treebase.web.model.MyProgressionListener; +import org.cipres.treebase.web.util.CitationParser; import org.cipres.treebase.web.util.ControllerUtil; import org.cipres.treebase.web.util.DryadUtil; @@ -106,28 +107,7 @@ String importKey = (String)request.getSession().getAttribute("importKey"); request.getSession().removeAttribute("importKey"); - if (request.getParameter(ACTION_SUBMIT) != null) { - // Study must be submitted with citation together - // here we are just saving the data to the session - // request.getSession().setAttribute(Constants.STUDY_KEY, study); - - // BeanUtils.copyProperties(citationCommand.getCitationMap(citationType), - // citationCommand); - - // FIXME citation - // Citation c = new ArticleCitation(); - // c.setStudy(study); - // study.setCitation(c); - - // retrieve Study object from session to be submitted with citation - // Study study = (Study) request.getSession().getAttribute(Constants.STUDY_KEY); - // citationCommand.getCitationMap(citationType).setStudy(study); - Submission submission = mSubmissionService.createSubmission(user, study); - - // save Study object to session and remove - ControllerUtil.saveStudy(request, submission.getStudy()); - - } else if(importKey != null && importKey.length()>0){ + if(importKey != null && importKey.length()>0){ String uploadpath = getServletContext() .getRealPath(TreebaseUtil.FILESEP + "DryadFileUpload") + TreebaseUtil.FILESEP + importKey; @@ -149,13 +129,14 @@ try{ Submission submission = mSubmissionService.createSubmission(user, new Study()); - Citation citation = DryadUtil.createCitation(dataPath); + CitationParser cparser= new CitationParser(dataPath); + Citation citation = cparser.getCitation(); submission.getStudy().setCitation(citation); citation.setStudy(submission.getStudy()); Collection<File> files = DryadUtil.getDataFiles(dataPath); MyProgressionListener listener = new MyProgressionListener(); - getSubmissionService().addNexusFilesJDBC(submission, files, listener); + //getSubmissionService().addNexusFilesJDBC(submission, files, listener); // save Study object to session ControllerUtil.saveStudy(request, submission.getStudy()); importStatus = "OK"; @@ -167,7 +148,32 @@ //request.getSession().removeAttribute("importKey"); return new ModelAndView(new RedirectView("submissionList.html")); - }else if (request.getParameter(ACTION_UPDATE) != null) { + } + + + + if (request.getParameter(ACTION_SUBMIT) != null) { + // Study must be submitted with citation together + // here we are just saving the data to the session + // request.getSession().setAttribute(Constants.STUDY_KEY, study); + + // BeanUtils.copyProperties(citationCommand.getCitationMap(citationType), + // citationCommand); + + // FIXME citation + // Citation c = new ArticleCitation(); + // c.setStudy(study); + // study.setCitation(c); + + // retrieve Study object from session to be submitted with citation + // Study study = (Study) request.getSession().getAttribute(Constants.STUDY_KEY); + // citationCommand.getCitationMap(citationType).setStudy(study); + Submission submission = mSubmissionService.createSubmission(user, study); + + // save Study object to session and remove + ControllerUtil.saveStudy(request, submission.getStudy()); + + } else if (request.getParameter(ACTION_UPDATE) != null) { mStudyService.update(study); } else if (request.getParameter(ACTION_DELETE) != null) { @@ -208,6 +214,10 @@ request.getSession().removeAttribute(Constants.STUDY_MAP); return new Study(); } + + if(request.getSession().getAttribute("importKey") != null) + return new Study(); + // if we are updating a data that's already in the db (access from RHS menu) study = ControllerUtil.findStudy(request, mStudyService); return study; Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/CitationParser.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/CitationParser.java 2010-07-14 02:16:55 UTC (rev 732) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/CitationParser.java 2010-07-14 20:45:11 UTC (rev 733) @@ -3,6 +3,7 @@ import java.io.File; import java.util.List; +import org.cipres.treebase.domain.admin.Person; import org.cipres.treebase.domain.study.ArticleCitation; import org.cipres.treebase.domain.study.Citation; import org.dom4j.Document; @@ -14,21 +15,18 @@ import org.dom4j.io.SAXReader; public class CitationParser { - + private ArticleCitation citation; private static final Namespace xs = new Namespace("xs","http://www.w3.org/2001/XMLSchema"); private static final Namespace dwc= new Namespace("dwc", "http://rs.tdwg.org/dwc/terms/"); private static final Namespace dcterms= new Namespace("dcterms", "http://purl.org/dc/terms/"); private static final Namespace prism= new Namespace("prism", "http://prismstandard.org/namespaces/basic/2.0/"); - private ArticleCitation citation; private Element pubRoot; private Element pkgRoot; public CitationParser(File path){ - - citation = new ArticleCitation(); - + File pubFile = new File(path, "dryadpub.xml"); SAXReader pubReader = new SAXReader(); Document pubDoc= null ; @@ -52,31 +50,69 @@ e.printStackTrace(); } + citation = new ArticleCitation(); loadData(); } private void loadData(){ - - citation.setAbstract(getNode(pubRoot,"description",dcterms).getText()); - citation.setDoi(getNode(pubRoot,"identifier",dcterms).getText());; + + Node description = getNode(pubRoot,"description",dcterms); + if(description!=null)citation.setAbstract(description.getText()); - citation.setTitle(getNode(pubRoot,"title",dcterms).getText()); - citation.setIssue(getNode(pubRoot,"issueIdentifier",prism).getText()); - citation.setJournal(getNode(pubRoot,"publicationName",prism).getText()); - citation.setVolume(getNode(pubRoot,"volume",prism).getText()); - citation.setPages(getNode(pubRoot,":pageRange",prism).getText()); + Node identifier = getNode(pubRoot,"identifier",dcterms); + if(identifier!=null)citation.setDoi(identifier.getText());; - //citation.setKeywords(getNode(pubRoot,"description",dcterms).getText()); - //citation.setAuthors(pAuthors); + Node title = getNode(pubRoot,"title",dcterms); + if(title!=null)citation.setTitle(title.getText()); - //citation.setPublishYear(getNode(pubRoot,"issued",dcterms).getText()); - //citation.setPublished(getNode(pubRoot,"description",dcterms).getText()); + Node issueIdentifier = getNode(pubRoot,"issueIdentifier",prism); + if(issueIdentifier!=null)citation.setIssue(issueIdentifier.getText()); + Node publicationName = getNode(pubRoot,"publicationName",prism); + if(publicationName!=null)citation.setJournal(publicationName.getText()); + + Node volume = getNode(pubRoot,"volume",prism); + if(volume!=null)citation.setVolume(volume.getText()); + + Node pageRange = getNode(pubRoot,"pageRange",prism); + if(pageRange!=null)citation.setPages(pageRange.getText()); + + List<Node> kl = getNodes(pkgRoot,"subject",dcterms); + String keywords=""; + for(int i = 0; i<kl.size(); i++) { + keywords+= kl.get(i).getText()+","; + } + citation.setKeywords(keywords.substring(0, keywords.length()-1)); + + List<Node> al = getNodes(pubRoot,"creator",dcterms); + for(int i = 0; i<al.size(); i++) { + String []names = al.get(i).getText().split(","); + if(names.length >1 ){ + Person p = new Person (); + p.setFirstName(names[1]); + p.setLastName(names[0]); + citation.addAuthor(p); + } + } + + try{ + int issue = Integer.parseInt(getNode(pubRoot,"issued",dcterms).getText()); + citation.setPublishYear(issue); + }catch(Exception e){ + + } + + + if(getNode(pubRoot,"pubStatus",null).getText()!=null){ + if("published".compareToIgnoreCase(getNode(pubRoot,"pubStatus",null).getText())==0) + citation.setPublished(true); + else citation.setPublished(false); + } } private Node getNode(Element root, String localName, Namespace namespace){ - + if(namespace==null)return root.element(new QName(localName)); return root.element(new QName(localName, namespace)); } @@ -85,8 +121,7 @@ return root.elements(new QName(localName, namespace)); } - - public Citation getCitation() { + public ArticleCitation getCitation() { return citation; } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/DryadUtil.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/DryadUtil.java 2010-07-14 02:16:55 UTC (rev 732) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/DryadUtil.java 2010-07-14 20:45:11 UTC (rev 733) @@ -1,7 +1,9 @@ package org.cipres.treebase.web.util; import java.io.File; +import java.io.FileFilter; import java.io.FilenameFilter; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -14,41 +16,26 @@ public class DryadUtil { - - - public static Citation createCitation(File path){ - Citation citation = new Citation(); - - File f = new File(path, "citation.xml"); - SAXReader reader = new SAXReader(); - Document doc= null ; - try { - doc = reader.read(f); - } catch (DocumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Element root = doc.getRootElement(); - Element node; - for (Iterator i = root.elementIterator("author"); i.hasNext();) { - node = (Element) i.next(); - Person p = new Person(); - //node.getName(); - citation.addAuthor(p); - } - citation.setTitle(root.element("title").getName()); - - - return citation; - } - public static Collection<File> getDataFiles(File path) { // TODO Auto-generated method stub - List<File> flist=Arrays.asList(path.listFiles(new FilenameFilter() { - public boolean accept(File file, String name) { - boolean ret = !(name.endsWith("xml")); - return ret; - }})); + File[] files = path.listFiles(new FileFilter() { + public boolean accept(File file) { + return file.isDirectory(); + }}); + + List<File> flist = new ArrayList<File>(); + + for(int i=0; i<files.length; i++){ + + File[] nexus = files[i].listFiles(new FilenameFilter() { + public boolean accept(File file, String name) { + boolean ret = !(name.endsWith("nexus")); + return ret; + }}); + + if (nexus!=null && nexus.length>0) flist.addAll(Arrays.asList(nexus)); + } + return flist; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |