Project

General

Profile

« Previous | Next » 

Revision 6029

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

View differences:

src/edu/ucsb/nceas/metacat/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
    }
src/edu/ucsb/nceas/metacat/event/MetacatDocumentEvent.java
1
package edu.ucsb.nceas.metacat.event;
2

  
3
public class MetacatDocumentEvent implements MetacatEvent {
4

  
5
	private String docid;
6
	private String action;
7
	private String doctype;
8
	private String user;
9
	private String[] groups;
10
	
11
	public MetacatDocumentEvent() {
12
	}
13

  
14
	public String getDocid() {
15
		return docid;
16
	}
17

  
18
	public void setDocid(String docid) {
19
		this.docid = docid;
20
	}
21

  
22
	public String getDoctype() {
23
		return doctype;
24
	}
25

  
26
	public void setDoctype(String doctype) {
27
		this.doctype = doctype;
28
	}
29

  
30
	public String getAction() {
31
		return action;
32
	}
33

  
34
	public void setAction(String action) {
35
		this.action = action;
36
	}
37

  
38
	public String getUser() {
39
		return user;
40
	}
41

  
42
	public void setUser(String user) {
43
		this.user = user;
44
	}
45

  
46
	public String[] getGroups() {
47
		return groups;
48
	}
49

  
50
	public void setGroups(String[] groups) {
51
		this.groups = groups;
52
	}
53
	
54
}
0 55

  
src/edu/ucsb/nceas/metacat/event/MetacatEvent.java
1
package edu.ucsb.nceas.metacat.event;
2

  
3
public interface MetacatEvent {
4

  
5
}
0 6

  
src/edu/ucsb/nceas/metacat/event/MetacatEventService.java
1
package edu.ucsb.nceas.metacat.event;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public class MetacatEventService {
7
	
8
	private static MetacatEventService instance;
9
	
10
	private List<MetacatEventObserver> observers;
11
	
12
	private MetacatEventService() {
13
		observers = new ArrayList<MetacatEventObserver>();
14
	}
15
	
16
	public static MetacatEventService getInstance() {
17
		if (instance == null) {
18
			instance = new MetacatEventService();
19
		}
20
		return instance;
21
	}
22
	
23
	public void addMetacatEventObserver(MetacatEventObserver o) {
24
		observers.add(o);
25
	}
26
	
27
	public void removeMetacatEventObserver(MetacatEventObserver o) {
28
		observers.remove(o);
29
	}
30
	
31
	public void notifyMetacatEventObservers(MetacatEvent e) {
32
		for (MetacatEventObserver o: observers) {
33
			o.handleEvent(e);
34
		}
35
	}
36
}
0 37

  
src/edu/ucsb/nceas/metacat/event/MetacatEventObserver.java
1
package edu.ucsb.nceas.metacat.event;
2

  
3
public interface MetacatEventObserver {
4
	
5
	public void handleEvent(MetacatEvent e);
6

  
7
}
0 8

  

Also available in: Unified diff