Project

General

Profile

« Previous | Next » 

Revision 5333

Added by berkley over 14 years ago

adding a system to track system metadata documents for dataone

View differences:

src/xmltables-postgres.sql
283 283
);
284 284

  
285 285
/*
286
 * Table used to store all document identifiers for system metadata objects
287
 * similar restraints to identifier.  Cannot use identifier table for this 
288
 * purpose because then you have to worry about whether you insert the
289
 * data first or the systemMetadata first.
290
 */
291
CREATE TABLE systemMetadata (
292
   guid   text,          -- the globally unique string identifier
293
   docid  VARCHAR(250),	 -- the local document id #
294
   rev    INT8,          -- the revision part of the local identifier
295
   CONSTRAINT systemMetadata_pk PRIMARY KEY (guid)
296
);
297

  
298
/*
286 299
 * accesssubtree -- table to store access subtree info
287 300
 */
288 301
CREATE TABLE xml_accesssubtree (
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
483 483
     * @param guid ID of data object to be read
484 484
     */
485 485
    private void getObject(String guid) {
486
      //hack...fix this
486 487
        CrudService cs = new CrudService(servletContext, request, response);
487 488
        AuthToken token = null;
488 489
        OutputStream out = null;
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
106 106
     */
107 107
    public CrudService(ServletContext servletContext,
108 108
            HttpServletRequest request, HttpServletResponse response) {
109
    //change crud service into a singleton.  dont pass servlet data structures here
110
    
109 111
        this.servletContext = servletContext;
110 112
        this.request = request;
111 113
        this.response = response;
......
491 493
    private void insertSystemMetadata(SystemMetadata sysmeta, SessionData sessionData) 
492 494
        throws ServiceFailure {
493 495
        logMetacat.debug("Starting to insert SystemMetadata...");
494
        IdentifierManager im = IdentifierManager.getInstance();
495 496
    
496 497
        // generate guid/localId pair for sysmeta
497 498
        Identifier sysMetaGuid = new Identifier();
......
499 500
        sysmeta.setDateSysMetadataModified(new Date());
500 501

  
501 502
        String xml = new String(serializeSystemMetadata(sysmeta).toByteArray());
502
        insertDocument(xml, sysMetaGuid, sessionData);
503
        String localId = insertDocument(xml, sysMetaGuid, sessionData);
504
        //insert the system metadata doc id into the identifiers table to 
505
        //link it to the data or metadata document
506
        IdentifierManager.getInstance().createSystemMetadataMapping(sysMetaGuid.getValue(), localId);
503 507
    }
504 508
    
505
    private void insertDocument(String xml, Identifier guid, SessionData sessionData) 
509
    /**
510
     * insert a document, return the id of the document that was inserted
511
     */
512
    private String insertDocument(String xml, Identifier guid, SessionData sessionData) 
506 513
        throws ServiceFailure {
507 514
        logMetacat.debug("Starting to insert xml document...");
508 515
        IdentifierManager im = IdentifierManager.getInstance();
......
536 543
//        if (!(outputS.indexOf("<success>") > 0 && outputS.indexOf(localId) > 0)) {
537 544
//            throw new ServiceFailure(1190, outputS);
538 545
//        }
539
        logMetacat.debug("Finsished inserting xml document.");
546
        logMetacat.debug("Finsished inserting xml document with id " + localId);
547
        return localId;
540 548
    }
541 549
    
542 550
    public static ByteArrayOutputStream serializeSystemMetadata(SystemMetadata sysmeta) 
src/edu/ucsb/nceas/metacat/IdentifierManager.java
277 277
        
278 278
        return guid;
279 279
    }
280
    
281
    /**
282
     * insert a system metadata id for a local id
283
     * 
284
     * @param guid the id to insert
285
     * @param localId the systemMetadata object to get the local id for
286
     */
287
    public void createSystemMetadataMapping(String guid, String localId)
288
    {
289
      int serialNumber = -1;
290
        DBConnection dbConn = null;
291
        try {
292

  
293
            // Parse the localId into scope and rev parts
294
            AccessionNumber acc = new AccessionNumber(localId, "NOACTION");
295
            String docid = acc.getDocid();
296
            int rev = (new Integer(acc.getRev()).intValue());
297

  
298
            // Get a database connection from the pool
299
            dbConn = 
300
                DBConnectionPool.getDBConnection("Identifier.createMapping");
301
            serialNumber = dbConn.getCheckOutSerialNumber();
302

  
303
            // Execute the insert statement
304
            String query = "insert into systemMetadata (guid, docid, rev) values (?, ?, ?)";            
305
            PreparedStatement stmt = dbConn.prepareStatement(query);
306
            stmt.setString(1, guid);
307
            stmt.setString(2, docid);
308
            stmt.setInt(3, rev);
309
            int rows = stmt.executeUpdate();
310

  
311
            stmt.close();
312
        } catch (SQLException e) {
313
            logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " 
314
                    + e.getMessage());
315
        } catch (NumberFormatException e) {
316
            logMetacat.error("NumberFormat error while creating a mapping to the system metadata identifier: " 
317
                    + e.getMessage());
318
        } catch (AccessionNumberException e) {
319
            logMetacat.error("AccessionNumber error while creating a mapping to the system metadata identifier: " 
320
                    + e.getMessage());
321
        } finally {
322
            // Return database connection to the pool
323
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
324
        }
325
    }
280 326
}

Also available in: Unified diff