Project

General

Profile

« Previous | Next » 

Revision 8560

Sync access policy between MN -> CN when access rules are updated in EML 2.1+ for data object

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
67 67
import edu.ucsb.nceas.metacat.database.DBConnection;
68 68
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
69 69
import edu.ucsb.nceas.metacat.database.DatabaseService;
70
import edu.ucsb.nceas.metacat.dataone.SyncAccessPolicy;
70 71
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
71 72
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex;
72 73
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
2693 2694
    	
2694 2695
    	// Get the xml as a string so we can write to file later
2695 2696
    	StringReader xmlReader = new StringReader(xmlString);
2696
    	
2697

  
2697 2698
        logMetacat.debug("DocumentImpl.write - conn usage count before writing: "
2698 2699
                + conn.getUsageCount());
2699 2700
        AccessionNumber ac = new AccessionNumber(accnum, action);
......
2755 2756
                	// detect encoding
2756 2757
                    XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
2757 2758
			        String encoding = xsr.getEncoding();
2758
			        
2759
			        Vector<String>guidsToSync = new Vector<String>();
2760

  
2759 2761
                    /*
2760 2762
                     * XMLReader parser = initializeParser(conn, action, docid,
2761 2763
                     * updaterev, validate, user, groups, pub, serverCode, dtd);
......
2763 2765
                    logMetacat.debug("DocumentImpl.write - initializing parser");
2764 2766
                    parser = initializeParser(conn, action, docid, xmlReader, updaterev,
2765 2767
                            user, groups, pub, serverCode, dtd, ruleBase,
2766
                            needValidation, false, null, null, encoding, writeAccessRules);
2768
                            needValidation, false, null, null, encoding, writeAccessRules, guidsToSync);
2767 2769
                    	// false means it is not a revision doc
2768 2770
                                   //null, null are createdate and updatedate
2769 2771
                                   //null will use current time as create date time
......
2782 2784

  
2783 2785
                    // write to xml_node complete. start the indexing thread.
2784 2786
                    addDocidToIndexingQueue(docid, rev);
2787
                    
2788
			        // The EML parser has already written to systemmetadata and then writes to xml_access when the db transaction
2789
                    // is committed. If the pids that have been updated are for data objects with their own access rules, we
2790
			        // must inform the CN to sync it's access rules with the MN, so the EML 2.1 parser collected such pids from the parse
2791
			        // operation.
2792
            		if (guidsToSync.size() > 0) {
2793
            			try {
2794
            				SyncAccessPolicy syncAP = new SyncAccessPolicy();
2795
            				syncAP.sync(guidsToSync);
2796
            			} catch (Exception e) {
2797
            				logMetacat.error("Error syncing pids with CN: " + " Exception " + e.getMessage());
2798
            				e.printStackTrace(System.out);
2799
            			}
2800
            		}
2785 2801
               } catch (Exception e) {
2786 2802
                   e.printStackTrace();
2787 2803
            	   logMetacat.error("DocumentImpl.write - Problem with parsing: " + e.getMessage());
......
2851 2867
            // detect encoding
2852 2868
        	XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
2853 2869
	        String encoding = xsr.getEncoding();
2854
	        
2870
	        Vector<String>guidsToSync = new Vector<String>();
2871

  
2855 2872
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
2856
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules);
2873
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync);
2857 2874
                    // null and null are createtime and updatetime
2858 2875
                    // null will create current time
2859 2876
                    //false means it is not a revision doc
......
2872 2889
        	writeToFileSystem(xmlString, accnum, encoding);
2873 2890

  
2874 2891
            addDocidToIndexingQueue(docid, rev);
2892
    		if (guidsToSync.size() > 0) {
2893
    			try {
2894
    				SyncAccessPolicy syncAP = new SyncAccessPolicy();
2895
    				syncAP.sync(guidsToSync);
2896
    			} catch (Exception e) {
2897
    				logMetacat.error("Error syncing pids with CN: " + " Exception " + e.getMessage());
2898
    				e.printStackTrace(System.out);
2899
    			}
2900
    		}
2875 2901
        } catch (Exception e) {
2876 2902
        	logMetacat.error("DocumentImpl.write - Problem with parsing: " + e.getMessage());
2877 2903
            e.printStackTrace();
......
3051 3077
	        
3052 3078
	        // no need to write the EML-contained access rules for replication
3053 3079
	        boolean writeAccessRules = false;
3054
	       
3080
	        Vector<String>guidsToSync = new Vector<String>();
3081

  
3055 3082
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
3056 3083
                    pub, serverCode, dtd, ruleBase, needValidation, 
3057
                    isRevision, createDate, updateDate, encoding, writeAccessRules);
3084
                    isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync);
3058 3085
         
3059 3086
            conn.setAutoCommit(false);
3060 3087
            parser.parse(new InputSource(xmlReader));
......
3562 3589
            String action, String docid, Reader xml, String rev, String user,
3563 3590
            String[] groups, String pub, int serverCode, Reader dtd,
3564 3591
            String ruleBase, boolean needValidation, boolean isRevision,
3565
            Date createDate, Date updateDate, String encoding, boolean writeAccessRules) throws Exception
3592
            Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync) throws Exception
3566 3593
    {
3567 3594
        XMLReader parser = null;
3568 3595
        try {
......
3604 3631
            } else if (ruleBase != null && ruleBase.equals(EML210)) {
3605 3632
                logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.1.0 parser");
3606 3633
                chandler = new Eml210SAXHandler(dbconn, action, docid, rev,
3607
                        user, groups, pub, serverCode, createDate, updateDate, writeAccessRules);
3634
                        user, groups, pub, serverCode, createDate, updateDate, writeAccessRules, guidsToSync);
3608 3635
                chandler.setIsRevisionDoc(isRevision);
3609 3636
                chandler.setEncoding(encoding);
3610 3637
                parser.setContentHandler((ContentHandler) chandler);
src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java
122 122
	DistributionSection currentDistributionSection = null;
123 123

  
124 124
	Vector<DistributionSection> allDistributionSections = new Vector<DistributionSection>();
125
    private Vector<String> guidsToSync;
125 126

  
126 127
	// This variable keeps a counter of each distribution element. This index
127 128
	// will be used to name the inline data file that gets written to disk, and to
......
191 192
	 */
192 193
	public Eml210SAXHandler(DBConnection conn, String action, String docid,
193 194
			String revision, String user, String[] groups, String pub, int serverCode,
194
			Date createDate, Date updateDate, boolean writeAccessRules) throws SAXException {
195
			Date createDate, Date updateDate, boolean writeAccessRules, Vector<String> guidsToSync) throws SAXException {
195 196
		super(conn, action, docid, revision, user, groups, pub, serverCode, createDate,
196 197
				updateDate, writeAccessRules);
198
		
199
		this.guidsToSync = guidsToSync;
197 200
		// Get the unchangeable subtrees (user doesn't have write permission)
198 201
		try {
199 202

  
......
1597 1600

  
1598 1601
				pstmt.setString(7, subSectionId);
1599 1602
				logMetacat.debug("SubSectionId in accesstable: " + subSectionId);
1603
				
1604
				// Save guid of data object for syncing of access policy with CN after parsing
1605
				// is successful (see DocumentImpl.write)
1606
				guidsToSync.add(referencedGuid);
1600 1607
			}
1601 1608

  
1602 1609
			Vector<AccessRule> accessRules = accessSection.getAccessRules();
......
1637 1644
		// for D1, refresh the entries
1638 1645
		HazelcastService.getInstance().refreshSystemMetadataEntry(guid);
1639 1646
		HazelcastService.getInstance().refreshSystemMetadataEntry(referencedGuid);
1640
		
1641 1647

  
1642 1648
	}// writeGivenAccessRuleIntoDB
1643 1649

  

Also available in: Unified diff