Project

General

Profile

« Previous | Next » 

Revision 6569

Change updateSystemMetadata() to evaluate the incoming system metadata serial version against that found in the hzSystemMetadata map. If they are the same, do the update. If not, throw an InvalidRequest explaining that they need the most current version.

View differences:

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

  
24 24
package edu.ucsb.nceas.metacat.dataone;
25 25

  
26
import java.io.IOException;
27
import java.io.InputStream;
26 28
import java.math.BigInteger;
27 29
import java.util.Calendar;
28 30
import java.util.Date;
......
31 33

  
32 34
import javax.servlet.http.HttpServletRequest;
33 35

  
36
import org.apache.commons.io.IOUtils;
34 37
import org.apache.log4j.Logger;
35 38
import org.dataone.client.CNode;
36 39
import org.dataone.client.D1Client;
......
47 50
import org.dataone.service.exceptions.NotFound;
48 51
import org.dataone.service.exceptions.NotImplemented;
49 52
import org.dataone.service.exceptions.ServiceFailure;
53
import org.dataone.service.exceptions.UnsupportedType;
50 54
import org.dataone.service.types.v1.Checksum;
51 55
import org.dataone.service.types.v1.Identifier;
52 56
import org.dataone.service.types.v1.Node;
......
64 68
import org.dataone.service.types.v1.Session;
65 69
import org.dataone.service.types.v1.Subject;
66 70
import org.dataone.service.types.v1.SystemMetadata;
71
import org.dataone.service.types.v1.util.ChecksumUtil;
72
import org.dataone.service.util.Constants;
67 73

  
68 74
import com.hazelcast.query.SqlPredicate;
69 75

  
......
662 668
    	    HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier());
663 669
          SystemMetadata currentSysMeta = 
664 670
              HazelcastService.getInstance().getSystemMetadataMap().get(sysmeta.getIdentifier());
671
          
672
          // only update if the requester has the most current system metadata
673
          if (sysmeta.getSerialVersion().compareTo(currentSysMeta.getSerialVersion()) != 0 ) {
674
              String msg = "The serial version of the system metadata " + 
675
                  "to be updated does not equal the serial version of the current " +
676
                  "system metadata for identifier " + guid + ". Ensure that the " +
677
                  "copy is the most current before updating.";
678
              logMetacat.warn(msg);
679
              HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
680
              throw new InvalidRequest("4913", msg);
681
              
682
          }
683
          
665 684
          sysmeta.setSerialVersion(currentSysMeta.getSerialVersion().add(BigInteger.ONE));
666 685
          sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
667 686
          HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
......
886 905
    
887 906
  }
888 907

  
908
  /**
909
   * Adds a new object to the Node, where the object is either a data 
910
   * object or a science metadata object. This method is called by clients 
911
   * to create new data objects on Member Nodes or internally for Coordinating
912
   * Nodes
913
   * 
914
   * @param session - the Session object containing the credentials for the Subject
915
   * @param pid - The object identifier to be created
916
   * @param object - the object bytes
917
   * @param sysmeta - the system metadata that describes the object  
918
   * 
919
   * @return pid - the object identifier created
920
   * 
921
   * @throws InvalidToken
922
   * @throws ServiceFailure
923
   * @throws NotAuthorized
924
   * @throws IdentifierNotUnique
925
   * @throws UnsupportedType
926
   * @throws InsufficientResources
927
   * @throws InvalidSystemMetadata
928
   * @throws NotImplemented
929
   * @throws InvalidRequest
930
   */
931
  public Identifier create(Session session, Identifier pid, InputStream object,
932
    SystemMetadata sysmeta) 
933
    throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
934
    UnsupportedType, InsufficientResources, InvalidSystemMetadata, 
935
    NotImplemented, InvalidRequest {
936
        
937
      return pid;
938

  
939
  }
940

  
889 941
}

Also available in: Unified diff