Project

General

Profile

« Previous | Next » 

Revision 3457

Added by barteau over 17 years ago

Clear the bean's "action" property after most operations are complete, in case user refreshes the browser (it won't repeat). Modified "delete" code, and "handleFileUpdate" method. Added new methods: getStringFromInputStream and makeRedirectUrl.

View differences:

src/edu/ucsb/nceas/metacat/clientview/ClientViewHelper.java
116 116
                    if (isLoggedIn()) {
117 117
                        clientViewBean.setSessionid(metacatClient.getSessionId());
118 118
                    }
119
                    //*** Now that the action has been processed, clear it.
120
                    clientViewBean.setAction("");
119 121
                } else if (action.equals("Logout")) {
120 122
                    message = metacatClient.logout();
121 123
                    setLoggedIn(message);
......
127 129
                        clientViewBean.setPassword("");
128 130
                        clientViewBean.setOrganization("");
129 131
                    }
132
                    //*** Now that the action has been processed, clear it.
133
                    clientViewBean.setAction("");
130 134
                    
131 135
                } else if (action.equals("Delete")) {
132 136
                    
133
                    //*** Refresh the select list.
134
//                    message = handleDocIdSelect();
135
//                    clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
136 137
                    ClientFgdcHelper.clientDeleteRequest(clientViewBean, this);
137
                    message = (String) clientSession.getAttribute("updateFeedback");
138
                    clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
138
                    clientViewBean.setAction("read"); //*** Set for re-query.
139
                    //*** Note: the clientViewBean will already have the updated Meta Doc Id.
139 140
                } else if (action.equals("Upload")) {
140 141
                    message = "";
141 142
                    //*** Only process request if a file upload.
......
145 146
                        message = handlePackageUpload(clientViewBean, multipartParser);
146 147
                    }
147 148
                    clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, message);
149
                    //*** Now that the action has been processed, clear it.
150
                    clientViewBean.setAction("");
148 151
                    
149 152
                } else if (action.equals("Update")) {
150 153
                    System.out.println("This is not implemented here.  Call ClientViewHelper.jspx");
......
152 155
                    message = handleDocIdSelect();
153 156
                    clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
154 157
                }
155
                //*** Now that the action has been processed, clear it.
156
                clientViewBean.setAction("");
157 158
                
158 159
            } catch (Exception ex) {
159 160
                message = ex.getMessage();
......
317 318
    }
318 319
    
319 320
    public String handleFileUpdate(MultipartParser multipartParser) throws Exception {
320
        String                      result = "", fNm, action, lastDocId, newDocId, xPathQuery;
321
        String                      result = "", fNm, action, lastDocId, newDocId, xPathQuery, qFrmt;
321 322
        InputStream                 inputStream;
322 323
        HashMap                     paramsMap;
323 324
        StringBuilder               fileName;
......
333 334
            lastDocId = (String) paramsMap.get("docid");
334 335
            //*** Get the metadata Doc Id.
335 336
            metadataDocId = (String) paramsMap.get("metadataDocId");
337
            //*** Get the qformat.
338
            qFrmt = (String) paramsMap.get("qformat");
339
            
336 340
            fNm = fileName.toString();
337 341
            
338 342
            try {
......
342 346
                    if (ClientFgdcHelper.isFGDC(getMetadataDoc())) {
343 347
                        clientViewBean.setContentStandard(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE);
344 348
                        if (!ClientFgdcHelper.hasMetacatInfo(lastDocId, getMetadataDoc())) {
349
                            
350
                            //*** Save the Doc Id for re-query.
351
                            clientViewBean.setMetaFileDocId(lastDocId);
352
                            clientViewBean.setAction("read"); //*** Set for re-query.
345 353
                            result = "Update not performed: the Metadata file has no prior Metacat info in it.";
346 354
                        } else {
347 355
                            xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1s", lastDocId);
348 356
                            newDocId = updateMetadataDoc(lastDocId, xPathQuery, fNm);
349
                            result = "MetaCat Package Updated:  the Document Identifier is " + newDocId;
357
                            
358
                            //*** Save the Doc Id for re-query.
359
                            clientViewBean.setMetaFileDocId(newDocId);
360
                            clientViewBean.setAction("read"); //*** Set for re-query.
361
                            //result = makeRedirectUrl(newDocId, qFrmt);
362
                            result = "Updated to new document (from " + lastDocId + " to " + newDocId + ")";
350 363
                        }
351 364
                    } else {
352 365
                        //***TODO This is EML.
353 366
                        clientViewBean.setContentStandard(ClientView.ECOLOGICAL_METADATA_LANGUAGE);
367
                        
368
                        //*** Save the Doc Id for re-query.
369
                        clientViewBean.setMetaFileDocId(lastDocId);
370
                        clientViewBean.setAction("read"); //*** Set for re-query.
354 371
                        result = "Currently this functionality only supports FGDC metadata.";
355 372
                    }
356 373
                } else {
357 374
                    //*** This is a data file.
358 375
                    //*** Query for the metadata, we need to update it with the new data file doc id.
359 376
                    setMetadataDoc(metadataDocId);
377
                    
360 378
                    if (ClientFgdcHelper.isFGDC(getMetadataDoc())) {
361 379
                        clientViewBean.setContentStandard(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE);
362 380
                        fileInfo = parseFileInfo(fNm);
......
366 384
                        ClientFgdcHelper.updateFileNameAndType(getMetadataDoc().getDocumentElement(), newDocId, fileInfo);
367 385
                        //*** Upload the data file to metacat.
368 386
                        result = getMetacatClient().upload(newDocId, fNm, inputStream, Integer.MAX_VALUE);
369
                        result = "Updated " + lastDocId + " with " + fNm + " (" + newDocId + ") ";
387
                        System.out.println("ClientViewHelper.handleFileUpdate: upload returned " + result);
370 388
                        
389
                        
371 390
                        //*** Upload the metadata file to metacat.
372 391
                        xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1s", metadataDocId);
373 392
                        newDocId = updateMetadataDoc(metadataDocId, xPathQuery, null);
374
                        System.out.println("ClientViewHelper.handleFileUpdate:\n" + XMLUtilities.getDOMTreeAsString(getMetadataDoc().getDocumentElement()));
393
                        
394
                        //*** Save the new meta Doc Id for re-query.
395
                        clientViewBean.setMetaFileDocId(newDocId);
396
                        clientViewBean.setAction("read"); //*** Set for re-query.
397
                        //result = makeRedirectUrl(newDocId, qFrmt);
398
                        result = "Updated to new document (from " + lastDocId + " to " + newDocId + ")";
399
                        
375 400
                    } else {
376 401
                        //***TODO This is EML.
377 402
                        clientViewBean.setContentStandard(ClientView.ECOLOGICAL_METADATA_LANGUAGE);
403
                        
404
                        //*** Save the old meta Doc Id for re-query.
405
                        clientViewBean.setMetaFileDocId(metadataDocId);
406
                        clientViewBean.setAction("read"); //*** Set for re-query.
378 407
                        result = "Currently this functionality only supports FGDC metadata.";
379 408
                    }
380
                    
381 409
                }
382 410
            } catch (java.io.IOException ex) {
383 411
                ex.printStackTrace();
......
385 413
        } else {
386 414
            result = "Please enter the updated file path/name.";
387 415
        }
416
        clientViewBean.setMessage(ClientView.UPDATE_MESSAGE, result);
388 417
        return(result);
389 418
    }
390 419
    
......
715 744
        return(result);
716 745
        
717 746
    }
747
    
748
    public static String getStringFromInputStream(InputStream input) {
749
        StringBuffer result = new StringBuffer();
750
        BufferedReader in = new BufferedReader(new InputStreamReader(input));
751
        String line;
752
        try {
753
            while ((line = in.readLine()) != null) {
754
                result.append(line);
755
            }
756
        } catch (IOException e) {
757
            System.out.println("ClientViewHelper.getStringFromInputStream: " + e);
758
        }
759
        return result.toString();
760
    }
761
    
718 762
    //*** END: Static utility methods ***
719 763
    
764
    public String makeRedirectUrl() {
765
        String                      result = "", docId;
766
        
767
        docId = clientViewBean.getMetaFileDocId();
768
        if (docId != null && !docId.equals("")) {
769
            result = "metacat?action=" + clientViewBean.getAction()
770
            + "&qformat=" +clientViewBean.getQformat()
771
            + "&docid=" + docId
772
            + "&sessionid=" + clientViewBean.getSessionid();
773
            result += "&msg=" + clientViewBean.getMessage(ClientView.UPDATE_MESSAGE);
774
        } else {
775
//            result = "metacat?action=query&qformat=" + clientViewBean.getQformat()
776
//            + "&anyfield=" + clientViewBean.getAnyfield()
777
//            + "&sessionid=" + clientViewBean.getSessionid();
778
            result = "style/common/confirm.jspx";
779
        }
780
        //*** Reset bean action property.
781
        clientViewBean.setAction("");
782
        return(result);
783
    }
784
    
720 785
}

Also available in: Unified diff