Project

General

Profile

« Previous | Next » 

Revision 5286

Added by Matt Jones about 14 years ago

Added support to ResourceHandler to allow the putObject method to use
arbitrary guid strings as input. These strings are examined, and if they
match the Metacat docid format (scope.id.rev), they are used directly. If
the id is a string in another format, a new localId is generated based on
the current time. Either way, a mapping is made into the identifier table
to relate the original guid to the new localId. Modified DocumentUtil to
generate the ids, and MCTest case to use this new utility method (to stay DRY).
Tests were updated to expect these global identifiers in the putObject
method.

View differences:

ResourceHandler.java
227 227
    private void loadSessionData() {
228 228
        SessionData sessionData = RequestUtil.getSessionData(request);
229 229

  
230
        // TODO: validate the session before allowing these values to be set
230 231
        username = sessionData.getUserName();
231 232
        password = sessionData.getPassword();
232 233
        groupNames = sessionData.getGroupNames();
233 234
        sessionId = sessionData.getId();
234 235

  
235
        if (username == null)
236
        if (username == null) {
236 237
            username = "public";
238
        }
237 239
    }
238 240

  
239 241
    /**
......
344 346

  
345 347
    /**
346 348
     *  Earthgrid API > Identifier Service > isRegistered Function : calls MetacatHandler > handleIdIsRegisteredAction
347
     * @param identifierId
349
     * @param guid
348 350
     * @throws IOException
349 351
     */
350
    private void isRegistered(String identifierId) throws IOException {
351
        params.put("docid", new String[] { identifierId });
352
    private void isRegistered(String guid) throws IOException
353
    {
354
        
355
        // Look up the localId for this guid
356
        IdentifierManager im = IdentifierManager.getInstance();
357
        String localId = "";
358
        try {
359
            localId = im.getLocalId(guid);
360
        } catch (McdbDocNotFoundException e) {
361
            // TODO: Need to return the proper DataONE exception
362
        }
363
        
364
        params.put("docid", new String[] { localId });
352 365
        PrintWriter out = response.getWriter();
353 366
        handler.handleIdIsRegisteredAction(out, params, response);
354 367
        out.close();
......
366 379

  
367 380
    /**
368 381
     * Earthgrid API > Identifier Service > getNextRevision Function : calls MetacatHandler > handleGetRevisionAndDocTypeAction
369
     * @param identifierId
382
     * @param guid
370 383
     * @throws IOException
371 384
     */
372
    private void getNextRevision(String identifierId) throws IOException {
373
        params.put("docid", new String[] { identifierId });
385
    private void getNextRevision(String guid) throws IOException 
386
    {
387
        params.put("docid", new String[] { guid });
374 388
        PrintWriter out = response.getWriter();
375 389
        //handler.handleGetRevisionAndDocTypeAction(out, params);
376 390

  
377 391
        try {
378 392
            // Make sure there is a docid
379
            if (identifierId == null || identifierId.equals("")) {
393
            if (guid == null || guid.equals("")) {
380 394
                throw new Exception("User didn't specify docid!");
381
            }//if
395
            }
382 396

  
397
            // Look up the localId for this guid
398
            IdentifierManager im = IdentifierManager.getInstance();
399
            String localId = "";
400
            try {
401
                localId = im.getLocalId(guid);
402
            } catch (McdbDocNotFoundException e) {
403
                // TODO: Need to return the proper DataONE exception
404
            }
405
           
383 406
            // Create a DBUtil object
384 407
            DBUtil dbutil = new DBUtil();
385 408
            // Get a rev and doctype
386 409
            String revAndDocType = dbutil
387
                    .getCurrentRevisionAndDocTypeForGivenDocument(identifierId);
410
                    .getCurrentRevisionAndDocTypeForGivenDocument(localId);
388 411
            int revision = Integer.parseInt(revAndDocType.split(";")[0]) + 1;
389 412

  
390 413
            out.println("<?xml version=\"1.0\"?>");
......
425 448
        try {
426 449
            localId = im.getLocalId(guid);
427 450
        } catch (McdbDocNotFoundException e) {
428
            // Need to return the proper DataONE exception
451
            // TODO: Need to return the proper DataONE exception
429 452
        }
430 453
        
431 454
        // Now use that localId to read the object and return it
......
454 477
    private void query() throws Exception {
455 478
        /*  This block commented out because of the EcoGrid circular dependency.
456 479
         *  For now, query will not be supported until the circularity can be
457
         *  resolved, probably by movind the ecogrid query syntax transformers
480
         *  resolved, probably by moving the ecogrid query syntax transformers
458 481
         *  directly into the Metacat codebase.  MBJ 2010-02-03
459 482
         
460 483
        try {
......
509 532
     */
510 533
    private void putObject(String objectId) throws IOException {
511 534

  
535
        // TODO: This function lacks proper handling of authz and authn, so it
536
        // seems that anyone can insert or update; interacts with 
537
        // loadSessinData(), which doesn't validate the session
538
        
512 539
        String action = request.getParameter(FUNCTION_KEYWORD);
513 540

  
514 541
        if (action.equals(FUNCTION_NAME_UPDATE)
515 542
                || action.equals(FUNCTION_NAME_INSERT)) {
516
            //
543
            
544
            // Check if the objectId exists
545
            IdentifierManager im = IdentifierManager.getInstance();
546
            if (im.identifierExists(objectId)) {
547
                // TODO: return IdentifierNotUnique exception
548
            }
549
            
550
            // TODO: For updates, need to check if the old id exists, and if not throw an exception
551
            
517 552
            // WARNING: This should not be a Reader if we are inserting data
518 553
            // Nor should it be read into a String
519 554
            // so this seems like a latent bug to me (MBJ; 16Mar2010)
......
524 559
                buffer.append(line);
525 560
            }
526 561

  
527
            params.put("docid", new String[] { objectId });
562
            String localId = im.generateLocalId(objectId, 1);
563
            params.put("docid", new String[] { localId });
528 564
            params.put("doctext", new String[] { buffer.toString().trim() });
529 565
            params.put("action", new String[] { action });
530 566

  
......
534 570
                        params, username, groupNames);
535 571
                out.close();
536 572
            } else {
573
                // TODO: throw exception to show lack of credentials
537 574
                printError("Permission denied for user " + username, response);
538 575

  
539 576
            }
540 577
        } else {
578
            // TODO: throw the proper exception to indicate an invalid request
541 579
            printError("Specifiy the operation type.(update or insert)",
542 580
                    response);
543 581
        }

Also available in: Unified diff