Project

General

Profile

« Previous | Next » 

Revision 4399

adding document "cart" feature to metacat. will not be highly published as a feature until well-vetted.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
46 46
import java.text.ParseException;
47 47
import java.text.SimpleDateFormat;
48 48
import java.util.Enumeration;
49
import java.util.HashMap;
49 50
import java.util.Hashtable;
50 51
import java.util.Iterator;
52
import java.util.Map;
51 53
import java.util.Timer;
52 54
import java.util.Vector;
53 55
import java.util.zip.ZipEntry;
......
73 75
import com.oreilly.servlet.multipart.ParamPart;
74 76
import com.oreilly.servlet.multipart.Part;
75 77

  
78
import edu.ucsb.nceas.metacat.cart.CartManager;
76 79
import edu.ucsb.nceas.metacat.dataquery.DataQuery;
77 80
import edu.ucsb.nceas.metacat.service.DatabaseService;
78 81
import edu.ucsb.nceas.metacat.service.PropertyService;
......
706 709
							.debug("******************* DATA QUERY ********************");
707 710
					handleDataquery(params, response, sessionId);
708 711
				}
712
				else if (action.trim().equals("editcart")) {
713
					logMetacat
714
							.debug("******************* EDIT CART ********************");
715
					handleEditCart(params, response, sessionId);
716
				}
709 717
				else if (action.equals("export")) {
710 718

  
711 719
					handleExportAction(params, response, userName, groupNames, password);
......
933 941
		
934 942
	}
935 943
	
944
	private void handleEditCart(
945
			Hashtable<String, String[]> params,
946
            HttpServletResponse response,
947
            String sessionId) throws PropertyNotFoundException, IOException {
948
		
949
		CartManager cm = null;
950
		if (sessionId != null) {
951
			cm = new CartManager(sessionId);
952
		}
953
		else {
954
			cm = new CartManager();
955
		}
956
		
957
    	String editOperation = ((String[])params.get("operation"))[0];
958
    	
959
    	String[] docids = (String[]) params.get("docid");
960
    	String[] field = (String[])params.get("field");
961
    	String[] path = (String[])params.get("path");
962
    	
963
    	Map fields = null;
964
    	if (field != null && path != null) {
965
    		fields = new HashMap();
966
    		fields.put(field[0], path[0]);
967
    	}
968
    	
969
    	//TODO handle attribute map (metadata fields)
970
    	cm.editCart(editOperation, docids, fields);
971
    	
972
	}
973
	
936 974
    // ///////////////////////////// METACAT SPATIAL ///////////////////////////
937 975
    
938 976
    /**
src/edu/ucsb/nceas/metacat/util/SessionData.java
40 40

  
41 41
import edu.ucsb.nceas.metacat.AuthLdap;
42 42
import edu.ucsb.nceas.metacat.MetaCatServlet;
43
import edu.ucsb.nceas.metacat.cart.DocumentCart;
43 44

  
44 45
public class SessionData {
45 46
	
......
49 50
	private String password = null;
50 51
	private final Calendar creationTime = Calendar.getInstance();
51 52
	private Calendar lastAccessedTime = Calendar.getInstance();
53
	private DocumentCart documentCart = null;
52 54
	
53 55
	private Logger logMetacat = Logger.getLogger(SessionData.class);
54 56
	
......
104 106
	public Calendar getCreationTime() {
105 107
		return creationTime;
106 108
	}
109

  
110
	public DocumentCart getDocumentCart() {
111
		if (documentCart == null) {
112
			documentCart = new DocumentCart();
113
		}
114
		return documentCart;
115
	}
116

  
117
	public void setDocumentCart(DocumentCart documentCart) {
118
		this.documentCart = documentCart;
119
	}
107 120
}
src/edu/ucsb/nceas/metacat/cart/CartManager.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2008 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 * Author: Benjamin Leinfelder 
7
 * '$Date:  $'
8
 * '$Revision:  $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

  
25
package edu.ucsb.nceas.metacat.cart;
26

  
27
import java.util.Map;
28

  
29
import org.apache.commons.logging.Log;
30
import org.apache.commons.logging.LogFactory;
31

  
32
import edu.ucsb.nceas.metacat.service.SessionService;
33

  
34

  
35
/**
36
 * Class to query data
37
 */
38
public class CartManager {
39

  
40
	private static Log log = LogFactory.getLog(CartManager.class);
41

  
42
	private String sessionId = null;
43
	private DocumentCart documentCart = null;
44
	
45
	/**
46
	 * empty constructor to initialize query
47
	 */
48
	public CartManager() {
49
		init();
50
	}
51
	
52
	public CartManager(String sessionId) {
53
		// initialize the necessary parts
54
		this.sessionId = sessionId;
55
		init();
56
	}
57
	
58
	private void init() {
59
		documentCart = SessionService.getRegisteredSession(sessionId).getDocumentCart();
60
		if (documentCart == null) {
61
			documentCart = new DocumentCart();
62
		}
63
		
64
	}
65
	
66
	public void editCart(String operation, String[] docids, Map fields) {
67
		
68
		//for attribute fields
69
		if (operation.equalsIgnoreCase("addField")) {
70
			documentCart.addFields(fields);
71
		}
72
		if (operation.equalsIgnoreCase("removeField")) {
73
			String field = (String) fields.keySet().toArray()[0];
74
			documentCart.removeField(field);
75
		}
76
		if (operation.equalsIgnoreCase("addFields")) {
77
			documentCart.addFields(fields);
78
		}
79
		if (operation.equalsIgnoreCase("clearfields")) {
80
			documentCart.clearFields();
81
		}
82
		
83
		//for document ids
84
		if (operation.equalsIgnoreCase("clear")) {
85
			documentCart.clear();
86
		}
87
		if (docids != null) {
88
			for (int i=0; i < docids.length; i++) {
89
				if (operation.equalsIgnoreCase("add")) {
90
					documentCart.addDocument(docids[i], fields);
91
				}
92
				if (operation.equalsIgnoreCase("remove")) {
93
					documentCart.removeDocument(docids[i]);
94
				}
95
			}
96
		}
97
		
98
		SessionService.getRegisteredSession(sessionId).setDocumentCart(documentCart);
99
	}
100

  
101
}
0 102

  
src/edu/ucsb/nceas/metacat/cart/DocumentCart.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2008 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 * Author: Benjamin Leinfelder 
7
 * '$Date:  $'
8
 * '$Revision:  $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24
package edu.ucsb.nceas.metacat.cart;
25

  
26
import java.util.HashMap;
27
import java.util.Map;
28

  
29
public class DocumentCart {
30

  
31
	
32
	private Map docids = new HashMap();
33
	
34
	private Map fields = new HashMap();
35
	
36
	public void addDocument(String docid, Map fields) {
37
		docids.put(docid, fields);
38
	}
39
	
40
	public void removeDocument(String docid) {
41
		docids.remove(docid);
42
	}
43
	
44
	public Map getFields(String docid) {
45
		return (Map) docids.get(docid);
46
	}
47
	
48
	public String[] getDocids() {
49
		return (String[]) docids.keySet().toArray(new String[0]);
50
	}
51
	
52
	public void clear() {
53
		docids.clear();
54
	}
55
	
56
	//for accessing the metadata attribute field mappings
57
	public void addField(String label, String path) {
58
		fields.put(label, path);
59
	}
60
	
61
	public void removeField(String label) {
62
		fields.remove(label);
63
	}
64
	
65
	public void clearFields() {
66
		fields.clear();
67
	}
68
	
69
	public Map getFields() {
70
		return fields;
71
	}
72
	
73
	public void addFields(Map f) {
74
		fields.putAll(f);
75
	}
76
	
77
	public String[] getLabels() {
78
		return (String[]) fields.keySet().toArray(new String[0]);
79
	}
80
	
81
	public String[] getPaths() {
82
		return (String[]) fields.values().toArray(new String[0]);
83
	}
84
}

Also available in: Unified diff