Project

General

Profile

« Previous | Next » 

Revision 2102

Added by Matt Jones over 20 years ago

Added additional logging calls for read, upload, insert, update, delete, and
other commands. Now need to get a reporting function working and this
bug 101 will be largely finished.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
402 402
                }
403 403
            } else if (action.equals("export")) {
404 404

  
405
                handleExportAction(params, response, username, groupnames,
406
                        password);
405
                handleExportAction(params, response, username, 
406
                        groupnames, password);
407 407
            } else if (action.equals("read")) {
408
                handleReadAction(params, response, username, password,
408
                handleReadAction(params, request, response, username, password,
409 409
                        groupnames);
410 410
            } else if (action.equals("readinlinedata")) {
411
                handleReadInlineDataAction(params, response, username,
411
                handleReadInlineDataAction(params, request, response, username,
412 412
                        password, groupnames);
413 413
            } else if (action.equals("insert") || action.equals("update")) {
414 414
                PrintWriter out = response.getWriter();
415 415
                if ((username != null) && !username.equals("public")) {
416
                    handleInsertOrUpdateAction(out, params, username,
417
                            groupnames);
416
                    handleInsertOrUpdateAction(request, response,
417
                            out, params, username, groupnames);
418 418
                } else {
419 419
                    out.println("Permission denied for user " + username + " "
420 420
                            + action);
......
423 423
            } else if (action.equals("delete")) {
424 424
                PrintWriter out = response.getWriter();
425 425
                if ((username != null) && !username.equals("public")) {
426
                    handleDeleteAction(out, params, response, username,
426
                    handleDeleteAction(out, params, request, response, username,
427 427
                            groupnames);
428 428
                } else {
429 429
                    out.println("Permission denied for " + action);
......
695 695
     * @param user the username sent the request
696 696
     * @param groups the user's groupnames
697 697
     */
698
    private void handleExportAction(Hashtable params,
699
            HttpServletResponse response, String user, String[] groups,
700
            String passWord)
698
    private void handleExportAction(Hashtable params, 
699
            HttpServletResponse response, 
700
            String user, String[] groups, String passWord)
701 701
    {
702 702
        // Output stream
703 703
        ServletOutputStream out = null;
......
786 786
     * @param groups the user's groupnames
787 787
     */
788 788
    private void handleReadInlineDataAction(Hashtable params,
789
            HttpServletResponse response, String user, String passWord,
790
            String[] groups)
789
            HttpServletRequest request, HttpServletResponse response, 
790
            String user, String passWord, String[] groups)
791 791
    {
792 792
        String[] docs = new String[10];
793 793
        String inlineDataId = null;
......
816 816
                        + " doesn't have permission " + " to read document "
817 817
                        + docId);
818 818
            } else if (controller.hasSubTreeAccessControl()) {
819
                // if the document has subtree control, we need to check subtree
820
                // control
819
                // if the document has subtree control, we need to check 
820
                // subtree control
821 821
                // get node id for inlinedata
822 822
                long nodeId = getInlineDataNodeId(inlineDataId, docId);
823 823
                if (!controller.hasPermissionForSubTreeNode(user, groups,
824
                        AccessControlInterface.READSTRING, nodeId)) { throw new Exception(
825
                        "User " + user + " doesn't have permission "
826
                                + " to read inlinedata " + inlineDataId); }//if
827

  
824
                    AccessControlInterface.READSTRING, nodeId)) { 
825
                    throw new Exception(
826
                    "User " + user + " doesn't have permission "
827
                    + " to read inlinedata " + inlineDataId); 
828
                }
828 829
            }
829 830

  
830 831
            // Get output stream
......
841 842
            }
842 843
            out.close();
843 844

  
845
            EventLog.getInstance().log(request.getRemoteAddr(), user, 
846
                    inlineDataId, "readinlinedata");
844 847
        } catch (Exception e) {
845 848
            try {
846 849
                PrintWriter pw = null;
......
928 931
     * presentation if requested; zip files when more than one were requested.
929 932
     * 
930 933
     * @param params the Hashtable of HTTP request parameters
934
     * @param request the HTTP request object linked to the client
931 935
     * @param response the HTTP response object linked to the client
932 936
     * @param user the username sent the request
933 937
     * @param groups the user's groupnames
934 938
     */
935
    private void handleReadAction(Hashtable params,
939
    private void handleReadAction(Hashtable params, HttpServletRequest request,
936 940
            HttpServletResponse response, String user, String passWord,
937 941
            String[] groups)
938 942
    {
......
982 986
                        // get only docid, eliminate the rest
983 987
                        docid = (String) murlQueryStr.get("docid");
984 988
                        if (zip) {
985
                            addDocToZip(docid, zout, user, groups);
989
                            addDocToZip(request, docid, zout, user, groups);
986 990
                        } else {
987
                            readFromMetacat(response, docid, qformat,
991
                            readFromMetacat(request, response, docid, qformat,
988 992
                                    abstrpath, user, groups, zip, zout,
989 993
                                    withInlineData, params);
990 994
                        }
......
993 997
                    } else {
994 998
                        docid = docs[i];
995 999
                        if (zip) {
996
                            addDocToZip(docid, zout, user, groups);
1000
                            addDocToZip(request, docid, zout, user, groups);
997 1001
                        } else {
998 1002
                            readFromURLConnection(response, docid);
999 1003
                        }
1000 1004
                    }
1001 1005
                    
1002 1006
                } catch (MalformedURLException mue) {
1003
                    MetaCatUtil.debugMessage("MUE handleReadAction", 5);
1004 1007
                    docid = docs[i];
1005 1008
                    if (zip) {
1006
                        addDocToZip(docid, zout, user, groups);
1009
                        addDocToZip(request, docid, zout, user, groups);
1007 1010
                    } else {
1008
                        readFromMetacat(response, docid, qformat, abstrpath,
1009
                            user, groups, zip, zout, withInlineData, params);
1011
                        readFromMetacat(request, response, docid, qformat, 
1012
                                abstrpath, user, groups, zip, zout, 
1013
                                withInlineData, params);
1010 1014
                    }
1011 1015
                }
1012 1016
            }
......
1122 1126

  
1123 1127
    /** read metadata or data from Metacat 
1124 1128
     */
1125
    private void readFromMetacat(HttpServletResponse response, String docid,
1126
            String qformat, String abstrpath, String user, String[] groups,
1127
            boolean zip, ZipOutputStream zout, boolean withInlineData,
1128
            Hashtable params) throws ClassNotFoundException, IOException,
1129
            SQLException, McdbException, Exception
1129
    private void readFromMetacat(HttpServletRequest request, 
1130
            HttpServletResponse response, String docid, String qformat,
1131
            String abstrpath, String user, String[] groups, boolean zip,
1132
            ZipOutputStream zout, boolean withInlineData, Hashtable params)
1133
            throws ClassNotFoundException, IOException, SQLException,
1134
            McdbException, Exception
1130 1135
    {
1131 1136

  
1132 1137
        try {
......
1202 1207
                }
1203 1208

  
1204 1209
            }
1205
            EventLog.getInstance().log("192.168.1.103", "public", 
1210
            EventLog.getInstance().log(request.getRemoteAddr(), user, 
1206 1211
                    docid, "read");
1207 1212
        } catch (Exception except) {
1208 1213
            throw except;
......
1272 1277
     * @throws McdbException
1273 1278
     * @throws Exception
1274 1279
     */
1275
    private void addDocToZip(String docid, ZipOutputStream zout, String user,
1276
            String[] groups) throws ClassNotFoundException, IOException,
1277
            SQLException, McdbException, Exception
1280
    private void addDocToZip(HttpServletRequest request, String docid, 
1281
            ZipOutputStream zout, String user, String[] groups) throws
1282
            ClassNotFoundException, IOException, SQLException, McdbException,
1283
            Exception
1278 1284
    {
1279 1285
        byte[] bytestring = null;
1280 1286
        ZipEntry zentry = null;
......
1347 1353
                    zout.write(bytestring, 0, bytestring.length);
1348 1354
                    zout.closeEntry();
1349 1355
                }
1350
                EventLog.getInstance().log("192.168.1.103", "public", 
1356
                EventLog.getInstance().log(request.getRemoteAddr(), user, 
1351 1357
                        docid, "read");
1352 1358
            } catch (Exception except) {
1353 1359
                throw except;
......
1390 1396
     * Handle the database putdocument request and write an XML document to the
1391 1397
     * database connection
1392 1398
     */
1393
    private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params,
1399
    private void handleInsertOrUpdateAction(HttpServletRequest request,
1400
            HttpServletResponse response, PrintWriter out, Hashtable params,
1394 1401
            String user, String[] groups)
1395 1402
    {
1396 1403
        DBConnection dbConn = null;
......
1469 1476
                                + accNumber + "...", 10);
1470 1477
                        if (accNumber.equals("")) {
1471 1478
                            accNumber = null;
1472
                        }//if
1479
                        }
1473 1480
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
1474 1481
                                doAction, accNumber, user, groups);
1475

  
1476
                    }//try
1477
                    catch (NullPointerException npe) {
1482
                        EventLog.getInstance().log(request.getRemoteAddr(), 
1483
                                user, accNumber, action[0]);
1484
                    } catch (NullPointerException npe) {
1478 1485
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
1479 1486
                                doAction, null, user, groups);
1480
                    }//catch
1481

  
1482
                }//try
1487
                        EventLog.getInstance().log(request.getRemoteAddr(), 
1488
                                user, "", action[0]);
1489
                    }
1490
                }
1483 1491
                finally {
1484 1492
                    // Return db connection
1485 1493
                    DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
1700 1708
     * database connection
1701 1709
     */
1702 1710
    private void handleDeleteAction(PrintWriter out, Hashtable params,
1703
            HttpServletResponse response, String user, String[] groups)
1711
            HttpServletRequest request, HttpServletResponse response, 
1712
            String user, String[] groups)
1704 1713
    {
1705 1714

  
1706 1715
        String[] docid = (String[]) params.get("docid");
......
1713 1722
            // BEFORE ACCESSING ARRAY
1714 1723
            try {
1715 1724
                DocumentImpl.delete(docid[0], user, groups);
1725
                EventLog.getInstance().log(request.getRemoteAddr(), 
1726
                    user, docid[0], "delete");
1716 1727
                response.setContentType("text/xml");
1717 1728
                out.println("<?xml version=\"1.0\"?>");
1718 1729
                out.println("<success>");
......
2148 2159
                        File newFile = new File(dataDirectory, docid);
2149 2160
                        long size = filePart.writeTo(newFile);
2150 2161

  
2162
                        EventLog.getInstance().log(request.getRemoteAddr(), 
2163
                                username, docid, "upload");
2151 2164
                        // Force replication this data file
2152 2165
                        // To data file, "insert" and update is same
2153 2166
                        // The fourth parameter is null. Because it is

Also available in: Unified diff