Project

General

Profile

« Previous | Next » 

Revision 6311

allow very minimal system metadata for provisional entries (CN.reserveIdentifier)

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
625 625
		SystemMetadata provisoinalSystemMetadata = new SystemMetadata();
626 626
		provisoinalSystemMetadata.setIdentifier(pid);
627 627
		provisoinalSystemMetadata.setRightsHolder(session.getSubject());
628
		provisoinalSystemMetadata.setSubmitter(session.getSubject());
629
		provisoinalSystemMetadata.setDateSysMetadataModified(new Date());
630
		provisoinalSystemMetadata.setDateUploaded(new Date());
631
		provisoinalSystemMetadata.setSize(0);
628 632
		try {
629 633
			IdentifierManager.getInstance().createSystemMetadata(provisoinalSystemMetadata);
634
			IdentifierManager.getInstance().setProvisional(pid.getValue(), true);
630 635
		} catch (McdbDocNotFoundException e) {
631 636
			throw new ServiceFailure("4210", e.getMessage());
632 637
		}
src/edu/ucsb/nceas/metacat/IdentifierManager.java
1089 1089
        }
1090 1090
    }
1091 1091
    
1092
    public void setProvisional(String guid, boolean provisional) {
1093
        DBConnection dbConn = null;
1094
        int serialNumber = -1;
1095
        
1096
        try {
1097
            // Get a database connection from the pool
1098
            dbConn = 
1099
                DBConnectionPool.getDBConnection("IdentifierManager.setProvisional");
1100
            serialNumber = dbConn.getCheckOutSerialNumber();
1101

  
1102
            // Execute the insert statement
1103
            String query = "update " + TYPE_SYSTEM_METADATA + 
1104
                " set provisional = ? where guid = ?";
1105
            PreparedStatement stmt = dbConn.prepareStatement(query);
1106
            
1107
            //data values
1108
            stmt.setBoolean(1, provisional);
1109
            //where clause
1110
            stmt.setString(2, guid);
1111
            logMetacat.debug("stmt: " + stmt.toString());
1112
            //execute
1113
            int rows = stmt.executeUpdate();
1114

  
1115
            stmt.close();
1116
        } catch (SQLException e) {
1117
            e.printStackTrace();
1118
            logMetacat.error("setProvisional: SQL error while creating a mapping to the system metadata identifier: " 
1119
                    + e.getMessage());
1120
        } finally {
1121
            // Return database connection to the pool
1122
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1123
        }
1124
    }
1125
    
1092 1126
    private void insertSystemMetadataProvenance(String guid, String relationship, List<String> targetGuids)
1093 1127
    {
1094 1128
        DBConnection dbConn = null;
......
1245 1279

  
1246 1280
    	// the main systemMetadata fields
1247 1281
		updateSystemMetadataFields(
1248
                sm.getDateUploaded().getTime(),
1249
                sm.getRightsHolder().getValue(), 
1250
                sm.getChecksum().getValue(), 
1251
                sm.getChecksum().getAlgorithm().name(), 
1252
                sm.getOriginMemberNode().getValue(),
1253
                sm.getAuthoritativeMemberNode().getValue(), 
1254
                sm.getDateSysMetadataModified().getTime(),
1255
                sm.getSubmitter().getValue(), 
1282
				sm.getDateUploaded() == null ? null: sm.getDateUploaded().getTime(),
1283
				sm.getRightsHolder() == null ? null: sm.getRightsHolder().getValue(), 
1284
				sm.getChecksum() == null ? null: sm.getChecksum().getValue(), 
1285
				sm.getChecksum() == null ? null: sm.getChecksum().getAlgorithm().name(), 
1286
				sm.getOriginMemberNode() == null ? null: sm.getOriginMemberNode().getValue(),
1287
				sm.getAuthoritativeMemberNode() == null ? null: sm.getAuthoritativeMemberNode().getValue(), 
1288
				sm.getDateSysMetadataModified() == null ? null: sm.getDateSysMetadataModified().getTime(),
1289
				sm.getSubmitter() == null ? null: sm.getSubmitter().getValue(), 
1256 1290
                sm.getIdentifier().getValue(),
1257
                sm.getObjectFormat().getFmtid().getValue(),
1291
                sm.getObjectFormat() == null ? null: sm.getObjectFormat().getFmtid().getValue(),
1258 1292
                sm.getSize(),
1259 1293
                replicationAllowed, 
1260 1294
                numberReplicas);
1261 1295
        
1262 1296
        // add provenance information
1263 1297
        String guid = sm.getIdentifier().getValue();
1298
        List<Identifier> idList = null;
1264 1299
        List<String> targetGuids = null;
1265 1300
        String relationship = null;
1266 1301
        
1267 1302
        relationship = "obsoletedBy";
1268 1303
        targetGuids = new ArrayList<String>();
1269
        for (Identifier id: sm.getObsoletedByList()) {
1270
        	targetGuids.add(id.getValue());
1304
        idList = sm.getObsoletedByList();
1305
        if (idList != null) {
1306
	        for (Identifier id: idList) {
1307
	        	targetGuids.add(id.getValue());
1308
	        }
1309
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1271 1310
        }
1272
        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1273
        
1274 1311
        relationship = "obsoletes";
1275 1312
        targetGuids = new ArrayList<String>();
1276
        for (Identifier id: sm.getObsoleteList()) {
1277
        	targetGuids.add(id.getValue());
1313
        idList = sm.getObsoleteList();
1314
        if (idList != null) {
1315
	        for (Identifier id: idList) {
1316
	        	targetGuids.add(id.getValue());
1317
	        }
1318
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1278 1319
        }
1279
        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1280 1320
        
1281 1321
        relationship = "describes";
1282 1322
        targetGuids = new ArrayList<String>();
1283
        for (Identifier id: sm.getDescribeList()) {
1284
        	targetGuids.add(id.getValue());
1323
        idList = sm.getDescribeList();
1324
        if (idList != null) {
1325
	        for (Identifier id: idList) {
1326
	        	targetGuids.add(id.getValue());
1327
	        }
1328
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1285 1329
        }
1286
        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1287 1330
        
1288 1331
        relationship = "describedBy";
1289 1332
        targetGuids = new ArrayList<String>();
1290
        for (Identifier id: sm.getDescribedByList()) {
1291
        	targetGuids.add(id.getValue());
1333
        idList = sm.getDescribedByList();
1334
        if (idList != null) {
1335
	        for (Identifier id: idList) {
1336
	        	targetGuids.add(id.getValue());
1337
	        }
1338
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1292 1339
        }
1293
        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1294 1340
        
1295 1341
        relationship = "derivedFrom";
1296 1342
        targetGuids = new ArrayList<String>();
1297
        for (Identifier id: sm.getDerivedFromList()) {
1298
        	targetGuids.add(id.getValue());
1343
        idList = sm.getDerivedFromList();
1344
        if (idList != null) {
1345
	        for (Identifier id: idList) {
1346
	        	targetGuids.add(id.getValue());
1347
	        }
1348
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1299 1349
        }
1300
        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1301 1350
                
1302 1351
        // save replication policies
1303 1352
        if (replicationPolicy != null) {

Also available in: Unified diff