private static void removeRedundant(Node nodeVersioning) throws Exception{
    VersionHistory versionHistory = nodeVersioning.getVersionHistory();
    String baseVersion = nodeVersioning.getBaseVersion().getName();
    String rootVersion = nodeVersioning.getVersionHistory().getRootVersion().getName();
    VersionIterator versions = versionHistory.getAllVersions();
    Date currentDate = new Date();
    Map<String, String> lstVersions = new HashMap<String, String>();
    List<String> lstVersionTime = new ArrayList<String>();
    while (versions.hasNext()) {
      Version version = versions.nextVersion();
      if(rootVersion.equals(version.getName()) || baseVersion.equals(version.getName())) continue;

      if (maxLiveTime!= DOCUMENT_AUTO_DEFAULT_VERSION_EXPIRED &&
              currentDate.getTime() - version.getCreated().getTime().getTime() > maxLiveTime) {
        versionHistory.removeVersion(version.getName());
      } else {
        lstVersions.put(String.valueOf(version.getCreated().getTimeInMillis()), version.getName());
        lstVersionTime.add(String.valueOf(version.getCreated().getTimeInMillis()));
      }
    }
    if (maxAllowVersion <= lstVersionTime.size() && maxAllowVersion!= DOCUMENT_AUTO_DEFAULT_VERSION_MAX) {
      Collections.sort(lstVersionTime);
      String[] lsts = lstVersionTime.toArray(new String[lstVersionTime.size()]);
      for (int j = 0; j <= lsts.length - maxAllowVersion; j++) {
        versionHistory.removeVersion(lstVersions.get(lsts[j]));
      }
    }
  }
private static void removeRedundant ( Node nodeVersioning ) throws Exception { VersionHistory versionHistory = nodeVersioning . getVersionHistory ( ) ; String baseVersion = nodeVersioning . getBaseVersion ( ) . getName ( ) ; String rootVersion = nodeVersioning . getVersionHistory ( ) . getRootVersion ( ) . getName ( ) ; VersionIterator versions = versionHistory . getAllVersions ( ) ; Date currentDate = new Date ( ) ; Map < String , String > lstVersions = new HashMap < String , String > ( ) ; List < String > lstVersionTime = new ArrayList < String > ( ) ; while ( versions . hasNext ( ) ) { Version version = versions . nextVersion ( ) ; if ( rootVersion . equals ( version . getName ( ) ) || baseVersion . equals ( version . getName ( ) ) ) continue ; if ( maxLiveTime != DOCUMENT_AUTO_DEFAULT_VERSION_EXPIRED && currentDate . getTime ( ) - version . getCreated ( ) . getTime ( ) . getTime ( ) > maxLiveTime ) { versionHistory . removeVersion ( version . getName ( ) ) ; } else { lstVersions . put ( String . valueOf ( version . getCreated ( ) . getTimeInMillis ( ) ) , version . getName ( ) ) ; lstVersionTime . add ( String . valueOf ( version . getCreated ( ) . getTimeInMillis ( ) ) ) ; } } if ( maxAllowVersion <= lstVersionTime . size ( ) && maxAllowVersion != DOCUMENT_AUTO_DEFAULT_VERSION_MAX ) { Collections . sort ( lstVersionTime ) ; String [ ] lsts = lstVersionTime . toArray ( new String [ lstVersionTime . size ( ) ] ) ; for ( int j = 0 ; j <= lsts . length - maxAllowVersion ; j ++ ) { versionHistory . removeVersion ( lstVersions . get ( lsts [ j ] ) ) ; } } }
Remove redundant version
- Remove versions has been expired
- Remove versions over max allow
@param nodeVersioning
@throws Exception