Project

General

Profile

« Previous | Next » 

Revision 6278

implement reserveIdentifier() and check whether the id is reserved when creating records (only allow the create when the Subject creating matches the Subject who reserved it -- currently stored in rightsHolder)

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
531 531

  
532 532
	      logMetacat.debug("Checking if identifier exists...");
533 533
	      // Check that the identifier does not already exist
534
	      IdentifierManager im = IdentifierManager.getInstance();
535
	      if (im.identifierExists(guid.getValue())) {
534
	      if (IdentifierManager.getInstance().identifierExists(guid.getValue())) {
535
			// check if we reserved the id
536
			boolean reserved = IdentifierManager.getInstance().hasReservation(guid, session);
537
			// throw an exception if not
538
			if (!reserved) {
536 539
	          throw new InvalidRequest("4863", 
537 540
	              "GUID is already in use by an existing object.");
541
			}
538 542
	      }
539 543

  
540 544
	      // insert the system metadata into the object store
......
587 591
	  throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
588 592
	  NotImplemented, InvalidRequest {
589 593

  
590
		throw new NotImplemented("4191", "reserveIdentifier not implemented");
591

  
594
		// generate a pid if not provided
595
		if (pid == null) {
596
			pid = new Identifier();
597
			// TODO: go to EZID
598
			StringBuffer sb = new StringBuffer();
599
			if (scope != null) {
600
				sb.append(scope);
601
				sb.append(".");
602
			}
603
			sb.append(System.currentTimeMillis());
604
			pid.setValue(sb.toString());
605
		}
606
		// does this identifier exist?
607
		if (IdentifierManager.getInstance().identifierExists(pid.getValue())) {
608
			// check if it was reserved already
609
			if (IdentifierManager.getInstance().hasReservation(pid, session)) {
610
				throw new IdentifierNotUnique("4210", "Identifier already reserved: " + pid.getValue());
611
			}
612
			throw new IdentifierNotUnique("4210", "Identifier already exists: " + pid.getValue());
613
		}
614
		
615
		// if we got this far, save it
616
		SystemMetadata provisoinalSystemMetadata = new SystemMetadata();
617
		provisoinalSystemMetadata.setIdentifier(pid);
618
		provisoinalSystemMetadata.setRightsHolder(session.getSubject());
619
		try {
620
			IdentifierManager.getInstance().createSystemMetadata(provisoinalSystemMetadata);
621
		} catch (McdbDocNotFoundException e) {
622
			throw new ServiceFailure("4210", e.getMessage());
623
		}
624
		
625
		return pid;
592 626
	}
593 627

  
594 628
	/**
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
175 175

  
176 176
    logMetacat.debug("Checking if identifier exists...");
177 177
    // Check that the identifier does not already exist
178
    IdentifierManager im = IdentifierManager.getInstance();
179
    if (im.identifierExists(pid.getValue())) {
180
        throw new IdentifierNotUnique("1120", 
181
          "The requested identifier " + pid.getValue() +
182
          " is already used by another object and" +
183
          "therefore can not be used for this object. Clients should choose" +
184
          "a new identifier that is unique and retry the operation or " +
185
          "use CN_crud.reserveIdentifier() to reserve one.");
186
        
178
    if (IdentifierManager.getInstance().identifierExists(pid.getValue())) {
179
    	// check if we reserved the id
180
    	boolean reserved = IdentifierManager.getInstance().hasReservation(pid, session);
181
    	// throw an exception if not
182
    	if (!reserved) {
183
	    	throw new IdentifierNotUnique("1120", 
184
			          "The requested identifier " + pid.getValue() +
185
			          " is already used by another object and" +
186
			          "therefore can not be used for this object. Clients should choose" +
187
			          "a new identifier that is unique and retry the operation or " +
188
			          "use CN_crud.reserveIdentifier() to reserve one.");
189
    	}
187 190
    }
188 191

  
189 192
    // check for permission

Also available in: Unified diff