Project

General

Profile

« Previous | Next » 

Revision 2165

Added by Jing Tao over 20 years ago

fixed the bug that couldn't assign access rule for the data file come with morpho.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
49 49

  
50 50
    private static boolean debug = true;
51 51

  
52

  
52 53
    /**
53 54
     * Determine our db adapter class and create an instance of that class
54 55
     */
......
63 64

  
64 65
    /**
65 66
     * Instantiate a class using the name of the class at runtime
66
     * 
67
     *
67 68
     * @param className the fully qualified name of the class to instantiate
68 69
     */
69 70
    public static Object createObject(String className) throws Exception
......
85 86

  
86 87
    /**
87 88
     * Utility method to get an option value from the properties file
88
     * 
89
     *
89 90
     * @param optionName the name of the option requested
90 91
     * @return the String value for the option, or null if not set
91 92
     */
......
192 193
    /**
193 194
     * Utility method to print debugging messages. User can set debug level for
194 195
     * this message. The number is fewer, the message is more important
195
     * 
196
     *
196 197
     * @param msg, the content of the message
197 198
     * @param debugLevel, an integer indicating the message debug leve
198 199
     */
......
338 339
        return docid.trim();
339 340
    }
340 341

  
342

  
343
    /**
344
     * Eocgorid identifier will look like: ecogrid://knb/tao.1.1
345
     * The AccessionNumber tao.1.1 will be returned. If the given doesn't
346
     * contains ecogrid, null will be returned.
347
     * @param identifier String
348
     * @return String
349
     */
350
    public static String getAccessionNumberFromEcogridIdentifier(String identifier)
351
    {
352
      String accessionNumber = null;
353
      if (identifier != null && identifier.startsWith(DBSAXHandler.ECOGRID))
354
      {
355
        // find the last "/" in identifier
356
        int indexOfLastSlash = identifier.lastIndexOf("/");
357
        int start = indexOfLastSlash+1;
358
        int end   = identifier.length();
359
        accessionNumber = identifier.substring(start, end);
360
      }
361
      MetaCatUtil.debugMessage("The accession number from url is " +
362
                                 accessionNumber, 10);
363
      return accessionNumber;
364
    }
365

  
341 366
    private static int getIndexForGivenChar(String str, char character)
342 367
    {
343 368
        int index = -1;
......
362 387

  
363 388
    /**
364 389
     * Utility method to get docid from a given string
365
     * 
390
     *
366 391
     * @param string, the given string should be these two format: 1) str1.str2
367 392
     *            in this case docid= str1.str2 2) str1.str2.str3, in this case
368 393
     *            docid =str1.str2
......
408 433

  
409 434
    /**
410 435
     * Utility method to get version number from a given string
411
     * 
436
     *
412 437
     * @param string, the given string should be these two format: 1)
413 438
     *            str1.str2(no version) version =-1; 2) str1.str2.str3, in this
414 439
     *            case version = str3; 3) other, vresion =-2
......
451 476

  
452 477
    /**
453 478
     * Utility method to get version string from a given string
454
     * 
479
     *
455 480
     * @param string, the given string should be these two format: 1)
456 481
     *            str1.str2(no version) version=null; 2) str1.str2.str3, in
457 482
     *            this case version = str3; 3) other, vresion =null;
......
515 540
     * will be str1.str2. If the string is str1.str2.str3.str4 or more, the
516 541
     * docid will be str1.str2.str3. If the string look like str1, null will be
517 542
     * returned
518
     *  
543
     *
519 544
     */
520 545
    public static String getSmartDocId(String str)
521 546
    {
src/edu/ucsb/nceas/metacat/DBSAXHandler.java
126 126

  
127 127
    boolean hasTriple = false;
128 128

  
129
    public static final String ECOGRID = "ecogrid://";
130

  
129 131
    /**
130 132
     * Construct an instance of the handler class
131
     * 
133
     *
132 134
     * @param conn the JDBC connection to which information is written
133 135
     */
134 136
    private DBSAXHandler(DBConnection conn)
......
148 150

  
149 151
    /**
150 152
     * Construct an instance of the handler class
151
     * 
153
     *
152 154
     * @param conn the JDBC connection to which information is written
153 155
     * @param action - "INSERT" or "UPDATE"
154 156
     * @param docid to be inserted or updated into JDBC connection
......
157 159
     * @param pub flag for public "read" access on document
158 160
     * @param serverCode the serverid from xml_replication on which this
159 161
     *            document resides.
160
     *  
162
     *
161 163
     */
162
/* TODO excise this constructor because not used anywhere in project 
164
/* TODO excise this constructor because not used anywhere in project
163 165
    public DBSAXHandler(DBConnection conn, String action, String docid,
164 166
            String user, String[] groups, String pub, int serverCode)
165 167
    {
......
176 178
    /**
177 179
     * Construct an instance of the handler class In this constructor, user can
178 180
     * specify the version need to upadate
179
     * 
181
     *
180 182
     * @param conn the JDBC connection to which information is written
181 183
     * @param action - "INSERT" or "UPDATE"
182 184
     * @param docid to be inserted or updated into JDBC connection
......
186 188
     * @param pub flag for public "read" access on document
187 189
     * @param serverCode the serverid from xml_replication on which this
188 190
     *            document resides.
189
     *  
191
     *
190 192
     */
191 193
    public DBSAXHandler(DBConnection conn, String action, String docid,
192 194
            String revision, String user, String[] groups, String pub,
......
240 242
                                + e.getMessage());
241 243
            }
242 244
        }
243
        boolean useXMLIndex = 
245
        boolean useXMLIndex =
244 246
            (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
245 247
        if (useXMLIndex) {
246 248
            try {
......
250 252
                throw new SAXException(
251 253
                        "Problem with starting thread for writing XML Index. "
252 254
                                + e.getMessage());
253
            }   
255
            }
254 256
        }
255 257
    }
256 258

  
......
483 485
                    .getDBConnection("DBSAXHandler.checkDocumentTable");
484 486
            serialNumber = dbConn.getCheckOutSerialNumber();
485 487

  
486
            // the following while loop construct checks to make sure that 
487
            // the docid of the document that we are trying to index is already 
488
            // in the xml_documents table. if this is not the case, the foreign 
489
            // key relationship between xml_documents and xml_index is 
488
            // the following while loop construct checks to make sure that
489
            // the docid of the document that we are trying to index is already
490
            // in the xml_documents table. if this is not the case, the foreign
491
            // key relationship between xml_documents and xml_index is
490 492
            // temporarily broken causing multiple problems.
491 493
            boolean inxmldoc = false;
492 494
            long startTime = System.currentTimeMillis();
src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java
114 114
    private Stack storedAccessNodeStack = new Stack();
115 115

  
116 116
    // vector stored the data file id which will be write into relation table
117
    private Vector onlineDataFileIdVector = new Vector();
117
    private Vector onlineDataFileIdInRelationVector = new Vector();
118 118

  
119
    // vector stored the data file id which will be write top access rules to
120
   // access table
121
    private Vector onlineDataFileIdInTopAccessVector = new Vector();
122

  
119 123
    // Indicator of inline data
120 124
    private boolean handleInlineData = false;
121 125

  
......
131 135

  
132 136
    private Vector inlineFileIDList = new Vector();
133 137

  
138

  
134 139
    // Constant
135 140
    private static final String EML = "eml";
136 141

  
......
1010 1015
                        // if online data is in local metacat, add it to the
1011 1016
                        // vector
1012 1017
                        data = (textBuffer.toString()).trim();
1013
                        if (data != null
1018
                        handleOnlineUrlDataFile(data);
1019
                        /*if (data != null
1014 1020
                                && (data.indexOf(MetaCatUtil
1015 1021
                                        .getOption("httpserver")) != -1 || data
1016 1022
                                        .indexOf(MetaCatUtil
......
1020 1026
                                    .getDocIdWithRevFromOnlineURL(data);
1021 1027
                            // add to vector
1022 1028
                            onlineDataFileIdVector.add(dataId);
1023
                        }//if
1029
                        }//if*/
1024 1030
                    }//if
1025 1031
                }//else if
1026 1032
                // write text to db if it is not inline data
......
1409 1415
        //delete relation table
1410 1416
        deleteRelations();
1411 1417
        //write relations
1412
        for (int i = 0; i < onlineDataFileIdVector.size(); i++) {
1413
            String id = (String) onlineDataFileIdVector.elementAt(i);
1418
        for (int i = 0; i < onlineDataFileIdInRelationVector.size(); i++) {
1419
            String id = (String) onlineDataFileIdInRelationVector.elementAt(i);
1414 1420
            writeOnlineDataFileIdIntoRelationTable(id);
1415 1421
        }
1416 1422

  
......
1463 1469

  
1464 1470
                //write access section into xml_access table
1465 1471
                writeGivenAccessRuleIntoDB(accessSectionObj, top, subSectionId);
1466
                // write relative online data file into xml_access too.
1467
                /*
1468
                 * for (int i= 0; i <onlineDataFileIdVector.size(); i++) {
1469
                 * String id = (String)onlineDataFileIdVector.elementAt(i);
1470
                 * writeAccessRuleForRalatedDataFileIntoDB(accessSectionObj,
1471
                 * id);
1472
                 */
1472
                // write online data file into xml_access too.
1473
                for (int i= 0; i <onlineDataFileIdInTopAccessVector.size(); i++)
1474
                {
1475
                  String id = (String)
1476
                               onlineDataFileIdInTopAccessVector.elementAt(i);
1477
                  writeAccessRuleForRalatedDataFileIntoDB(accessSectionObj, id);
1478
                }
1473 1479

  
1480

  
1474 1481
            } else {
1475 1482

  
1476 1483
                // this is a reference and go trough the vector which contains
......
1512 1519
                        }//if
1513 1520
                        // write accessobject into db
1514 1521
                        writeGivenAccessRuleIntoDB(accessObj, top, subSectionId);
1515
                        // add access rule for related on line data id too.
1516
                        /*
1517
                         * for (int j= 0; j <onlineDataFileIdVector.size();
1518
                         * j++) { String id =
1519
                         * (String)onlineDataFileIdVector.elementAt(j);
1520
                         * writeAccessRuleForRalatedDataFileIntoDB(accessObj,
1521
                         * id);
1522
                         */
1522
                        // write online data file into xml_access too.
1523
                        for (int j= 0; j <onlineDataFileIdInTopAccessVector.size(); j++)
1524
                        {
1525
                          String id = (String)
1526
                              onlineDataFileIdInTopAccessVector.elementAt(j);
1527
                           writeAccessRuleForRalatedDataFileIntoDB(accessSectionObj, id);
1528
                        }
1523 1529

  
1524 1530
                        //write the reference access into xml_accesssubtree
1525 1531
                        // too
......
1806 1812
        if (accessSection == null) { throw new SAXException(
1807 1813
                "The access object is null"); }
1808 1814
        // get rid of rev from dataId
1809
        dataId = MetaCatUtil.getDocIdFromString(dataId);
1815
        //dataId = MetaCatUtil.getDocIdFromString(dataId);
1810 1816
        String permOrder = accessSection.getPermissionOrder();
1811 1817
        String sql = null;
1812 1818
        PreparedStatement pstmt = null;
......
2132 2138
        }//finally
2133 2139
    }
2134 2140

  
2135
    /* Write an online data file id into xml_relation table */
2141
    /* Write an online data file id into xml_relation table. The dataId shouldnot
2142
     * have the revision
2143
     */
2136 2144
    private void writeOnlineDataFileIdIntoRelationTable(String dataId)
2137 2145
            throws SAXException
2138 2146
    {
2139
        // Get rid of rev
2140
        dataId = MetaCatUtil.getDocIdFromString(dataId);
2141 2147
        PreparedStatement pStmt = null;
2142 2148
        String sql = "INSERT into xml_relation (docid, packagetype, subject, "
2143 2149
                + "relationship, object) values (?, ?, ?, ?, ?)";
......
2171 2177

  
2172 2178
    }//writeOnlineDataFileIdIntoRelationTable
2173 2179

  
2180
    /*
2181
     * This method will handle data file in online url. If the data file is in
2182
     * ecogrid protocol, then the datafile identifier(without rev)should be put
2183
     * into onlineDataFileRelationVector. The  docid in this vector will be
2184
     * insert into xml_relation table in endDocument().
2185
     * If the data file doesn't exsit in xml_documents or
2186
     * xml_revision table, or the user has all permission to the data file if
2187
     * the docid already existed, the data file id (without rev)will be put into
2188
     * onlineDataFileTopAccessVector. The top access rules specified in this eml
2189
     * document will apply to the data file.
2190
     * NEED to do:
2191
     * We should also need to implement http and ftp. Those
2192
     * external files should be download and assign a data file id to it.
2193
     */
2194
    private void handleOnlineUrlDataFile(String url) throws SAXException
2195
    {
2196
      MetaCatUtil.debugMessage("The url is "+ url, 10);
2197
      // if the url is not a ecogrid protocol, null will be getten
2198
      String accessionNumber =
2199
                 MetaCatUtil.getAccessionNumberFromEcogridIdentifier(url);
2200
      if (accessionNumber != null)
2201
      {
2202
        // handle ecogrid protocol
2203
        // get rid of revision number to get the docid.
2204
        String docid = MetaCatUtil.getDocIdFromAccessionNumber(accessionNumber);
2205
        onlineDataFileIdInRelationVector.add(docid);
2206
        try
2207
        {
2208

  
2209
          if (!AccessionNumber.accNumberUsed(docid))
2210
          {
2211
            onlineDataFileIdInTopAccessVector.add(docid);
2212
          }
2213
          PermissionController controller = new
2214
              PermissionController(accessionNumber);
2215
          if (controller.hasPermission(
2216
              user, groups, AccessControlInterface.ALLSTRING))
2217
          {
2218
            onlineDataFileIdInTopAccessVector.add(docid);
2219
          }
2220
        }//try
2221
        catch(Exception e)
2222
        {
2223
          MetaCatUtil.debugMessage("Eorr in " +
2224
                                "Eml200SAXHanlder.handleOnlineUrlDataFile is " +
2225
                                 e.getMessage(), 30);
2226
          throw new SAXException(e.getMessage());
2227
        }
2228
      }
2229
    }
2230

  
2174 2231
}

Also available in: Unified diff