Project

General

Profile

« Previous | Next » 

Revision 9166

Added by Jing Tao over 9 years ago

Add the code to check if a user tries to modify an immutable field on system metadata.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1563 1563
              }
1564 1564
          }
1565 1565
      }
1566
      checkModifiedImmutableFields(currentSysmeta, sysmeta);
1566 1567
      // do the actual update
1567 1568
      this.updateSystemMetadata(sysmeta);
1568 1569
      
......
1580 1581
      
1581 1582
      return true;
1582 1583
	}
1584
	
1585
	/*
1586
	 * Check if the newMeta modifies an immutable field. 
1587
	 */
1588
	private void checkModifiedImmutableFields(SystemMetadata orgMeta, SystemMetadata newMeta) throws InvalidRequest, InvalidSystemMetadata{
1589
	    if(orgMeta != null && newMeta != null) {
1590
	        if(newMeta.getIdentifier() == null) {
1591
	            throw new InvalidSystemMetadata("The new version of the system metadata is invalid since the identifier is null","4956");
1592
	        }
1593
	        if(!orgMeta.getIdentifier().equals(newMeta.getIdentifier())) {
1594
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's identifier "+newMeta.getIdentifier().getValue()+" is "+
1595
	                  "different to the orginal one "+orgMeta.getIdentifier().getValue(), "4869");
1596
	        }
1597
	        if(newMeta.getSize() == null) {
1598
	            throw new InvalidSystemMetadata("The new version of the system metadata is invalid since the size is null","4956");
1599
	        }
1600
	        if(!orgMeta.getSize().equals(newMeta.getSize())) {
1601
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's size "+newMeta.getSize().longValue()+" is "+
1602
	                      "different to the orginal one "+orgMeta.getSize().longValue(), "4869");
1603
	        }
1604
	        if(newMeta.getChecksum()!= null && orgMeta.getChecksum() != null && !orgMeta.getChecksum().getValue().equals(newMeta.getChecksum().getValue())) {
1605
	            logMetacat.error("The request is trying to modify an immutable field in the SystemMeta: the new system meta's checksum "+newMeta.getChecksum().getValue()+" is "+
1606
                        "different to the orginal one "+orgMeta.getChecksum().getValue());
1607
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's checksum "+newMeta.getChecksum().getValue()+" is "+
1608
                        "different to the orginal one "+orgMeta.getChecksum().getValue(), "4869");
1609
	        }
1610
	        if(orgMeta.getSubmitter() != null && newMeta.getSubmitter() != null && !orgMeta.getSubmitter().equals(newMeta.getSubmitter())) {
1611
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's submitter "+newMeta.getSubmitter().getValue()+" is "+
1612
                        "different to the orginal one "+orgMeta.getSubmitter().getValue(), "4869");
1613
	        }
1614
	        
1615
	        if(orgMeta.getDateUploaded() != null && newMeta.getDateUploaded() != null && !orgMeta.getDateUploaded().equals(newMeta.getDateUploaded())) {
1616
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's date of uploaded "+newMeta.getDateUploaded()+" is "+
1617
                        "different to the orginal one "+orgMeta.getDateUploaded(), "4869");
1618
	        }
1619
	        
1620
	        if(orgMeta.getOriginMemberNode() != null && newMeta.getOriginMemberNode() != null && !orgMeta.getOriginMemberNode().equals(newMeta.getOriginMemberNode())) {
1621
	            throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's orginal member node  "+newMeta.getOriginMemberNode().getValue()+" is "+
1622
                        "different to the orginal one "+orgMeta.getOriginMemberNode().getValue(), "4869");
1623
	        }
1624
	        
1625
	        if(orgMeta.getSeriesId() != null && newMeta.getSeriesId() != null && !orgMeta.getSeriesId().equals(newMeta.getSeriesId())) {
1626
                throw new InvalidRequest("The request is trying to modify an immutable field in the SystemMeta: the new system meta's series id  "+newMeta.getSeriesId().getValue()+" is "+
1627
                        "different to the orginal one "+orgMeta.getSeriesId().getValue(), "4869");
1628
            }
1629
	        
1630
	    }
1631
	}
1583 1632
  
1584 1633
  /**
1585 1634
   * Given a Permission, returns a list of all permissions that it encompasses

Also available in: Unified diff