Project

General

Profile

« Previous | Next » 

Revision 6904

Added by Chris Jones over 12 years ago

In IdentifierManager.updateSystemMetadata(), add a check for invalid system metadata (fields that throw a NullPointerException on access) to ensure that system metadata is populated correctly. Updated calling classes to handle the exception.

View differences:

src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
33 33
import java.util.concurrent.locks.Lock;
34 34

  
35 35
import org.apache.log4j.Logger;
36
import org.dataone.service.exceptions.InvalidSystemMetadata;
36 37
import org.dataone.service.types.v1.Identifier;
37 38
import org.dataone.service.types.v1.Node;
38 39
import org.dataone.service.types.v1.NodeReference;
......
435 436
		try {
436 437
			if (!IdentifierManager.getInstance().systemMetadataExists(sm.getIdentifier().getValue())) {
437 438
				IdentifierManager.getInstance().createSystemMetadata(sm);
439
				
438 440
			} else {
439 441
				IdentifierManager.getInstance().updateSystemMetadata(sm);
442
				
440 443
			}
441 444
		} catch (McdbDocNotFoundException e) {
442
			logMetacat.error(
443
					"Could not save System Metadata to local store.", e);
445
			logMetacat.error("Could not save System Metadata to local store.", e);
446
			
444 447
		} catch (SQLException e) {
445
	      logMetacat.error(
446
	              "Could not save System Metadata to local store.", e);
447
        }
448
	      logMetacat.error("Could not save System Metadata to local store.", e);
449
	      
450
    } catch (InvalidSystemMetadata e) {
451
        logMetacat.error("Could not save System Metadata to local store.", e);
452
        
453
    }
448 454
	}
449 455
	
450 456
	public void resynch() throws Exception {
src/edu/ucsb/nceas/metacat/dataone/hazelcast/SystemMetadataMap.java
7 7
import java.util.Set;
8 8

  
9 9
import org.apache.log4j.Logger;
10
import org.dataone.service.exceptions.InvalidSystemMetadata;
10 11
import org.dataone.service.types.v1.Identifier;
11 12
import org.dataone.service.types.v1.ObjectInfo;
12 13
import org.dataone.service.types.v1.ObjectList;
......
59 60
		} catch (SQLException e) {
60 61
	      throw new RuntimeException(e.getMessage(), e);
61 62
	      
62
    }
63
    } catch (InvalidSystemMetadata e) {
64
        throw new RuntimeException(e.getMessage(), e);
65
        }
63 66
	}
64 67

  
65 68
	@Override
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java
33 33
import org.apache.commons.logging.Log;
34 34
import org.apache.commons.logging.LogFactory;
35 35
import org.dataone.service.exceptions.InvalidRequest;
36
import org.dataone.service.exceptions.InvalidSystemMetadata;
36 37
import org.dataone.service.exceptions.InvalidToken;
37 38
import org.dataone.service.exceptions.NotAuthorized;
38 39
import org.dataone.service.exceptions.NotFound;
......
138 139
     * @throws InvalidToken 
139 140
     * @throws PropertyNotFoundException 
140 141
     * @throws McdbDocNotFoundException 
142
     * @throws InvalidSystemMetadata 
141 143
     */
142 144
    public void generateMissingSystemMetadata(String localId, boolean includeOre, boolean downloadData) 
143 145
    throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized,
144
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException 
146
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException, InvalidSystemMetadata 
145 147
    {
146 148
    	log.debug("generateMissingSystemMetadata() called.");
147 149
    	log.debug("Creating SystemMetadata for localId " + localId);
......
161 163
        //insert the systemmetadata object or just update it as needed
162 164
        boolean exists = IdentifierManager.getInstance().systemMetadataExists(sm.getIdentifier().getValue());
163 165
        if (!exists) {
164
        	IdentifierManager.getInstance().createSystemMetadata(sm);
166
        	IdentifierManager.getInstance().createSystemMetadata(sm);        	
165 167
        }
166 168
        IdentifierManager.getInstance().updateSystemMetadata(sm);
167 169

  
src/edu/ucsb/nceas/metacat/IdentifierManager.java
37 37

  
38 38
import org.apache.log4j.Logger;
39 39
import org.dataone.client.ObjectFormatCache;
40
import org.dataone.service.exceptions.InvalidSystemMetadata;
40 41
import org.dataone.service.exceptions.NotFound;
41 42
import org.dataone.service.types.v1.AccessPolicy;
42 43
import org.dataone.service.types.v1.AccessRule;
......
915 916
     * @param localId the systemMetadata object to get the local id for
916 917
     * @throws McdbDocNotFoundException 
917 918
     * @throws SQLException 
919
     * @throws InvalidSystemMetadata 
918 920
     */
919 921
    public void createSystemMetadata(SystemMetadata sysmeta) 
920
        throws McdbDocNotFoundException, SQLException {
922
        throws McdbDocNotFoundException, SQLException, InvalidSystemMetadata {
921 923
    	String guid = sysmeta.getIdentifier().getValue();
922 924
    	// insert the record
923 925
        insertSystemMetadata(guid);
......
1142 1144
     * @param sm
1143 1145
     * @throws McdbDocNotFoundException 
1144 1146
     * @throws SQLException 
1147
     * @throws InvalidSystemMetadata 
1145 1148
     */
1146 1149
    public void updateSystemMetadata(SystemMetadata sm) 
1147
      throws McdbDocNotFoundException, SQLException {
1150
      throws McdbDocNotFoundException, SQLException, InvalidSystemMetadata {
1148 1151
    	
1149 1152
      Boolean replicationAllowed = false;
1150 1153
		  Integer numberReplicas = -1;
......
1156 1159
    		numberReplicas = numberReplicas == null ? -1: numberReplicas;
1157 1160
    	}
1158 1161

  
1162
    	// ensure certain system metadata fields are populated
1163
    	try {
1164
          sm.getIdentifier().getValue();
1165
          sm.getSerialVersion().intValue();
1166
          sm.getDateUploaded().getTime();
1167
          sm.getRightsHolder().getValue();
1168
          sm.getChecksum().getValue();
1169
          sm.getChecksum().getAlgorithm();
1170
          sm.getOriginMemberNode().getValue();
1171
          sm.getAuthoritativeMemberNode().getValue();
1172
          sm.getDateSysMetadataModified().getTime();
1173
          // sm.getSubmitter().getValue(); // filled in with identifier
1174
          sm.getFormatId().getValue();
1175
          sm.getArchived().booleanValue();
1176
    	    
1177
    	} catch (NullPointerException npe) {
1178
    	    throw new InvalidSystemMetadata("0000", npe.getMessage());
1179
    	    
1180
    	}
1181
    	
1159 1182
    	// the main systemMetadata fields
1160 1183
		  updateSystemMetadataFields(
1161 1184
				sm.getDateUploaded() == null ? null: sm.getDateUploaded().getTime(),
......
1166 1189
				sm.getAuthoritativeMemberNode() == null ? null: sm.getAuthoritativeMemberNode().getValue(), 
1167 1190
				sm.getDateSysMetadataModified() == null ? null: sm.getDateSysMetadataModified().getTime(),
1168 1191
				sm.getSubmitter() == null ? null: sm.getSubmitter().getValue(), 
1169
		        sm.getIdentifier().getValue(),
1170
		        sm.getFormatId() == null ? null: sm.getFormatId().getValue(),
1171
		        sm.getSize(),
1172
		        sm.getArchived() == null ? false: sm.getArchived(),
1173
		        replicationAllowed, 
1174
		        numberReplicas,
1175
		        sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
1176
		        sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue(),
1177
		        sm.getSerialVersion()
1192
		    sm.getIdentifier().getValue(),
1193
		    sm.getFormatId() == null ? null: sm.getFormatId().getValue(),
1194
		    sm.getSize(),
1195
		    sm.getArchived() == null ? false: sm.getArchived(),
1196
		    replicationAllowed, 
1197
		    numberReplicas,
1198
		    sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
1199
		    sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue(),
1200
		    sm.getSerialVersion()
1178 1201
        );
1179 1202
        
1180 1203
        String guid = sm.getIdentifier().getValue();

Also available in: Unified diff