Project

General

Profile

« Previous | Next » 

Revision 6029

add event notification for insert/update/delete on documents (for semtools plugin)

View differences:

MetacatHandler.java
38 38
import edu.ucsb.nceas.metacat.database.DBConnection;
39 39
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
40 40
import edu.ucsb.nceas.metacat.dataquery.DataQuery;
41
import edu.ucsb.nceas.metacat.event.MetacatDocumentEvent;
42
import edu.ucsb.nceas.metacat.event.MetacatEventService;
41 43
import edu.ucsb.nceas.metacat.properties.PropertyService;
42 44
import edu.ucsb.nceas.metacat.replication.ForceReplicationHandler;
43 45
import edu.ucsb.nceas.metacat.service.SessionService;
......
1741 1743
          StringReader xmlReader = new StringReader(doctext[0]);
1742 1744
          boolean validate = false;
1743 1745
          DocumentImplWrapper documentWrapper = null;
1746
          String namespace = null;
1747

  
1744 1748
          try {
1745 1749
            // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ...
1746 1750
            // >
......
1752 1756
                documentWrapper = new DocumentImplWrapper(rule, validate);
1753 1757
            } else {
1754 1758
                
1755
                String namespace = XMLSchemaService.findDocumentNamespace(xmlReader);
1759
                namespace = XMLSchemaService.findDocumentNamespace(xmlReader);
1756 1760
                
1757 1761
                if (namespace != null) {
1758 1762
                    if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
......
1821 1825
              
1822 1826
              }
1823 1827
              
1828
              // alert listeners of this event
1829
              MetacatDocumentEvent mde = new MetacatDocumentEvent();
1830
              mde.setDocid(accNumber);
1831
              mde.setDoctype(namespace);
1832
              mde.setAction(doAction);
1833
              mde.setUser(user);
1834
              mde.setGroups(groups);
1835
              MetacatEventService.getInstance().notifyMetacatEventObservers(mde);
1836
              
1824 1837
              // Check for existing system metadata for the docid. Update
1825 1838
              // or create it as necessary, but only for non-DataONE
1826 1839
              // calls to handleInsertOrUpdateAction()
......
2018 2031
      } else {
2019 2032
        
2020 2033
        // delete the document from the database
2034
        String localId = null;
2021 2035
        try {
2022 2036
          
2023 2037
          // is the docid a GUID? 
2024 2038
          IdentifierManager im = IdentifierManager.getInstance();
2025
          String localId = im.getLocalId(docid[0]);
2039
          localId = im.getLocalId(docid[0]);
2026 2040
          this.deleteFromMetacat(out, request, response, localId, 
2027 2041
            user, groups);
2028 2042
          
2029 2043
        } catch (McdbDocNotFoundException mdnfe) {
2030 2044
          
2031 2045
          try {
2046
            localId = docid[0];
2047

  
2032 2048
            // not a GUID, use the docid instead
2033
            this.deleteFromMetacat(out, request, response, docid[0], 
2049
            this.deleteFromMetacat(out, request, response, localId, 
2034 2050
              user, groups);
2035 2051
              
2036 2052
          } catch ( McdbDocNotFoundException dnfe ) {
......
2049 2065
          
2050 2066
        } // end try()
2051 2067
        
2068
        // alert that it happened
2069
        MetacatDocumentEvent mde = new MetacatDocumentEvent();
2070
        mde.setDocid(localId);
2071
        mde.setDoctype(null);
2072
        mde.setAction("delete");
2073
        mde.setUser(user);
2074
        mde.setGroups(groups);
2075
        MetacatEventService.getInstance().notifyMetacatEventObservers(mde);
2076
        
2052 2077
      } // end if()
2053 2078
      
2054 2079
    }

Also available in: Unified diff