Skip to main content

Groovy Script - Stop Publishing Files on Files or Placeholders for Associated Records

Description: Sample Groovy Script to stop publishing Files on Files or Placeholders for associated records.

Context: Document

Document Type: File/Placeholder

Remark: Accessible in Pre task mode only

Script:

def execute(){
/**************** Configurable Parameter Section *******************************************************/
String status="Approved";
boolean Include_Deactivated=false;
int associationType =IGroovyConstant.ASSOC_PARENT_DOCS; //other option ASSOC_PARENT_DOCS = 1,ASSOC_CHILD_DOCS = 2,ASSOC_PARENT_AND_CHILD_DOCS = 3
/******************************************************************************************************/

boolean success=true;
//get current upload doc details.
DocumentVO document = documentService.getDocumentDetails();
String docRef = document.getDocRef();
//Prepare data to get previous document details like document or place holder.
Set<String> docRefs = new HashSet<>();
docRefs.add(docRef);
// set folder path details
String folderPath; //sample folder path: Asite Project\Documents
if(document.getFileFolderStructure() == null || document.getFileFolderStructure().isEmpty()) {
folderPath = documentService.getFolderPath(document);
}else {
folderPath = document.getFileFolderStructure();
}

HashMap mapRevDetailsOptions = new HashMap<>();
mapRevDetailsOptions.put(RevisionDetailsOption.LATEST_REVISION, true);
Map<String,DocumentVO> revisionsMap = documentService.getDocumentsByDocRefs(docRefs, folderPath, mapRevDetailsOptions);
if (revisionsMap != null && !revisionsMap.isEmpty() && revisionsMap.size() == 1) {
// if previous document found then get Associated doc list parent and child both
DocumentVO documentPre = revisionsMap.entrySet().iterator().next().getValue();

List<DocumentVO> AssociationList = documentService.getParentandChildAssociationList(documentPre,Include_Deactivated,associationType);
//check all parent doc status for document upload.
if(AssociationList!=null && !AssociationList.isEmpty()){
for(DocumentVO ParentAssdocVO: AssociationList){
if(!(status.equals(ParentAssdocVO.getStatus()))){
success=false;
break;
}
}

}else{
document.setResponseStatus(false);
document.setResponseMessage("Document Upload Restriction - Parent Link Document Missing for the doc ref : "+docRef);
}

}
//if any one parent document does not match with a configured status then send message to user.
if(!success){
document.setResponseStatus(false);
document.setResponseMessage("Document Upload Restriction - Parent document status is not a :"+status);
}

return document;
}
Did this answer your question?