Project

General

Profile

« Previous | Next » 

Revision 2253

Added by sgarg over 20 years ago

Fixed handling of various docid formats.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1832 1832
                    response.setContentType("text/xml");
1833 1833
                    out.println("<?xml version=\"1.0\"?>");
1834 1834
                    out.println("<error>");
1835
                    out.println("Error deleting document!!!");
1835
                    //out.println("Error deleting document!!!");
1836 1836
                    out.println(ane.getMessage());
1837 1837
                    out.println("</error>");
1838 1838
                }
src/edu/ucsb/nceas/metacat/DocumentImpl.java
127 127
     * from the database. If readNodes is false, then the node data is not read
128 128
     * at this time, but is deferred until it is needed (such as when a call to
129 129
     * toXml() is made).
130
     * 
130
     *
131 131
     * @param conn
132 132
     *            the database connection from which to read the document
133 133
     * @param docid
......
156 156
        } catch (McdbException ex) {
157 157
            throw ex;
158 158
        } catch (Throwable t) {
159
            throw new McdbException("Error reading document from "
160
                    + "DocumentImpl.DocumentImpl: " + docid);
159
            throw new McdbException("Error reading document: " + docid);
161 160
        }
162 161
    }
163 162

  
164 163
    /**
165 164
     * Constructor, creates document from database connection, used for reading
166 165
     * the document
167
     * 
166
     *
168 167
     * @param conn
169 168
     *            the database connection from which to read the document
170 169
     * @param docid
......
179 178
     * Construct a new document instance, writing the contents to the database.
180 179
     * This method is called from DBSAXHandler because we need to know the root
181 180
     * element name for documents without a DOCTYPE before creating it.
182
     * 
181
     *
183 182
     * In this constructor, the docid is without rev. There is a string rev to
184 183
     * specify the revision user want to upadate. The revion is only need to be
185 184
     * greater than current one. It is not need to be sequent number just after
186 185
     * current one. So it is only used in update action
187
     * 
186
     *
188 187
     * @param conn
189 188
     *            the JDBC Connection to which all information is written
190 189
     * @param rootnodeid -
......
212 211
     * @param serverCode
213 212
     *            the serverid from xml_replication on which this document
214 213
     *            resides.
215
     *  
214
     *
216 215
     */
217 216
    public DocumentImpl(DBConnection conn, long rootNodeId, String docName,
218 217
            String docType, String docId, String newRevision, String action,
......
249 248
     * (ie, just an entry in xml_documents, nothing in xml_nodes). Creates a
250 249
     * reference to a filesystem document (used for non-xml data files). This
251 250
     * class only be called in MetaCatServerlet.
252
     * 
251
     *
253 252
     * @param conn
254 253
     *            the JDBC Connection to which all information is written
255 254
     * @param docname -
......
376 375
     * reference to a filesystem document (used for non-xml data files) This
377 376
     * method will be called for register data file in xml_documents in
378 377
     * Replication. This method is revised from registerDocument.
379
     * 
378
     *
380 379
     * @param conn
381 380
     *            the JDBC Connection to which all information is written
382 381
     * @param docname -
......
465 464
            if (action != null && action.equals("insert")) {
466 465
                sql.append("insert into xml_documents (docid, docname, " +
467 466
                           "doctype, ");
468
                sql.append("user_owner, user_updated, server_location, " + 
467
                sql.append("user_owner, user_updated, server_location, " +
469 468
                           "rev,date_created");
470 469
                sql.append(", date_updated, public_access) values ('");
471 470
                sql.append(docid).append("','");
......
512 511
    /**
513 512
     * This method will register a data file entry in xml_documents and save a
514 513
     * data file input Stream into file system.. It is only used in replication
515
     * 
514
     *
516 515
     * @param input,
517 516
     *            the input stream which contain the file content.
518 517
     * @param ,
......
599 598
     * The method will check if metacat can get data file lock grant If server
600 599
     * code is 1, it get. If server code is not 1 but call replication getlock
601 600
     * successfully, it get else, it didn't get
602
     * 
601
     *
603 602
     * @param accnum,
604 603
     *            the ID of the document
605 604
     * @param action,
......
843 842

  
844 843
    /**
845 844
     * Print a text representation of the XML document to a Writer
846
     * 
845
     *
847 846
     * @param pw
848 847
     *            the Writer to which we print the document Now we decide no
849 848
     *            matter withinInlineData's value, the document will
850
     *  
849
     *
851 850
     */
852 851
    public void toXml(Writer pw, String user, String[] groups,
853 852
            boolean withInLineData) throws McdbException
......
885 884
         * PermissionController control = new PermissionController(docid);
886 885
         * Hashtable unaccessableSubTree =control.hasUnaccessableSubTree(user,
887 886
         * groups, AccessControlInterface.READSTRING);
888
         * 
887
         *
889 888
         * if (!unaccessableSubTree.isEmpty()) {
890
         * 
889
         *
891 890
         * nodeRecordLists = getPartNodeRecordList(rootnodeid,
892 891
         * unaccessableSubTree);
893 892
         *  } else { nodeRecordLists = getNodeRecordList(rootnodeid); }
......
1027 1026
                    // check if user has read permision for this inline data
1028 1027
                    boolean readInlinedata = false;
1029 1028
                    try {
1030
                        Hashtable unReadableInlineDataList = 
1029
                        Hashtable unReadableInlineDataList =
1031 1030
                            PermissionController
1032 1031
                                .getUnReadableInlineDataIdList(accessfileName,
1033 1032
                                        user, groups);
......
1202 1201

  
1203 1202
    /**
1204 1203
     * Look up the document type information from the database
1205
     * 
1204
     *
1206 1205
     * @param docid
1207 1206
     *            the id of the document to look up
1208 1207
     */
......
1319 1318
            }
1320 1319
        }
1321 1320

  
1322
        if (this.docname == null) { 
1321
        if (this.docname == null) {
1323 1322
            throw new McdbDocNotFoundException(
1324 1323
                "Document not found: " + docid, docid.getIdentifier(), docid
1325
                        .getRev()); 
1324
                        .getRev());
1326 1325
        }
1327 1326
    }
1328 1327

  
1329 1328
    /**
1330 1329
     * Look up the node data from the database, but some node would be shown
1331 1330
     * because of access control
1332
     * 
1331
     *
1333 1332
     * @param rootnodeid
1334 1333
     *            the id of the root node of the node tree to look up
1335 1334
     * @param accessControl
......
1424 1423

  
1425 1424
    /**
1426 1425
     * Look up the node data from the database
1427
     * 
1426
     *
1428 1427
     * @param rootnodeid
1429 1428
     *            the id of the root node of the node tree to look up
1430 1429
     */
......
1624 1623

  
1625 1624
    /**
1626 1625
     * Write an XML file to the database, given a filename
1627
     * 
1626
     *
1628 1627
     * @param conn
1629 1628
     *            the JDBC connection to the database
1630 1629
     * @param filename
......
1646 1645
     * public static String write(DBConnection conn,String filename, String pub,
1647 1646
     * String dtdfilename, String action, String docid, String user, String[]
1648 1647
     * groups ) throws Exception {
1649
     * 
1648
     *
1650 1649
     * Reader dtd = null; if ( dtdfilename != null ) { dtd = new FileReader(new
1651 1650
     * File(dtdfilename).toString()); } return write ( conn, new FileReader(new
1652 1651
     * File(filename).toString()), pub, dtd, action, docid, user, groups,
......
1668 1667

  
1669 1668
    /**
1670 1669
     * Write an XML file to the database, given a Reader
1671
     * 
1670
     *
1672 1671
     * @param conn
1673 1672
     *            the JDBC connection to the database
1674 1673
     * @param xml
......
1711 1710
        MetaCatUtil.debugMessage("action: " + action + " servercode: "
1712 1711
                + serverCode + " override: " + override, 10);
1713 1712

  
1714
        if ((serverCode != 1 && action.equals("UPDATE")) && !override) { 
1713
        if ((serverCode != 1 && action.equals("UPDATE")) && !override) {
1715 1714
            // if this document being written is not a resident of this server
1716 1715
            // then we need to try to get a lock from it's resident server. If
1717 1716
            // the resident server will not give a lock then we send the user
......
1721 1720
            char istreamChar;
1722 1721

  
1723 1722
            // check for 'write' permission for 'user' to update this document
1724
            if (!hasWritePermission(user, groups, accnum)) { 
1723
            if (!hasWritePermission(user, groups, accnum)) {
1725 1724
                throw new Exception(
1726 1725
                    "User " + user
1727 1726
                    + " does not have permission to update XML Document #"
1728
                    + accnum); 
1727
                    + accnum);
1729 1728
            }
1730 1729

  
1731 1730
            DocumentIdentifier id = new DocumentIdentifier(accnum);
......
1785 1784

  
1786 1785
            else if (openingtag.equals("<filelocked>")) {
1787 1786
                // the file is currently locked by another user notify our
1788
                // user to wait a few minutes, check out a new copy and try 
1787
                // user to wait a few minutes, check out a new copy and try
1789 1788
                // again.
1790 1789
                MetacatReplication.replLog("lock denied for " + accnum + " on "
1791 1790
                        + server + " reason: file already locked");
......
1809 1808

  
1810 1809
        if (action.equals("UPDATE")) {
1811 1810
            // check for 'write' permission for 'user' to update this document
1812
            if (!hasWritePermission(user, groups, accnum)) { 
1811
            if (!hasWritePermission(user, groups, accnum)) {
1813 1812
                throw new Exception(
1814 1813
                    "User " + user
1815 1814
                    + " does not have permission to update XML Document #"
......
1842 1841
        runRelationAndAccessHandler(accnum, user, groups, serverCode);
1843 1842

  
1844 1843
        // Force replicate out the new document to each server in our server
1845
        // list. Start the thread to replicate this new document out to the 
1846
        // other servers true mean it is xml document null is because no 
1844
        // list. Start the thread to replicate this new document out to the
1845
        // other servers true mean it is xml document null is because no
1847 1846
        // metacat notify the force replication.
1848 1847
        ForceReplicationHandler frh = new ForceReplicationHandler(accnum,
1849 1848
                action, true, null);
......
1855 1854

  
1856 1855
    /**
1857 1856
     * Write an XML file to the database during replication
1858
     * 
1857
     *
1859 1858
     * @param conn
1860 1859
     *            the JDBC connection to the database
1861 1860
     * @param xml
......
1996 1995
            Vector packagedoctypes = new Vector();
1997 1996
            packagedoctypes = MetaCatUtil.getOptionList(packagedoctype);
1998 1997
            String docIdWithoutRev = MetaCatUtil.getDocIdFromString(accnumber);
1999
            if (documenttype != null && 
1998
            if (documenttype != null &&
2000 1999
                    packagedoctypes.contains(documenttype)) {
2001 2000
                dbconn = DBConnectionPool.getDBConnection(
2002 2001
                        "DocumentImpl.runRelationAndAccessHandeler");
......
2104 2103
    /**
2105 2104
     * Delete an XML file from the database (actually, just make it a revision
2106 2105
     * in the xml_revisions table)
2107
     * 
2106
     *
2108 2107
     * @param docid
2109 2108
     *            the ID of the document to be deleted from the database
2110 2109
     */
......
2353 2352
                    parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
2354 2353
                    // From DB to find the register external schema location
2355 2354
                    String externalSchemaLocation = null;
2356
                    SchemaLocationResolver resolver = 
2355
                    SchemaLocationResolver resolver =
2357 2356
                        new SchemaLocationResolver();
2358 2357
                    externalSchemaLocation = resolver
2359 2358
                            .getNameSpaceAndLocationString();
......
2494 2493

  
2495 2494
    /**
2496 2495
     * delete a entry in xml_table for given docid
2497
     * 
2496
     *
2498 2497
     * @param docId,
2499 2498
     *            the id of the document need to be delete
2500 2499
     */
......
2530 2529
     * Get last revision number from database for a docid If couldn't find an
2531 2530
     * entry, -1 will return The return value is integer because we want compare
2532 2531
     * it to there new one
2533
     * 
2532
     *
2534 2533
     * @param docid
2535 2534
     *            <sitecode>. <uniqueid>part of Accession Number
2536 2535
     */
......
2579 2578

  
2580 2579
    /**
2581 2580
     * Get server location form database for a accNum
2582
     * 
2581
     *
2583 2582
     * @param accum
2584 2583
     *            <sitecode>. <uniqueid>. <rev>
2585 2584
     */
......
2638 2637
    /**
2639 2638
     * Given a server name, return its servercode in xml_replication table. If
2640 2639
     * no server is found, -1 will return
2641
     * 
2640
     *
2642 2641
     * @param serverName,
2643 2642
     */
2644 2643
    private static int getServerCode(String serverName)
......
2698 2697

  
2699 2698
    /**
2700 2699
     * Insert a server into xml_replcation table
2701
     * 
2700
     *
2702 2701
     * @param server,
2703 2702
     *            the name of server
2704 2703
     */
......
2791 2790
     * the main routine used to test the DBWriter utility.
2792 2791
     * <p>
2793 2792
     * Usage: java DocumentImpl <-f filename -a action -d docid>
2794
     * 
2793
     *
2795 2794
     * @param filename
2796 2795
     *            the filename to be loaded into the database
2797 2796
     * @param action
src/edu/ucsb/nceas/metacat/AccessionNumber.java
99 99
    // INSERT
100 100
    if ( action.equals("INSERT")) {
101 101

  
102
        if(rev != null){
103
            try {
104
                Integer.parseInt(rev);
105
            }
106
            catch (java.lang.NumberFormatException e) {
107
                throw new AccessionNumberException(
108
                    "Revision number is required");
109
            }
110
        }
111

  
102 112
      // check accession number for validness
103 113
      if ( docid == null ) {
104
        throw new AccessionNumberException("Accession number is required.");
114
        throw new AccessionNumberException("Accession number is required");
105 115

  
106 116
      // rev is not provided; throw an exception to prevent the insertion
107 117
      } else if ( rev == null ) {
108 118
        throw new AccessionNumberException
109
                  ("Revision number is required and must be 1.");
119
                  ("Revision number is required");
110 120

  
111 121
      // docid is used; throw an exception to prevent the insertion
112 122
      } else if ( accNumberUsed(docid) ) {
113 123
        throw new AccessionNumberException
114
                  ("Accession number " + docid + " is already in use.");
124
                  ("Accession number " + docid + " is already in use");
115 125

  
116 126
      // rev is <> 1; throw an exception to prevent the insertion
117 127
      } /*else if ( !rev.equals("1")) {
118
        throw new AccessionNumberException("Revision number must be 1.");
128
        throw new AccessionNumberException("Revision number must be 1");
119 129
      }*/
120 130

  
121 131
    // UPDATE or DELETE
......
125 135
      int reversionNumber = 1;
126 136

  
127 137
      if(rev != null){
128
        reversionNumber = Integer.parseInt(rev);
138
          try{
139
              reversionNumber = Integer.parseInt(rev);
140
          } catch (java.lang.NumberFormatException e){
141
              throw new AccessionNumberException(
142
                      "Revision number is required");
143
          }
129 144
      }
130 145

  
131 146
      // Accession# is not provided; throw an exception to prevent the action
132 147
      if ( docid == null ) {
133
        throw new AccessionNumberException("Accession number is required.");
148
        throw new AccessionNumberException("Accession number is required");
134 149

  
135 150
      // rev is not provided; throw an exception to prevent the action
136 151
      } else if ( rev == null ) {
137 152
        throw new AccessionNumberException
138
                  ("Revision number is required.");
153
                  ("Revision number is required");
139 154

  
140 155
      // Accession# is not current (not in xml_documents); throw an exception
141 156
      } else if ( !accNumberIsCurrent(docid) ) {
......
195 210
        // docid is used; throw an exception to prevent the insertion
196 211
        } else if ( accNumberUsed(docid) ) {
197 212
          throw new AccessionNumberException
198
                    ("Accession number " + docid + " is already in use.");
213
                    ("Accession number " + docid + " is already in use");
199 214
        // rev is <> 1; throw an exception to prevent the insertion
200 215
        } else if ( !rev.equals("1") ) {
201 216
          throw new AccessionNumberException
202
                    ("Revision number must be 1.");
217
                    ("Revision number must be 1");
203 218
        // docid is not used and rev=1; return it
204 219
        } else {
205 220
          return docid;
......
210 225

  
211 226
        // Accession# is not provided; throw an exception to prevent the action
212 227
        if ( docid == null ) {
213
          throw new AccessionNumberException("Accession number is required.");
228
          throw new AccessionNumberException("Accession number is required");
214 229

  
215 230
        // Accession# is not current (not in xml_documents); throw an exception
216 231
        } else if ( !accNumberIsCurrent(docid) ) {
......
220 235
        // Revision number is not the recent one; throw an exception
221 236
        } else if ( !rev.equals(getLastRevision(docid)) ) {
222 237
          throw new AccessionNumberException
223
          ("Revision number must be the recent.");
238
          ("Revision number must be the recent");
224 239

  
225 240
        // Accession# is current (present in xml_documents); return it
226 241
        } else {
......
235 250

  
236 251
    // never comes here
237 252
    throw new
238
    AccessionNumberException("Fatal Error in accession number generation.");
253
    AccessionNumberException("Fatal Error in accession number generation");
239 254
  }
240 255

  
241 256
  // get local sitecode

Also available in: Unified diff