Project

General

Profile

« Previous | Next » 

Revision 5798

Added by berkley almost 14 years ago

fixes for creating SM for legacy docs

View differences:

test/test.properties
1 1
# Set this to the location of the metacat application context
2 2
# directory.  The tests will use this to find metacat.properties
3
metacat.contextDir=/Users/berkley/tools/tomcat/webapps/knb
3
metacat.contextDir=/var/lib/tomcat/webapps/knb
4 4
#metacat.contextDir=/usr/share/tomcat5.5/webapps/knb
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
94 94
	public static Test suite() 
95 95
	{
96 96
		TestSuite suite = new TestSuite();
97
		suite.addTest(new CrudServiceTest("initialize"));
97
		/*suite.addTest(new CrudServiceTest("initialize"));
98 98
		suite.addTest(new CrudServiceTest("testSingletonAccessor"));
99 99
		suite.addTest(new CrudServiceTest("testCreateAndGet"));
100 100
		suite.addTest(new CrudServiceTest("testGetSystemMetadata"));
101 101
		suite.addTest(new CrudServiceTest("testUpdate"));
102 102
		suite.addTest(new CrudServiceTest("testListObjects"));
103
		suite.addTest(new CrudServiceTest("testAccessControl"));
103
		suite.addTest(new CrudServiceTest("testAccessControl"));*/
104 104
		suite.addTest(new CrudServiceTest("testGenerateMissingSystemMetadata"));
105
		suite.addTest(new CrudServiceTest("testGetLogRecords"));
105
		/*suite.addTest(new CrudServiceTest("testGetLogRecords"));
106 106
		suite.addTest(new CrudServiceTest("testChecksumError"));
107 107
		suite.addTest(new CrudServiceTest("testPublicAccess"));
108 108
		suite.addTest(new CrudServiceTest("testFailedCreate"));
109 109
		suite.addTest(new CrudServiceTest("testChecksum"));
110 110
		suite.addTest(new CrudServiceTest("testDescribe"));
111 111
		suite.addTest(new CrudServiceTest("testDelete"));
112
		suite.addTest(new CrudServiceTest("testSemiColonsInIdentifiers"));
112
		suite.addTest(new CrudServiceTest("testSemiColonsInIdentifiers"));*/
113 113
		return suite;
114 114
	}
115 115
	
......
432 432
	    try
433 433
	    {
434 434
	        CrudService cs = CrudService.getInstance();
435
	        AuthToken token = getToken();
435
	        AuthToken token = getToken("uid=dataone_cn_metacat,o=DATAONE,dc=ecoinformatics,dc=org", "umtmm4tcn");
436 436
	        //create a document with no system metadata
437 437
	        String testDoc = getTestDoc();
438 438
	        Identifier id = new Identifier();
......
810 810
	
811 811
	/**
812 812
	 * authenticate and return a token
813
	 * use the test.mcUser and test.mcPassword username/password combo
813 814
	 */
814 815
	private AuthToken getToken()
815 816
	  throws Exception
816 817
	{
818
        String username = PropertyService.getProperty("test.mcUser");
819
        String password = PropertyService.getProperty("test.mcPassword");
820
        return getToken(username, password);
821
	}
822
	
823
	/**
824
	 * authenticate and return a token using the given credentials
825
	 */
826
	private AuthToken getToken(String username, String password)
827
	  throws Exception
828
	{
817 829
	    CrudService cs = CrudService.getInstance();
818 830
        //login and get a sessionid
819 831
        MetacatRestClient restClient = new MetacatRestClient(cs.getContextUrl());
820
        String username = PropertyService.getProperty("test.mcUser");
821
        String password = PropertyService.getProperty("test.mcPassword");
822 832
        String response = restClient.login(username, password);
823 833
        String sessionid = restClient.getSessionId();
824 834
        SessionService sessionService = SessionService.getInstance();
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
66 66

  
67 67
import com.gc.iotools.stream.is.InputStreamFromOutputStream;
68 68

  
69
import edu.ucsb.nceas.metacat.AccessionNumber;
69 70
import edu.ucsb.nceas.metacat.AccessionNumberException;
70 71
import edu.ucsb.nceas.metacat.MetacatResultSet;
71 72
import edu.ucsb.nceas.metacat.MetacatResultSet.Document;
......
244 245
                SystemMetadata sm = createSystemMetadata(localId, token);
245 246
                //insert the systemmetadata object
246 247
                SessionData sessionData = getSessionData(token);
247
                insertSystemMetadata(sm, sessionData);
248
                String smlocalid = insertSystemMetadata(sm, sessionData);
249
                System.out.println("setting access on SM doc with localid " + smlocalid);
250
                handler.setAccess(metacatUrl, sessionData.getUserName(), smlocalid,
251
                        "public", "4", "allow", "allowFirst");
252
                
248 253
                String username = "public";
249 254
                if(sessionData != null)
250 255
                {
......
255 260
            }
256 261
            catch(Exception e)
257 262
            {
258
                //e.printStackTrace();
263
                e.printStackTrace();
259 264
                System.out.println("Exception generating missing system metadata: " + e.getMessage());
260 265
                logMetacat.error("Could not generate missing system metadata: " + e.getMessage());
261 266
            }
......
1939 1944
        //get the document text
1940 1945
        int rev = im.getLatestRevForLocalId(localId);
1941 1946
        Identifier identifier = new Identifier();
1942
        identifier.setValue(im.getGUID(localId, rev));
1947
        try
1948
        {
1949
            identifier.setValue(im.getGUID(localId, rev));
1950
        }
1951
        catch(McdbDocNotFoundException mcdbe)
1952
        { //we're creating a new SM doc for a doc that is not in the identifier table
1953
          //so we need to add it to
1954
            System.out.println("No guid in the identifier table.  adding it for " + localId);
1955
            im.createMapping(localId, localId);
1956
            System.out.println("mapping created for " + localId);
1957
            AccessionNumber accNum = new AccessionNumber(localId, "NONE");
1958
            identifier.setValue(im.getGUID(accNum.getDocid(), rev));
1959
        }
1960
        
1961
        System.out.println("creating system metadata for guid " + identifier.getValue());
1943 1962
        InputStream is = this.get(token, identifier);
1944 1963
        
1945 1964
        SystemMetadata sm = new SystemMetadata();
......
2002 2021
        return sm;
2003 2022
    }
2004 2023
}
2024

  
src/edu/ucsb/nceas/metacat/IdentifierManager.java
90 90
    public Hashtable<String, Object> getDocumentInfo(String localId)
91 91
        throws McdbDocNotFoundException
92 92
    {
93
        try
94
        {
95
            AccessionNumber acc = new AccessionNumber(localId, "NONE");
96
            localId = acc.getDocid();
97
        }
98
        catch(Exception e)
99
        {
100
            //do nothing. just try the localId as it is
101
        }
93 102
        Hashtable<String, Object> h = new Hashtable<String, Object>();
94 103
        String sql = "select docname, doctype, user_owner, user_updated, " +
95 104
            "server_location, rev, date_created, date_updated from " + 
......
130 139
            {
131 140
                stmt.close();
132 141
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
133
                throw new McdbDocNotFoundException("Could not find document " + localId);
142
                throw new McdbDocNotFoundException("2Could not find document " + localId);
134 143
            }
135 144
            
136 145
            String sql2 = "select principal_name, permission, perm_type, perm_order from xml_access " +
......
177 186
    public int getLatestRevForLocalId(String localId)
178 187
        throws McdbDocNotFoundException
179 188
    {
189
        try
190
        {
191
            AccessionNumber acc = new AccessionNumber(localId, "NONE");
192
            localId = acc.getDocid();
193
        }
194
        catch(Exception e)
195
        {
196
            //do nothing. just try the localId as it is
197
        }
180 198
        int rev = 0;
181 199
        String sql = "select rev from xml_documents where docid like '" + localId + "'";
182 200
        DBConnection dbConn = null;
......
199 217
            {
200 218
                stmt.close();
201 219
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
202
                throw new McdbDocNotFoundException("Could not find document " + localId);
220
                throw new McdbDocNotFoundException("While trying to get the latest rev, could not find document " + localId);
203 221
            }
204 222
        } 
205 223
        catch (SQLException e) 
......
226 244
        //String sql = "select docid from xml_documents where docid not " +
227 245
        //    "in (select docid from identifier where guid in (select guid from systemmetadata)) " +
228 246
        //    "and doctype not like '" + DATAONE_SM_DOCTYPE + "'";
229
        String sql = "select docid from xml_documents where docid not in " +
247
        String sql = "select docid, rev from xml_documents where docid not in " +
230 248
            "(select docid from systemmetadata) and (docid not in " +
231 249
            "(select docid from identifier where guid in (select guid from systemmetadata)))";
232 250
        DBConnection dbConn = null;
......
243 261
            while (rs.next()) 
244 262
            {
245 263
                String localid = rs.getString(1);
264
                String rev = rs.getString(2);
265
                localid += "." + rev;
246 266
                System.out.println("id to add SM for: " + localid);
247 267
                ids.add(localid);
248 268
            } 
......
421 441
    public String getGUID(String docid, int rev)
422 442
      throws McdbDocNotFoundException
423 443
    {
444
        System.out.println("getting guid for " + docid);
424 445
        String query = "select guid from identifier where docid = ? and rev = ?";
425 446
        String guid = null;
426 447
        boolean found = false;
......
653 674
        }
654 675
    }
655 676
}
677

  

Also available in: Unified diff