Project

General

Profile

« Previous | Next » 

Revision 5887

Added by berkley almost 14 years ago

adding fields for additional system metadata info

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
62 62
     */
63 63
    public void testGetGUID()
64 64
    {
65
        ph("testGetGUID");
65 66
        try
66 67
        {
67 68
            IdentifierManager im = IdentifierManager.getInstance();
......
86 87
     */
87 88
    public void testGetAllLocalIds()
88 89
    {
90
        ph("testGetAllLocalIds");
89 91
        try
90 92
        {
91 93
            List l = IdentifierManager.getInstance().getAllLocalIds();
92 94
            for(int i=0; i<l.size(); i++)
93 95
            {
94
                //System.out.println(l.get(i));
96
                System.out.println(l.get(i));
95 97
            }
96 98
            assertTrue(l.size() > 0);
97 99
        }
......
103 105

  
104 106
    /** Test that IM instances can be created. */
105 107
    public void testGetInstance() {
108
        ph("testGetInstance");
106 109
        IdentifierManager im = IdentifierManager.getInstance();
107 110
        assertNotNull(im);
108 111
    }
109 112

  
110 113
    /** Test that known LocalId's can be looked up from GUIDs. */
111 114
    public void testGetLocalId() {
115
        ph("testGetLocalId");
112 116
        IdentifierManager im = IdentifierManager.getInstance();
113 117
        String docid = insertTestDocument();
114 118
        String goodGuid = "test:" + docid;
......
124 128
    
125 129
    /** Test that unknown LocalId's return the proper exception. */
126 130
    public void testGetLocalIdNotFound() {
131
        ph("testGetLocalIdNotFound");
127 132
        IdentifierManager im = IdentifierManager.getInstance();
128 133
        String idReturned;
129 134
        try {
......
140 145
     *  be, and that it is not present when it shouldn't be. 
141 146
     */
142 147
    public void testIdentifierExists() {
148
        ph("testIdentifierExists");
143 149
        IdentifierManager im = IdentifierManager.getInstance();
144 150
        String docid = insertTestDocument();
145 151
        im.createMapping("test:"+docid, docid);
......
154 160
     * getLocalId() and getGUID()
155 161
     */
156 162
    public void testCreateMapping() {
163
       ph("testCreateMapping");
157 164
       try
158 165
       {
159 166
            IdentifierManager im = IdentifierManager.getInstance();
......
177 184
     */
178 185
    public void testCreateSystemMetadataMapping()
179 186
    {
187
        ph("testCreateSystemMetadataMapping");
180 188
        try
181 189
        {
182 190
            IdentifierManager im = IdentifierManager.getInstance();
......
211 219
                null, "http://fake.example.com/somedata", null,
212 220
                accessBlock, null, null,
213 221
                null, null);
222
        System.out.println("inserting doc: " + emldoc);
214 223
        String docid = generateDocumentId() + ".1";
215 224
        try {
216 225
            m.login(username, password);
......
222 231
        }
223 232
        return docid;
224 233
    }
234
    
235
    private void ph(String s)
236
    {
237
        System.out.println("*********************** " + s + " ****************************");
238
    }
225 239
}
src/xmltables-oracle.sql
402 402
CREATE TABLE systemMetadata (
403 403
   guid   VARCHAR2(2000),    -- the globally unique string identifier
404 404
   docid  VARCHAR(250), 	 -- the local document id #
405
   rev    NUMBER(8)          -- the revision part of the local identifier
405
   rev    NUMBER(8),          -- the revision part of the local identifier
406
   date_uploaded DATE, -- the date/time the document was first submitted
407
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
408
   checksum VARCHAR2(512), --the checksum of the doc using the given algorithm (see below)
409
   checksum_algorithm VARCHAR2(250), --the algorithm used to calculate the checksum
410
   origin_member_node VARCHAR2(250), --the member node where the document was first uploaded
411
   authoritive_member_node VARCHAR2(250), --the member node that currently controls the document
412
   date_modified DATE, -- the last date/time that the file was changed
413
   submitter VARCHAR2(256) -- the user who originally submitted the doc
406 414
)
407 415

  
408 416
/*
src/upgrade-db-to-1.10.0-postgres.sql
4 4
   guid   text,          -- the globally unique string identifier
5 5
   docid  VARCHAR(250),	 -- the local document id #
6 6
   rev    INT8,          -- the revision part of the local identifier
7
   date_uploaded TIMESTAMP, -- the date/time the document was first submitted
8
   rights_holder VARCHAR(250), --the user who has rights to the document, usually the first persons to upload it
9
   checksum VARCHAR(512), --the checksum of the doc using the given algorithm (see below)
10
   checksum_algorithm VARCHAR(250), --the algorithm used to calculate the checksum
11
   origin_member_node VARCHAR(250), --the member node where the document was first uploaded
12
   authoritive_member_node VARCHAR(250), --the member node that currently controls the document
13
   date_modified TIMESTAMP, -- the last date/time that the file was changed
14
   submitter VARCHAR(256), -- the user who originally submitted the doc
7 15
   CONSTRAINT systemMetadata_pk PRIMARY KEY (guid)
8 16
);
9 17

  
src/xmltables-postgres.sql
289 289
 * data first or the systemMetadata first.
290 290
 */
291 291
CREATE TABLE systemMetadata (
292
   guid   text,          -- the globally unique string identifier
292
   guid   text,          -- the globally unique string identifier of the object that the system metadata describes
293 293
   docid  VARCHAR(250),	 -- the local document id #
294 294
   rev    INT8,          -- the revision part of the local identifier
295
   date_uploaded TIMESTAMP, -- the date/time the document was first submitted
296
   rights_holder VARCHAR(250), --the user who has rights to the document, usually the first persons to upload it
297
   checksum VARCHAR(512), --the checksum of the doc using the given algorithm (see below)
298
   checksum_algorithm VARCHAR(250), --the algorithm used to calculate the checksum
299
   origin_member_node VARCHAR(250), --the member node where the document was first uploaded
300
   authoritive_member_node VARCHAR(250), --the member node that currently controls the document
301
   date_modified TIMESTAMP, -- the last date/time that the file was changed
302
   submitter VARCHAR(256), -- the user who originally submitted the doc
295 303
   CONSTRAINT systemMetadata_pk PRIMARY KEY (guid)
296 304
);
297 305

  
src/upgrade-db-to-1.10.0-oracle.sql
4 4
CREATE TABLE systemMetadata (
5 5
   guid   VARCHAR2(2000),    -- the globally unique string identifier
6 6
   docid  VARCHAR(250), 	 -- the local document id #
7
   rev    NUMBER(8)          -- the revision part of the local identifier
7
   rev    NUMBER(8),          -- the revision part of the local identifier
8
   date_uploaded DATE, -- the date/time the document was first submitted
9
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
10
   checksum VARCHAR2(512), --the checksum of the doc using the given algorithm (see below)
11
   checksum_algorithm VARCHAR2(250), --the algorithm used to calculate the checksum
12
   origin_member_node VARCHAR2(250), --the member node where the document was first uploaded
13
   authoritive_member_node VARCHAR2(250), --the member node that currently controls the document
14
   date_modified DATE, -- the last date/time that the file was changed
15
   submitter VARCHAR2(256) -- the user who originally submitted the doc
8 16
)
9 17

  
10 18
CREATE TABLE identifier (
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
1557 1557
        //insert the system metadata doc id into the systemmetadata table to 
1558 1558
        //link it to the data or metadata document
1559 1559
        IdentifierManager.getInstance().createSystemMetadataMapping(
1560
                sysmeta.getIdentifier().getValue(), sysMetaGuid.getValue());
1560
                sysmeta, sysMetaGuid.getValue());
1561 1561
        return localId;
1562 1562
    }
1563 1563
    
src/edu/ucsb/nceas/metacat/IdentifierManager.java
31 31
import java.sql.SQLException;
32 32

  
33 33
import org.apache.log4j.Logger;
34
import org.dataone.service.types.SystemMetadata;
34 35

  
35 36
import edu.ucsb.nceas.metacat.database.DBConnection;
36 37
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
38
import edu.ucsb.nceas.metacat.properties.PropertyService;
37 39
import edu.ucsb.nceas.metacat.util.DocumentUtil;
38 40

  
39 41
/**
......
49 51
    
50 52
    public static final String TYPE_SYSTEM_METADATA = "systemmetadata";
51 53
    public static final String TYPE_IDENTIFIER = "identifier";
52
    public static final String DATAONE_SM_DOCTYPE = "http://dataone.org/service/types/SystemMetadata/0.1";
54
    public static String DATAONE_SM_DOCTYPE;
53 55
  
54 56
    /**
55 57
     * The single instance of the manager that is always returned.
......
63 65
     */
64 66
    private IdentifierManager()
65 67
    {
68
        try
69
        {
70
            DATAONE_SM_DOCTYPE = PropertyService.getProperty("crudService.listObjects.ReturnDoctype");
71
        }
72
        catch(Exception e)
73
        {
74
            throw new RuntimeException("Error getting System Metadata doctype from " + 
75
                    "the properties file.  Please make sure crudService.listObjects.ReturnDoctype " +
76
                    "exists in metacat.properties.");
77
        }
66 78
    }
67 79

  
68 80
    /**
......
491 503
    }
492 504
    
493 505
    /**
494
     * insert a system metadata id for a local id
506
     * creates a mapping for a system metadata document, but DOES NOT add any
507
     * of the extra system metadata information to the table.  You must call 
508
     * insertAdditionalSystemMetadataFields to complete the entry
495 509
     * 
496 510
     * @param guid the id to insert
497 511
     * @param localId the systemMetadata object to get the local id for
......
502 516
    }
503 517
    
504 518
    /**
519
     * creates a system metadata mapping and adds additional fields from sysmeta
520
     * to the table for quick searching.
521
     * 
522
     * @param guid the id to insert
523
     * @param localId the systemMetadata object to get the local id for
524
     */
525
    public void createSystemMetadataMapping(SystemMetadata sysmeta, String localId)
526
    {
527
        createGenericMapping(sysmeta.getIdentifier().getValue(), localId, TYPE_SYSTEM_METADATA);
528
        insertAdditionalSystemMetadataFields(sysmeta);
529
    }
530
    
531
    /**
505 532
     * update a mapping
506 533
     * @param guid
507 534
     * @param localId
......
561 588
      return this.getLocalId(guid, TYPE_SYSTEM_METADATA);
562 589
    }
563 590
    
591
    public void insertAdditionalSystemMetadataFields(long dateUploaded, String rightsHolder,
592
            String checksum, String checksumAlgorithm, String originMemberNode,
593
            String authoritativeMemberNode, long modifiedDate, String submitter, String guid)
594
    {
595
        DBConnection dbConn = null;
596
        int serialNumber = -1;
597
        try {
598
            // Get a database connection from the pool
599
            dbConn = 
600
                DBConnectionPool.getDBConnection("IdentifierManager.createMapping");
601
            serialNumber = dbConn.getCheckOutSerialNumber();
602

  
603
            // Execute the insert statement
604
            String query = "update " + TYPE_SYSTEM_METADATA + 
605
                " set (date_uploaded, rights_holder, checksum, checksum_algorithm, " +
606
                "origin_member_node, authoritive_member_node, date_modified, submitter) " +
607
                "= (?, ?, ?, ?, ?, ?, ?, ?) where guid = ?";
608
            PreparedStatement stmt = dbConn.prepareStatement(query);
609
            
610
            //data values
611
            stmt.setTimestamp(1, new java.sql.Timestamp(dateUploaded));
612
            stmt.setString(2, rightsHolder);
613
            stmt.setString(3, checksum);
614
            stmt.setString(4, checksumAlgorithm);
615
            stmt.setString(5, originMemberNode);
616
            stmt.setString(6, authoritativeMemberNode);
617
            stmt.setTimestamp(7, new java.sql.Timestamp(modifiedDate));
618
            stmt.setString(8, submitter);
619
            //where clause
620
            stmt.setString(9, guid);
621
            System.out.println("stmt: " + stmt.toString());
622
            //execute
623
            int rows = stmt.executeUpdate();
624

  
625
            stmt.close();
626
        } catch (SQLException e) {
627
            e.printStackTrace();
628
            logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " 
629
                    + e.getMessage());
630
        } catch (NumberFormatException e) {
631
            e.printStackTrace();
632
            logMetacat.error("NumberFormat error while creating a mapping to the system metadata identifier: " 
633
                    + e.getMessage());
634
        } finally {
635
            // Return database connection to the pool
636
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
637
        }
638
    }
639
    
564 640
    /**
641
     * Insert the system metadata fields into the db
642
     * @param sm
643
     */
644
    public void insertAdditionalSystemMetadataFields(SystemMetadata sm)
645
    {
646
        insertAdditionalSystemMetadataFields(
647
                sm.getDateUploaded().getTime(),
648
                sm.getRightsHolder().getValue(), 
649
                sm.getChecksum().getValue(), 
650
                sm.getChecksum().getAlgorithm().name(), 
651
                sm.getOriginMemberNode().getValue(),
652
                sm.getAuthoritativeMemberNode().getValue(), 
653
                sm.getDateSysMetadataModified().getTime(),
654
                sm.getSubmitter().getValue(), 
655
                sm.getIdentifier().getValue());
656
    }
657
    
658
    /**
565 659
     * return a localId based on a guid.  The type can either be 'identifier' 
566 660
     * to get an id from the identifier table or 'systemmetadata' to get
567 661
     * the identifier from the systemidentifier table
......
653 747
            stmt.setString(1, guid);
654 748
            stmt.setString(2, docid);
655 749
            stmt.setInt(3, rev);
750
            System.out.println("generic mapping query: " + stmt.toString());
656 751
            int rows = stmt.executeUpdate();
657 752

  
658 753
            stmt.close();
659 754
        } catch (SQLException e) {
660 755
            e.printStackTrace();
661
            logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " 
756
            logMetacat.warn("SQL error while creating a mapping to the system metadata identifier: " 
662 757
                    + e.getMessage());
663 758
        } catch (NumberFormatException e) {
664 759
            e.printStackTrace();

Also available in: Unified diff