Project

General

Profile

Revision 3517

Added by barteau almost 14 years ago

Added new functionality for action="Set Access". Includes methods handleChangeAccess, setPublicAccess and getNodeTextStack. Also, cleaned up some code as a result.

View differences:

src/edu/ucsb/nceas/metacat/clientview/ClientViewHelper.java
14 14
import com.oreilly.servlet.multipart.ParamPart;
15 15
import com.oreilly.servlet.multipart.Part;
16 16
import edu.ucsb.nceas.metacat.MetaCatUtil;
17
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
17 18
import edu.ucsb.nceas.metacat.client.MetacatClient;
19
import edu.ucsb.nceas.metacat.client.MetacatException;
18 20
import edu.ucsb.nceas.metacat.client.MetacatFactory;
19 21
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
20 22
import edu.ucsb.nceas.utilities.XMLUtilities;
......
25 27
import java.io.InputStreamReader;
26 28
import java.io.Reader;
27 29
import java.io.StringReader;
30
import java.util.Collection;
28 31
import java.util.HashMap;
29 32
import java.util.Iterator;
30 33
import java.util.Properties;
34
import java.util.Stack;
31 35
import java.util.TreeMap;
32 36
import java.util.Vector;
33 37
import javax.servlet.http.HttpServletRequest;
......
59 63
    
60 64
    public static final String                          DOWNLOAD_ACTION = "Download";
61 65
    
66
    public static final String                          PERMISSION_TYPE_ALLOW = "allow";
67
    
68
    public static final String                          PERMISSION_TYPE_DISALLOW = "deny";
69
    
62 70
    /**
63 71
     * Creates a new instance of ClientViewHelper
64 72
     */
......
88 96
        if (clientViewBean != null) {
89 97
            action = clientViewBean.getAction();
90 98
            contentType = request.getContentType();
91
            
99
        
92 100
            //*** BEGIN: manual bind params to bean (if we arrived here via the ClientViewHelper.jspx).
93 101
            if (action == null || action.equals("")) {
94 102
                if (contentType != null && contentType.contains("multipart/form-data")) {
......
99 107
                    clientViewBean.setDocId(request.getParameter("docid"));
100 108
                    clientViewBean.setMetaFileDocId(request.getParameter("metadataDocId"));
101 109
                    clientViewBean.setQformat(request.getParameter("qformat"));
110
                    clientViewBean.setPublicAccess(request.getParameter("publicAccess") != null);
111
                    clientViewBean.setContentStandard(request.getParameter("contentStandard"));
102 112
                }
103 113
            }
114
            //*** END: manual bind params to bean.
104 115
            
105
            //*** END: manual bind params to bean.
106 116
            if (action != null) {
107 117
                try {
108 118
                    if (action.equals("Login")) {
......
160 170
                        clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
161 171
                    } else if (action.equals("Download")) {
162 172
                        download(clientViewBean, response);
173
                    } else if (action.equals("Set Access")) {
174
                        result = handleChangeAccess(clientViewBean.getMetaFileDocId(), 
175
                                (clientViewBean.isPublicAccess()? PERMISSION_TYPE_ALLOW: PERMISSION_TYPE_DISALLOW));
176
                        clientViewBean.setAction("");
177
                        clientViewBean.setMessage(ClientView.UPDATE_MESSAGE, result);
163 178
                    }
164 179
                    
165 180
                } catch (Exception ex) {
......
266 281
        StringBuffer                fileName;
267 282
        boolean                     sendIt;
268 283
        Iterator                    iterIt;
284
        Stack                       docIdStack;
269 285
        
270 286
        //*** Get the First file, which should be the metadata file.
271 287
        paramsMap = new HashMap();
......
312 328
                
313 329
                result = "MetaCat Package Inserted:  the Document Identifier is " + metaDocId;
314 330
                reader.close();
315
                
316 331
                //*** Grant the public read access to the meta file.
317 332
                if (paramsMap.containsKey("publicAccess")) {
318
                    getMetacatClient().setAccess(metaDocId, "public", "read", "allow", "allowFirst");
319
                    //*** Grant the public read access to the data files.
320
                    iterIt = dataDocIDs.keySet().iterator();
321
                    while(iterIt.hasNext()) {
322
                        getMetacatClient().setAccess((String) iterIt.next(), "public", "read", "allow", "allowFirst");
323
                    }
333
                    docIdStack = new Stack();
334
                    docIdStack.addAll(dataDocIDs.keySet());
335
                    setPublicAccess(this.PERMISSION_TYPE_ALLOW, metaDocId, docIdStack);
324 336
                }
325 337
            }
326 338
        } else {
......
331 343
        return(result);
332 344
    }
333 345
    
346
    private String setPublicAccess(String permissionType, String metaDocId, Stack docIdStack)
347
    throws InsufficientKarmaException, MetacatException, MetacatInaccessibleException {
348
        String                      result = " for Documents ";
349
        String                      docId, lst = metaDocId, permOrder;
350
        
351
        if (permissionType.equals("allow"))
352
            permOrder = "denyFirst";
353
        else
354
            permOrder = "allowFirst";
355
        
356
        getMetacatClient().setAccess(metaDocId, "public", "read", permissionType, permOrder);
357
        //*** Grant the public read access to the data files.
358
        while(!docIdStack.isEmpty()) {
359
            docId = (String) docIdStack.pop();
360
            getMetacatClient().setAccess(docId, "public", "read", permissionType, permOrder);
361
            lst += ", " + docId;
362
        }
363
        result = "Changed public read access to '" + permissionType + "' for " + result + lst;
364
        return(result);
365
    }
366
    
367
    private String handleChangeAccess(String metaDocId, String permissionType) throws Exception {
368
        Stack                       dataDocIDs;
369
        String                      result = "", xpathExpr = null;
370
        
371
        setMetadataDoc(metaDocId);
372
        //*** Build list of sub-documents.
373
        if (clientViewBean.getContentStandard().equals(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE)) {
374
            xpathExpr = ClientFgdcHelper.SUB_DOCS_PATH;
375
        } else if (clientViewBean.getContentStandard().equals(ClientView.ECOLOGICAL_METADATA_LANGUAGE)) {
376
            xpathExpr = null; //TODO  - EML
377
        }
378
        if (xpathExpr != null) {
379
            dataDocIDs = getNodeTextStack(xpath, xpathExpr, getMetadataDoc().getDocumentElement());
380
            result = setPublicAccess(permissionType, metaDocId, dataDocIDs);
381
        }
382
        return(result);
383
    }
384
    
334 385
    public String handleFileUpdate(MultipartParser multipartParser) throws Exception {
335 386
        String                      result = "", fNm, action, lastDocId, newDocId, xPathQuery, qFrmt;
336 387
        InputStream                 inputStream;
......
372 423
                            //*** Save the Doc Id for re-query.
373 424
                            clientViewBean.setMetaFileDocId(newDocId);
374 425
                            clientViewBean.setAction("read"); //*** Set for re-query.
375
                            //result = makeRedirectUrl(newDocId, qFrmt);
376 426
                            result = "Updated to new document (from " + lastDocId + " to " + newDocId + ")";
377 427
                        }
378 428
                    } else {
......
783 833
        return(result);
784 834
    }
785 835
    
836
    public static Stack getNodeTextStack(XPath xpathInstance, String xpathExpr, Node parentNode) {
837
        String                      nodeLst[];
838
        Stack                       result = new Stack();
839
        
840
        nodeLst = getNodeTextList(xpathInstance, xpathExpr, parentNode);
841
        for(int i = 0; i < nodeLst.length; i++)
842
            result.push(nodeLst[i]);
843
        return(result);
844
    }
845
    
786 846
    public static String getStringFromInputStream(InputStream input) {
787 847
        StringBuffer result = new StringBuffer();
788 848
        BufferedReader in = new BufferedReader(new InputStreamReader(input));
......
800 860
    //*** END: Static utility methods ***
801 861
    
802 862
    public String makeRedirectUrl() {
803
        String                      result, docId;
863
        String                      result, docId, message;
804 864
        
805 865
        docId = clientViewBean.getMetaFileDocId();
806 866
        if (clientViewBean.getAction().equals(DOWNLOAD_ACTION)) {
807 867
            result = null;
808 868
        } else if (docId != null && !docId.equals("")) {
869
            message = clientViewBean.getMessage(ClientView.UPDATE_MESSAGE);
809 870
            result = "metacat?action=read&qformat=" +clientViewBean.getQformat()
810
            + "&docid=" + docId
811
                    + "&sessionid=" + clientViewBean.getSessionid();
812
            result += "&msg=" + clientViewBean.getMessage(ClientView.UPDATE_MESSAGE);
871
            + "&docid=" + docId + "&sessionid=" + clientViewBean.getSessionid() + "&message=" + message;
813 872
        } else {
814 873
            result = "style/common/confirm.jspx";
815 874
        }

Also available in: Unified diff