@Override public boolean saveVersion(VersionType versionType){
  MetadataVersion currentVersion=getCurrentVersion();
  String versionName=MetadataVersionNameGenerator.getNextVersionName(currentVersion);
  Date minDate;
  if (currentVersion == null) {
    minDate=null;
  }
 else {
    minDate=currentVersion.getCreated();
  }
  ByteArrayOutputStream os=getMetadataExport(minDate);
  String value=getBodyAsString(StandardCharsets.UTF_8,os);
  createMetadataVersionInDataStore(versionName,value);
  MetadataVersion version=new MetadataVersion();
  version.setName(versionName);
  version.setCreated(new Date());
  version.setType(versionType);
  try {
    String hashCode=HashCodeGenerator.getHashCode(value);
    version.setHashCode(hashCode);
  }
 catch (  NoSuchAlgorithmException e) {
    String message="Exception occurred while generating MetadataVersion HashCode " + e.getMessage();
    log.error(message,e);
    throw new MetadataVersionServiceException(message,e);
  }
  try {
    addVersion(version);
    metadataSystemSettingService.setSystemMetadataVersion(version.getName());
  }
 catch (  Exception ex) {
    String message="Exception occurred while saving a new MetadataVersion " + ex.getMessage();
    log.error(message,ex);
    throw new MetadataVersionServiceException(message,ex);
  }
  return true;
}

@ Override public boolean saveVersion ( VersionType versionType ) { MetadataVersion currentVersion = getCurrentVersion ( ) ; String versionName = MetadataVersionNameGenerator . getNextVersionName ( currentVersion ) ; Date minDate ; if ( currentVersion == null ) { minDate = null ; } else { minDate = currentVersion . getCreated ( ) ; } ByteArrayOutputStream os = getMetadataExport ( minDate ) ; String value = getBodyAsString ( StandardCharsets . UTF_8 , os ) ; createMetadataVersionInDataStore ( versionName , value ) ; MetadataVersion version = new MetadataVersion ( ) ; version . setName ( versionName ) ; version . setCreated ( new Date ( ) ) ; version . setType ( versionType ) ; try { String hashCode = HashCodeGenerator . getHashCode ( value ) ; version . setHashCode ( hashCode ) ; } catch ( NoSuchAlgorithmException e ) { String message = "Exception occurred while generating MetadataVersion HashCode " + e . getMessage ( ) ; log . error ( message , e ) ; throw new MetadataVersionServiceException ( message , e ) ; } try { addVersion ( version ) ; metadataSystemSettingService . setSystemMetadataVersion ( version . getName ( ) ) ; } catch ( Exception ex ) { String message = "Exception occurred while saving a new MetadataVersion " + ex . getMessage ( ) ; log . error ( message , ex ) ; throw new MetadataVersionServiceException ( message , ex ) ; } return true ; }
this method is taking care of 3 steps : 1 . generating a metadata snapshot ( using the exportservice ) 2 . saving that snapshot to the datastore 3 . creating the actual metadataversion entry .
