Project

General

Profile

Revision 5195

Added by daigle about 11 years ago

Pass the doc xml as a string to docImpl.write and writeRepication. This is so a reader can be create for the parsing and for the write to disk. Also created a db access class for xml query result deletion.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
2335 2335
            }
2336 2336
            
2337 2337
            logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - the xml document in metacat servlet (before parsing):\n" + doctext[0]);
2338
            StringReader xml = new StringReader(doctext[0]);
2338
            StringReader xmlReader = new StringReader(doctext[0]);
2339 2339
            boolean validate = false;
2340 2340
            DocumentImplWrapper documentWrapper = null;
2341 2341
            try {
2342 2342
                // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ...
2343 2343
                // >
2344 2344
                // in order to decide whether to use validation parser
2345
                validate = needDTDValidation(xml);
2345
                validate = needDTDValidation(xmlReader);
2346 2346
                if (validate) {
2347 2347
                    // set a dtd base validation parser
2348 2348
                    String rule = DocumentImpl.DTD;
2349 2349
                    documentWrapper = new DocumentImplWrapper(rule, validate);
2350 2350
                } else {
2351 2351
                    
2352
                    String namespace = XMLSchemaService.findDocumentNamespace(xml);
2352
                    String namespace = XMLSchemaService.findDocumentNamespace(xmlReader);
2353 2353
                    
2354 2354
                    if (namespace != null) {
2355 2355
                        if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
......
2405 2405
                            accNumber = null;
2406 2406
                        }
2407 2407

  
2408
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
2408
                        newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
2409 2409
                                doAction, accNumber, user, groups);
2410 2410
                                
2411 2411
                        EventLog.getInstance().log(request.getRemoteAddr(),
......
2413 2413
                    } catch (NullPointerException npe) {
2414 2414
                      // MCD this seems a bit dubious, since many things can throw npe
2415 2415
                      logMetacat.warn("MetaCatServlet.handleInsertOrUpdateAction - writing with null acnumber");
2416
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
2416
                        newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
2417 2417
                                doAction, null, user, groups);
2418 2418
                        EventLog.getInstance().log(request.getRemoteAddr(),
2419 2419
                                user, "", action[0]);
src/edu/ucsb/nceas/metacat/DocumentImpl.java
63 63
import edu.ucsb.nceas.metacat.replication.ReplicationService;
64 64
import edu.ucsb.nceas.metacat.service.XMLSchema;
65 65
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
66
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
66
import edu.ucsb.nceas.metacat.shared.AccessException;
67 67
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
68 68
import edu.ucsb.nceas.metacat.util.AuthUtil;
69 69
import edu.ucsb.nceas.metacat.util.DocumentUtil;
......
71 71
import edu.ucsb.nceas.metacat.util.SystemUtil;
72 72
import edu.ucsb.nceas.utilities.FileUtil;
73 73
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
74
import edu.ucsb.nceas.utilities.StringUtil;
75 74
import edu.ucsb.nceas.utilities.UtilException;
76 75

  
77 76
import org.apache.log4j.Logger;
......
166 165
    protected long rootnodeid;
167 166
    private ElementNode rootNode = null;
168 167
    private TreeSet<NodeRecord> nodeRecordList = null;
168
    
169
    private Vector<String> pathsForIndexing = null;
169 170
  
170 171
    private static Logger logMetacat = Logger.getLogger(DocumentImpl.class);
171 172
    private static Logger logReplication = Logger.getLogger("ReplicationLogging");
......
199 200
            //this.conn = conn;
200 201
            this.docid = DocumentUtil.getDocIdFromAccessionNumber(accNum);
201 202
            this.rev   = DocumentUtil.getRevisionFromAccessionNumber(accNum);
203
            
204
            pathsForIndexing = SystemUtil.getPathsForIndexing();
202 205

  
203 206
            // Look up the document information
204 207
            getDocumentInfo(docid, rev);
......
284 287
        this.doctype = docType;
285 288
        this.docid = docId;
286 289
        this.rev = (new Integer(newRevision)).intValue();
290
        
291
        pathsForIndexing = SystemUtil.getPathsForIndexing();
292
        
287 293
        //this.updatedVersion = newRevision;
288 294
        writeDocumentToDB(action, user, pub, catalogId, serverCode, createDate, updateDate);
289 295
    }
......
1404 1410
	 * @param accNumber
1405 1411
	 *            the document id which is used to name the output file
1406 1412
	 */
1407
    private static void writeToFileSystem(String xml, String accNumber) throws McdbException {
1413
    private static void writeToFileSystem(Reader xml, String accNumber) throws McdbException {
1408 1414

  
1409 1415
		// write the document to disk
1410 1416
//		FileWriter fileWriter = null;
......
1748 1754
                      currentName, docid, doctype, parentId));
1749 1755
                  }
1750 1756
                }
1751
                try {
1752
					if (SystemUtil.getPathsForIndexing().contains(currentName)
1753
							&& leafData.trim().length() != 0) {
1754
						logMetacat.debug("paths found for indexing: " + currentName);
1755
						pathsFoundForIndexing.put(currentName, new PathIndexEntry(
1756
								leafNodeId, currentName, docid, leafParentId, leafData,
1757
								leafDataNumerical));
1758
					}
1759
				} catch (MetacatUtilException ue) {
1760
					logMetacat.warn("Could not get index paths: " + ue.getMessage());
1757
				if (pathsForIndexing.contains(currentName)
1758
						&& leafData.trim().length() != 0) {
1759
					logMetacat.debug("paths found for indexing: " + currentName);
1760
					pathsFoundForIndexing.put(currentName, new PathIndexEntry(
1761
							leafNodeId, currentName, docid, leafParentId, leafData,
1762
							leafDataNumerical));
1761 1763
				}
1762
                
1763 1764
            }
1764 1765
            
1765 1766
            // process relative xpaths
......
1777 1778
                logMetacat.debug("B: " + path +"\n");
1778 1779
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
1779 1780
                    doctype, parentId));
1780
            	try {
1781
					if (SystemUtil.getPathsForIndexing().contains(path)
1782
							&& leafData.trim().length() != 0) {
1783
						logMetacat.debug("paths found for indexing: " + currentName);
1784
						pathsFoundForIndexing.put(path, new PathIndexEntry(leafNodeId,
1785
								path, docid, leafParentId, leafData, leafDataNumerical));
1786
					}
1787
				} catch (MetacatUtilException ue) {
1788
					logMetacat.warn("Could not get index paths: " + ue.getMessage());
1781
				if (pathsForIndexing.contains(path)
1782
						&& leafData.trim().length() != 0) {
1783
					logMetacat.debug("paths found for indexing: " + currentName);
1784
					pathsFoundForIndexing.put(path, new PathIndexEntry(leafNodeId,
1785
							path, docid, leafParentId, leafData, leafDataNumerical));
1789 1786
				}
1790 1787
            }
1791 1788
            // process absolute xpaths
......
1797 1794
                logMetacat.debug("C: " + fullPath +"\n");
1798 1795
                pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
1799 1796
                    docid, doctype, parentId));
1800
                try {
1801
					if (SystemUtil.getPathsForIndexing().contains(fullPath)
1802
							&& leafData.trim().length() != 0) {
1803
						logMetacat.debug("paths found for indexing: " + currentName);
1804
						pathsFoundForIndexing.put(fullPath, new PathIndexEntry(
1805
								leafNodeId, fullPath, docid, leafParentId, leafData,
1806
								leafDataNumerical));
1807
					}
1808
				} catch (MetacatUtilException ue) {
1809
					logMetacat.warn("Could not get index paths: " + ue.getMessage());
1797

  
1798
				if (pathsForIndexing.contains(fullPath)
1799
						&& leafData.trim().length() != 0) {
1800
					logMetacat.debug("paths found for indexing: " + currentName);
1801
					pathsFoundForIndexing.put(fullPath, new PathIndexEntry(
1802
							leafNodeId, fullPath, docid, leafParentId, leafData,
1803
							leafDataNumerical));
1810 1804
				}
1811 1805
            }
1812 1806
        } 
......
1843 1837
        double afterDeleteIndex = System.currentTimeMillis()/1000;
1844 1838
        logMetacat.debug("DocumentImpl.deleteNodeIndex - The delete index time is "+(afterDeleteIndex - start));
1845 1839
        // Delete all the entries in xml_queryresult
1846
        pstmt = conn.prepareStatement(
1847
                "DELETE FROM xml_queryresult WHERE docid = ?");
1848
        pstmt.setString(1, docid);
1849
        rows = pstmt.executeUpdate();
1850
        conn.increaseUsageCount(1);
1851
        pstmt.close();
1840
        
1841
//        pstmt = conn.prepareStatement(
1842
//                "DELETE FROM xml_queryresult WHERE docid = ?");
1843
//        pstmt.setString(1, docid);
1844
//        rows = pstmt.executeUpdate();
1845
//        conn.increaseUsageCount(1);
1846
//        pstmt.close();
1847
        try {
1848
            XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
1849
            xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
1850
        } catch (AccessException ae) {
1851
        	throw new SQLException("Problem deleting xml query result for docid " + 
1852
        			docid + " : " + ae.getMessage());
1853
        }
1852 1854
        logMetacat.debug("DocumentImpl.deleteNodeIndex - Deleted " + rows + " rows from xml_queryresult " +
1853 1855
                "for document " + docid);
1854 1856
        double afterDeleteQueryResult = System.currentTimeMillis()/1000;
......
2496 2498
     * false); }
2497 2499
     */
2498 2500

  
2499
    public static String write(DBConnection conn, Reader xml, String pub,
2501
    public static String write(DBConnection conn, String xmlString, String pub,
2500 2502
            Reader dtd, String action, String docid, String user,
2501 2503
            String[] groups, String ruleBase, boolean needValidation)
2502 2504
            throws Exception
......
2505 2507
        //in MetacatServlet class and now is wrapper into documentImple
2506 2508
        // get server location for this doc
2507 2509
        int serverLocation = getServerLocationNumber(docid);
2508
        return write(conn, xml, pub, dtd, action, docid, user, groups,
2510
        return write(conn, xmlString, pub, dtd, action, docid, user, groups,
2509 2511
                serverLocation, false, ruleBase, needValidation);
2510 2512
    }
2511 2513

  
......
2539 2541
     *            and version checked.
2540 2542
     */
2541 2543

  
2542
    public static String write(DBConnection conn, Reader xml, String pub,
2544
    public static String write(DBConnection conn, String xmlString, String pub,
2543 2545
            Reader dtd, String action, String accnum, String user,
2544 2546
            String[] groups, int serverCode, boolean override, String ruleBase,
2545 2547
            boolean needValidation) throws Exception
......
2547 2549
        // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
2548 2550
    	
2549 2551
    	// Get the xml as a string so we can write to file later
2550
    	String xmlString = StringUtil.readerToString(xml);
2552
    	StringReader xmlReader = new StringReader(xmlString);
2551 2553
    	
2552 2554
        logMetacat.debug("DocumentImpl.write - conn usage count before writting: "
2553 2555
                + conn.getUsageCount());
......
2598 2600
                     * updaterev, validate, user, groups, pub, serverCode, dtd);
2599 2601
                     */
2600 2602
                    logMetacat.debug("DocumentImpl.write - initializing parser");
2601
                    parser = initializeParser(conn, action, docid, xml, updaterev,
2603
                    parser = initializeParser(conn, action, docid, xmlReader, updaterev,
2602 2604
                            user, groups, pub, serverCode, dtd, ruleBase,
2603 2605
                            needValidation, false, null, null);// false means it is not a revision doc
2604 2606
                                   //null, null are createdate and updatedate
2605 2607
                                   //null will use current time as create date time
2606 2608
                    conn.setAutoCommit(false);
2607 2609
                    logMetacat.debug("DocumentImpl.write - parsing xml");
2608
                    parser.parse(new InputSource(xml));
2610
                    parser.parse(new InputSource(xmlReader));
2609 2611
                    conn.commit();
2610 2612
                    conn.setAutoCommit(true);
2611 2613
                    
2612 2614
                    //write the file to disk
2613 2615
                    logMetacat.debug("DocumentImpl.write - Writing xml to file system");
2614
                	writeToFileSystem(xmlString, accnum);
2616
                    StringReader xmlReaderForFile = new StringReader(xmlString);
2617
                	writeToFileSystem(xmlReaderForFile, accnum);
2615 2618

  
2616 2619
                    // write to xml_node complete. start the indexing thread.
2617 2620
                    addDocidToIndexingQueue(docid, rev);
......
2676 2679
        }
2677 2680
        XMLReader parser = null;
2678 2681
        try {
2679
            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
2682
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
2680 2683
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null);
2681 2684
                    // null and null are createtime and updatetime
2682 2685
                    // null will create current time
2683 2686
                    //false means it is not a revision doc
2684 2687

  
2685 2688
            conn.setAutoCommit(false);
2686
            logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xml);
2687
            parser.parse(new InputSource(xml));
2689
            logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
2690
            parser.parse(new InputSource(xmlReader));
2688 2691

  
2689 2692
            conn.commit();
2690 2693
            conn.setAutoCommit(true);
2691 2694
            
2692 2695
            //write the file to disk
2693
        	writeToFileSystem(xmlString, accnum);
2696
            StringReader xmlReaderForFile = new StringReader(xmlString);
2697
        	writeToFileSystem(xmlReaderForFile, accnum);
2694 2698

  
2695 2699
            addDocidToIndexingQueue(docid, rev);
2696 2700
        } catch (Exception e) {
......
2719 2723
        // result next time
2720 2724
        if (action.equals("UPDATE")) {
2721 2725
          try {
2722
              PreparedStatement pstmt = null;
2723
              pstmt = conn.prepareStatement(
2724
                      "DELETE FROM xml_queryresult WHERE docid = ?");
2725
              pstmt.setString(1, docid);
2726
              pstmt.execute();
2727
              pstmt.close();
2728
              conn.increaseUsageCount(1);
2726
//              PreparedStatement pstmt = null;
2727
//              pstmt = conn.prepareStatement(
2728
//                      "DELETE FROM xml_queryresult WHERE docid = ?");
2729
//              pstmt.setString(1, docid);
2730
//              pstmt.execute();
2731
//              pstmt.close();
2732
//              conn.increaseUsageCount(1);
2733
              try {
2734
                  XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
2735
                  xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
2736
              } catch (AccessException ae) {
2737
              	throw new SQLException("Problem deleting xml query result for docid " + 
2738
              			docid + " : " + ae.getMessage());
2739
              }
2729 2740
          } catch (Exception e){
2730 2741
              logMetacat.error("DocumentImpl.write - Error in deleting enteries from "
2731 2742
                                       + "xml_queryresult where docid is "
......
2790 2801
     *            the server which notify local server the force replication
2791 2802
     *            command
2792 2803
     */
2793
    public static String writeReplication(DBConnection conn, Reader xml,
2804
    public static String writeReplication(DBConnection conn, String xmlString,
2794 2805
            String pub, Reader dtd, String action, String accnum, String user,
2795 2806
            String[] groups, String homeServer, String notifyServer,
2796 2807
            String ruleBase, boolean needValidation, String tableName, 
2797 2808
            boolean timedReplication, String createDate, String updateDate) throws Exception
2798 2809
    {
2799 2810
    	// Get the xml as a string so we can write to file later
2800
    	String xmlString = StringUtil.readerToString(xml);
2811
    	StringReader xmlReader = new StringReader(xmlString);
2801 2812
    	
2802 2813
        long rootId;
2803 2814
        String docType = null;
......
2851 2862
            {
2852 2863
                isRevision = true;
2853 2864
            }
2854
            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
2865
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
2855 2866
                    pub, serverCode, dtd, ruleBase, needValidation, 
2856 2867
                    isRevision, createDate, updateDate);
2857 2868
         
2858 2869
            conn.setAutoCommit(false);
2859
            parser.parse(new InputSource(xml));
2870
            parser.parse(new InputSource(xmlReader));
2860 2871
            conn.commit();
2861 2872
            conn.setAutoCommit(true);
2862 2873
            
2863 2874
            // Write the file to disk
2864
        	writeToFileSystem(xmlString, accnum);
2875
            StringReader xmlReaderForFile = new StringReader(xmlString);
2876
        	writeToFileSystem(xmlReaderForFile, accnum);
2865 2877
            
2866 2878
            // write to xml_node complete. start the indexing thread.
2867 2879
            // this only for xml_documents
......
3173 3185
            double afterDeleteXmlAccess2 = System.currentTimeMillis()/1000;
3174 3186
            logMetacat.info("DocumentImpl.delete - The deleting xml_access base on docid time is "+(afterDeleteXmlAccess2 - afterDeleteXmlAccess1 ));
3175 3187
            // Delete enteries from xml_queryresult
3176
            pstmt = conn.prepareStatement(
3177
                    "DELETE FROM xml_queryresult WHERE docid = ?");
3178
            pstmt.setString(1, docid);
3179
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3180
            pstmt.execute();
3181
            pstmt.close();
3182
            conn.increaseUsageCount(1);
3188
//            pstmt = conn.prepareStatement(
3189
//                    "DELETE FROM xml_queryresult WHERE docid = ?");
3190
//            pstmt.setString(1, docid);
3191
//            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3192
//            pstmt.execute();
3193
//            pstmt.close();
3194
//            conn.increaseUsageCount(1);
3195
            try {
3196
                XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
3197
                xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
3198
            } catch (AccessException ae) {
3199
            	throw new SQLException("Problem deleting xml query result for docid " + 
3200
            			docid + " : " + ae.getMessage());
3201
            }
3183 3202
            double afterDeleteQueryResult = System.currentTimeMillis()/1000;
3184 3203
            logMetacat.info("DocumentImpl.delete - The deleting xml_queryresult time is "+(afterDeleteQueryResult - afterDeleteXmlAccess2));
3185 3204
            // Delete it from relation table
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java
58 58
       
59 59
  }//Constructor
60 60

  
61
  public String write(DBConnection conn,Reader xml,String pub,Reader dtd,
61
  public String write(DBConnection conn, String xml, String pub, Reader dtd,
62 62
                      String action, String docid, String user, String[] groups)
63 63
                      throws Exception
64 64
  {
......
66 66
                              groups, ruleBase, needValidation);
67 67
  }
68 68
  
69
  public String writeReplication(DBConnection conn, Reader xml, 
69
  public String writeReplication(DBConnection conn, String xml, 
70 70
                                        String pub, Reader dtd, String action, 
71 71
                                        String accnum, String user,
72 72
                                        String[] groups,String homeServer, 
......
104 104
   * @return
105 105
   * @throws Exception
106 106
   */
107
  public String writeReplication(DBConnection conn, Reader xml, 
107
  public String writeReplication(DBConnection conn, String xml, 
108 108
          String pub, Reader dtd, String action, 
109 109
          String accnum, String user,
110 110
          String[] groups,String homeServer, 
src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java
152 152
             // using emlparser to check id validation
153 153
             EMLParser parser = new EMLParser(eml210Content);
154 154
             DocumentImplWrapper documentWrapper = new DocumentImplWrapper(rule, true);
155
             StringReader xml = new StringReader(eml210Content);
155
//             StringReader xml = new StringReader(eml210Content);
156 156
             String  doAction = "UPDATE";
157 157
             String pub = null;
158 158
             String []groups = null;
......
164 164
            	 dbconn = DBConnectionPool
165 165
                 .getDBConnection("EMLVersionsTransformer.handleSingleEML200Document");
166 166
                  serialNumber = dbconn.getCheckOutSerialNumber();
167
                  documentWrapper.write(dbconn, xml, pub, dtd,
167
                  documentWrapper.write(dbconn, eml210Content, pub, dtd,
168 168
                          doAction, newId, owner, groups);
169 169
                  logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
170 170
                  transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
src/edu/ucsb/nceas/metacat/XMLQueryresultAccess.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that manages database access of xml access  
4
 *             information.
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat;
29

  
30
import java.sql.PreparedStatement;
31
import java.sql.ResultSet;
32
import java.sql.SQLException;
33

  
34
import org.apache.log4j.Logger;
35

  
36
import edu.ucsb.nceas.metacat.database.DBConnection;
37
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
38
import edu.ucsb.nceas.metacat.shared.AccessException;
39
import edu.ucsb.nceas.metacat.shared.BaseAccess;
40
import edu.ucsb.nceas.metacat.shared.BaseDAO;
41

  
42
public class XMLQueryresultAccess extends BaseAccess {
43
	
44
	private Logger logMetacat = Logger.getLogger(XMLQueryresultAccess.class);
45
	
46
	// Constructor
47
	public XMLQueryresultAccess() throws AccessException {}
48
	
49
	/**
50
	 * Delete xml access.  This removes all access records from the database for a given document
51
	 * 
52
	 * @param docId
53
	 *            document id
54
	 */
55
	public void deleteXMLQueryresulForDoc(String docId) throws AccessException {
56
		if (docId == null) {
57
			throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - docid is required when " + 
58
					"deleting XML access record");
59
		}
60
		
61
	    PreparedStatement pstmt = null;
62
		DBConnection conn = null;
63
		int serialNumber = -1;
64
		try {
65
			// check out DBConnection
66
			conn = DBConnectionPool.getDBConnection("XMLQueryresultAccess.deleteXMLQueryresulForDoc");
67
    		serialNumber = conn.getCheckOutSerialNumber();
68
    		
69
			String sql = "DELETE FROM xml_queryresult WHERE docid = ?";
70
			pstmt = conn.prepareStatement(sql);
71

  
72
			// Bind the values to the query
73
			pstmt.setString(1, docId);
74

  
75
			String sqlReport = "XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL: " + sql;
76
			sqlReport += " [" + docId + "]";
77
			
78
			logMetacat.info(sqlReport);
79

  
80
			pstmt.execute();
81
		} catch (SQLException sqle) {
82
			throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL error when deleting"
83
					+ "xml query result for doc id: " + docId + ":" + sqle.getMessage());
84
		} finally {
85
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
86
		}	   
87
	}
88
	
89
	/**
90
	 * Populate a job data object with the current row in a resultset
91
	 * 
92
	 * @param resultSet
93
	 *            the result set which is already pointing to the desired row.
94
	 * @return a scheduled job data object
95
	 */
96
	protected BaseDAO populateDAO(ResultSet resultSet) throws SQLException {
97

  
98
//		XMLAccessDAO xmlAccessDAO = new XMLAccessDAO();
99
//		xmlAccessDAO.setDocId(resultSet.getString("docid"));
100
//		xmlAccessDAO.setAccessFileId(resultSet.getString("accessfileid"));
101
//		xmlAccessDAO.setPrincipalName(resultSet.getString("principal_name"));
102
//		xmlAccessDAO.setPermission(resultSet.getLong("permission"));
103
//		xmlAccessDAO.setPermType(resultSet.getString("perm_type"));
104
//		xmlAccessDAO.setPermOrder(resultSet.getString("perm_order"));
105
//		xmlAccessDAO.setBeginTime(resultSet.getDate("begin_time"));
106
//		xmlAccessDAO.setEndTime(resultSet.getDate("end_time"));
107
//		xmlAccessDAO.setTicketCount(resultSet.getLong("ticket_count"));
108
//		xmlAccessDAO.setSubTreeId(resultSet.getString("subtreeid"));
109
//		xmlAccessDAO.setStartNodeId(resultSet.getString("startnodeid"));
110
//		xmlAccessDAO.setEndNodeId(resultSet.getString("endnodeid"));
111

  
112
		return null;
113
	}
114
	
115
}
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
382 382
      // Write the document into local host
383 383
      DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
384 384
      String newDocid = wrapper.writeReplication(dbConn,
385
                              new StringReader(newxmldoc),
385
                              newxmldoc,
386 386
                              docinfoHash.get("public_access"),
387 387
                              null,  /* the dtd text */
388 388
                              actions,
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
40 40
import edu.ucsb.nceas.metacat.DocumentImplWrapper;
41 41
import edu.ucsb.nceas.metacat.EventLog;
42 42
import edu.ucsb.nceas.metacat.McdbException;
43
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
43 44
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
45
import edu.ucsb.nceas.metacat.accesscontrol.PermOrderException;
44 46
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
45 47
import edu.ucsb.nceas.metacat.database.DBConnection;
46 48
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
......
554 556
			// write the document to local database
555 557
			DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
556 558
			//try this independently so we can set
557
			Exception writeException = null;
559
//			Exception writeException = null;
558 560
			try {
559
				wrapper.writeReplication(dbConn, new StringReader(xmldoc), null, null,
561
				wrapper.writeReplication(dbConn, xmldoc, null, null,
560 562
						dbaction, docid, user, null, homeServer, server, createdDate,
561 563
						updatedDate);
562
			} catch (Exception e) {
563
				writeException = e;
564
			}
564
			} finally {
565
//				writeException = e;
565 566

  
566
			//process extra access rules before dealing with the write exception (doc exist already)
567
//			Vector<AccessControlForSingleFile> accessControlList = dih
568
//					.getAccessControlList();
569
			
570
	        Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList();
571
	        if (accessControlList != null) {
572
	        	AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid);
573
	        	for (XMLAccessDAO xmlAccessDAO : accessControlList) {
574
	        		if (!acfsf.accessControlExists(xmlAccessDAO)) {
575
	        			acfsf.insertPermissions(xmlAccessDAO);
576
						logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
577
								+ " permissions added to DB");
578
	        		}
579
	            }
580
	        }
581
//			if (accessControlList != null) {
582
//				for (int i = 0; i < accessControlList.size(); i++) {
583
//					AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList
584
//							.get(i);
585
//					if (!acfsf.accessControlExists()) {
586
//						acfsf.insertPermissions();
587
//						logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
588
//								+ " permissions added to DB");
567
				//process extra access rules before dealing with the write exception (doc exist already)			
568
		        Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList();
569
		        if (accessControlList != null) {
570
		        	AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid);
571
		        	for (XMLAccessDAO xmlAccessDAO : accessControlList) {
572
		        		if (!acfsf.accessControlExists(xmlAccessDAO)) {
573
		        			acfsf.insertPermissions(xmlAccessDAO);
574
							logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
575
									+ " permissions added to DB");
576
		        		}
577
		            }
578
		        }
579
//				if (accessControlList != null) {
580
//					for (int i = 0; i < accessControlList.size(); i++) {
581
//						AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList
582
//								.get(i);
583
//						if (!acfsf.accessControlExists()) {
584
//							acfsf.insertPermissions();
585
//							logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid
586
//									+ " permissions added to DB");
587
//						}
589 588
//					}
590 589
//				}
591
//			}
592 590

  
593
			if (writeException != null) {
594
				throw writeException;
591
//				if (writeException != null) {
592
//					throw writeException;
593
//				}
594

  
595
				logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with "
596
						+ "action " + dbaction);
597
				EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid,
598
						dbaction);
595 599
			}
596

  
597
			logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with "
598
					+ "action " + dbaction);
599
			EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid,
600
					dbaction);
601
		}//try
602
		catch (Exception e) {
600
		} catch (SQLException sqle) {
603 601
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
604
			logReplication.error("document " + docid
605
					+ " failed to added to DB with " + "action " + dbaction + " because "
606
					+ e.getMessage());
607
			logReplication.error("ReplicationService.handleForceReplicateRequest - "
608
					+ "error: " + e.getMessage());
609

  
610
		}//catch
611
		finally {
602
			logReplication.error("ReplicationService.handleForceReplicateRequest - SQL error when adding doc " + docid + 
603
					" to DB with action " + dbaction + ": " + sqle.getMessage());
604
		} catch (MalformedURLException mue) {
605
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
606
			logReplication.error("ReplicationService.handleForceReplicateRequest - URL error when adding doc " + docid + 
607
					" to DB with action " + dbaction + ": " + mue.getMessage());
608
		} catch (SAXException se) {
609
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
610
			logReplication.error("ReplicationService.handleForceReplicateRequest - SAX parsing error when adding doc " + docid + 
611
					" to DB with action " + dbaction + ": " + se.getMessage());
612
		} catch (HandlerException he) {
613
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
614
			logReplication.error("ReplicationService.handleForceReplicateRequest - Handler error when adding doc " + docid + 
615
					" to DB with action " + dbaction + ": " + he.getMessage());
616
		} catch (IOException ioe) {
617
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
618
			logReplication.error("ReplicationService.handleForceReplicateRequest - I/O error when adding doc " + docid + 
619
					" to DB with action " + dbaction + ": " + ioe.getMessage());
620
		} catch (PermOrderException poe) {
621
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
622
			logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + 
623
					" to DB with action " + dbaction + ": " + poe.getMessage());
624
		} catch (AccessControlException ace) {
625
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
626
			logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + 
627
					" to DB with action " + dbaction + ": " + ace.getMessage());
628
		} catch (Exception e) {
629
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         
630
			logReplication.error("ReplicationService.handleForceReplicateRequest - General error when adding doc " + docid + 
631
					" to DB with action " + dbaction + ": " + e.getMessage());
632
		} finally {
612 633
			// Return the checked out DBConnection
613 634
			DBConnectionPool.returnDBConnection(dbConn, serialNumber);
614 635
		}//finally

Also available in: Unified diff