From: <sp...@us...> - 2009-12-04 06:29:13
|
Revision: 5565 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=5565&view=rev Author: sppigot Date: 2009-12-04 06:29:01 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Change localfilesystem harvester to read files when processing rather than beforehand Fix result reporting - no results structure returned and client-result-tip.xsl wasn't looking for it Modified Paths: -------------- trunk/src/org/fao/geonet/kernel/harvest/harvester/localfilesystem/LocalFilesystemHarvester.java trunk/web/geonetwork/xsl/harvesting/filesystem/client-result-tip.xsl Modified: trunk/src/org/fao/geonet/kernel/harvest/harvester/localfilesystem/LocalFilesystemHarvester.java =================================================================== --- trunk/src/org/fao/geonet/kernel/harvest/harvester/localfilesystem/LocalFilesystemHarvester.java 2009-12-04 05:47:38 UTC (rev 5564) +++ trunk/src/org/fao/geonet/kernel/harvest/harvester/localfilesystem/LocalFilesystemHarvester.java 2009-12-04 06:29:01 UTC (rev 5565) @@ -123,17 +123,15 @@ } /** - * Reads contents of all files in directory and returns a list of JDOM elements. If files cannot be loaded as XML - * they are ignored. If recurse is true, processes recursively all subdirectories too. + * Returns a list of all file names in a directory - if recurse is true, + * processes all subdirectories too. * @param directory * @param recurse * @return - * @throws IOException - * @throws JDOMException */ - private List<Element> harvestFromDirectory(File directory, boolean recurse) throws IOException, JDOMException { + private List<String> harvestFromDirectory(File directory, boolean recurse) throws IOException { System.out.println("LocalFilesystem harvesting: directory " + directory.getAbsolutePath()); - List<Element> results = new ArrayList<Element>(); + List<String> results = new ArrayList<String>(); if(! directory.exists()) { throw new IOException("directory does not exist: "+ directory.getAbsolutePath()); } @@ -155,15 +153,8 @@ throw new IOException("cannot read file "+ file.getAbsolutePath()); } else { - try { - // get file content as Element - System.out.println("processing file: " + file.getName()); - Element xml = Xml.loadFile(file); - results.add(xml); - } - catch(Throwable x) { - System.out.println("error loading XML from file " + file.getName() + ", ignoring"); - } + System.out.println("adding file: " + file.getName()); + results.add(file.getAbsolutePath()); } } } @@ -179,9 +170,9 @@ * @param rm * @throws Exception */ - private void align(List<Element> results, ResourceManager rm) throws Exception { + private void align(List<String> results, ResourceManager rm) throws Exception { System.out.println("Start of alignment for : "+ params.name); - LocalFilesystemResult result = new LocalFilesystemResult(); + this.result = new LocalFilesystemResult(); Dbms dbms = (Dbms) rm.open(Geonet.Res.MAIN_DB); //---------------------------------------------------------------- //--- retrieve all local categories and groups @@ -192,8 +183,23 @@ List<String> idsForHarvestingResult = new ArrayList<String>(); //----------------------------------------------------------------------- //--- insert/update new metadata - for(Element xml : results) { + for(String xmlFile : results) { result.total++; + Element xml = null; + try { + System.out.println("reading file: " + xmlFile); + xml = Xml.loadFile(xmlFile); + } catch (JDOMException e) { // JDOM problem + System.out.println("Error loading XML from file " + xmlFile +", ignoring"); + e.printStackTrace(); + result.badFormat++; + continue; // skip this one + } catch (Exception e) { // some other error + System.out.println("Error retrieving XML from file " + xmlFile +", ignoring"); + e.printStackTrace(); + result.unretrievable++; + continue; // skip this one + } String schema = dataMan.autodetectSchema(xml); if(schema == null) { result.unknownSchema++; @@ -331,7 +337,7 @@ protected void doHarvest(Logger l, ResourceManager rm) throws Exception { System.out.println("LocalFilesystem doHarvest: top directory is " + params.directoryname + ", recurse is " + params.recurse); File directory = new File(params.directoryname); - List<Element> results = harvestFromDirectory(directory, params.recurse); + List<String> results = harvestFromDirectory(directory, params.recurse); System.out.println("LocalFilesystem doHarvest: found #" + results.size() + " results"); align(results, rm); } Modified: trunk/web/geonetwork/xsl/harvesting/filesystem/client-result-tip.xsl =================================================================== --- trunk/web/geonetwork/xsl/harvesting/filesystem/client-result-tip.xsl 2009-12-04 05:47:38 UTC (rev 5564) +++ trunk/web/geonetwork/xsl/harvesting/filesystem/client-result-tip.xsl 2009-12-04 06:29:01 UTC (rev 5565) @@ -12,25 +12,41 @@ <xsl:template match="/root/node"> <xsl:choose> - <xsl:when test="count(info/search) != 0"> + <xsl:when test="count(info/result) != 0"> <table> - <tr class="tipRow"> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/siteId"/> </td> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/total"/> </td> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/added"/> </td> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/updated"/> </td> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/unchanged"/> </td> - <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/skipped"/> </td> - </tr> - <xsl:for-each select="info/search"> + <xsl:for-each select="info/result"> <tr class="tipRow"> - <td class="tipCell"><b><xsl:value-of select="@siteId"/></b></td> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/total"/> </td> <td class="tipCell"><xsl:value-of select="total"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/added"/> </td> <td class="tipCell"><xsl:value-of select="added"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/updated"/> </td> <td class="tipCell"><xsl:value-of select="updated"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/unchanged"/> </td> <td class="tipCell"><xsl:value-of select="unchanged"/></td> - <td class="tipCell"><xsl:value-of select="skipped"/></td> </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/unknownSchema"/> </td> + <td class="tipCell"><xsl:value-of select="unknownSchema"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/removed"/> </td> + <td class="tipCell"><xsl:value-of select="removed"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/unretrievable"/> </td> + <td class="tipCell"><xsl:value-of select="unretrievable"/></td> + </tr> + <tr class="tipRow"> + <td class="tipHeader"> <xsl:value-of select="/root/strings/tipHeader/badFormat"/> </td> + <td class="tipCell"><xsl:value-of select="badFormat"/></td> + </tr> </xsl:for-each> </table> </xsl:when> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |