Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Stop publish document process if Document revision number is not numeric and it is not higher than previous/existing latest revision
Groovy Script - Stop publish document process if Document revision number is not numeric and it is not higher than previous/existing latest revision
Updated this week

Description: Sample groovy script to stop publish document process if Document revision number is not numeric and it is not higher than previous/existing latest revision

Context: Document

Remark: Accessible in 'Pre' task mode only

Script:

def execute(){

/* PRE Validation: Sample script to stop publish document process if Rev is not numeric and it is not higher than previous/existing latest revision */

boolean status = true;

String message = "";

// Get DocRef of current revision

DocumentVO document = documentService.getDocumentDetails();

String docRef = document.getDocRef();

Set<String> docRefSet = new HashSet<String>();

docRefSet.add(docRef);

// Get Folder Path of current revision

String folderPath; //sample folder path: Asite Project\Documents

if(document.getFileFolderStructure() == null || document.getFileFolderStructure().isEmpty()) {

folderPath = documentService.getFolderPath(document);

}else {

folderPath = document.getFileFolderStructure();

}

// Rev should be numeric only

String revision_current = document.getRevision();

if(!revision_current.matches("[0-9]+")){

status = false;

message = "Rev should be numeric only.";

}

if(status){

// Fetch existing revisions by DocRef and Folder Path

HashMap mapRevDetailsOptions = new HashMap<>();

mapRevDetailsOptions.put(RevisionDetailsOption.LATEST_REVISION, true); // here Only RevisionDetailsOption.ALL_REVISION and RevisionDetailsOption.LATEST_REVISION are supported.

Map<String,DocumentVO> mapDocumentVO = documentService.getDocumentsByDocRefs(docRefSet, folderPath, mapRevDetailsOptions); //folderPath should be with Project name. Response Map will have documentRef#revisionId as key and DocumentVO as its value.

// Check for higher number of Rev attribute

if(!mapDocumentVO.isEmpty()) {

Map.Entry<String, DocumentVO> entry = mapDocumentVO.entrySet().iterator().next();

String docRef_revision = entry.getKey();

DocumentVO document_previous = entry.getValue();

String revision_previous = document_previous.getRevision();

int revision_pre = Integer.parseInt(revision_previous);

int revision_cur = Integer.parseInt(revision_current);

if(! (revision_cur > revision_pre) ){

status = false;

message = "Rev should be higher than previous/existing latest : "+ revision_previous;

}

}

}

if(!status){

document.setResponseStatus(status);

document.setResponseMessage(message);

}

return document;

}



Did this answer your question?