public static void validateUpdate ( FieldMapping oldFieldMapping , FieldMapping newFieldMapping ) throws TypeUpdateException { Map < String , AttributeInfo > newFields = newFieldMapping . fields ; for ( AttributeInfo attribute : oldFieldMapping . fields . values ( ) ) { if ( newFields . containsKey ( attribute . name ) ) { AttributeInfo newAttribute = newFields . get ( attribute . name ) ; //If old attribute is also in new definition, only allowed change is multiplicity change from REQUIRED to OPTIONAL if ( ! newAttribute . equals ( attribute ) ) { if ( attribute . multiplicity == Multiplicity . REQUIRED && newAttribute . multiplicity == Multiplicity . OPTIONAL ) { continue ; } else { throw new TypeUpdateException ( "Attribute " + attribute . name + " can't be updated" ) ; } } } else { //If old attribute is missing in new definition, return false as attributes can't be deleted throw new TypeUpdateException ( "Old Attribute " + attribute . name + " is missing" ) ; } } //Only new attributes Set < String > newAttributes = new HashSet <> ( ImmutableList . copyOf ( newFields . keySet ( ) ) ) ; newAttributes . removeAll ( oldFieldMapping . fields . keySet ( ) ) ; for ( String attributeName : newAttributes ) { AttributeInfo newAttribute = newFields . get ( attributeName ) ; //New required attribute can't be added if ( newAttribute . multiplicity == Multiplicity . REQUIRED ) { throw new TypeUpdateException ( "Can't add required attribute " + attributeName ) ; } } }
Validates that the old field mapping can be replaced with new field mapping