Delete files from directory
Here is my code. Problem will be stated at the end.
def deleteDate = startDate.minus(5).format(“MM-dd-yyyy”)
loggerApi.info(“Delete Date:” + deleteDate.toString())
for (file in listOfFiles)
{
fileId = file.getFile().getId().toString()
//loggerApi.info("File ID: " + fileId)
fileName = file.getFile().getName()
//loggerApi.info("File Name :" + fileName)
//--- get the date the XL was created
def fileCreateDate = file.getCreatedOn()
def filecreateddate = new Date(fileCreateDate)
def cleanUploadDate = filecreateddate.format("MM-dd-yyyy")
//loggerApi.info("upload date : " + cleanUploadDate)
if (fileName.contains("Technical Asset Activity"))
{
loggerApi.info("directory file : " + fileName + " Created On : " + cleanUploadDate.toString() + " Delete Date : " + deleteDate.toString())
if (cleanUploadDate <= deleteDate)
{
loggerApi.info("File Deleted : " + fileName)
file.delete()
}
}
}
The code works just great (thanks to all of you). However, it does not like the “file.delete” statement.
No signature of method: com.collibra.dgc.core.api.model.instance.impl.AttachmentImpl.delete() is applicable for argument types: () values: []
Do I need a special import perhaps?
michaelwalter
Posted 3 years ago · Edited 2 years ago·Last reply 3 years ago
4 comments
arthurburkhardt
·3 years ago · EditedThe code I provided does not fit directly into your script.
In this case, you named your attachment
filein your loop.The code would then be:
But I would recommend to name the variable
attachmentinsteadmichaelwalter
OP3 years ago · EditedStill having problems. The log says: Caused by: javax.script.ScriptException: com.collibra.common.api.exception.ApiEntityNotFoundException: com.collibra.common.exception.EntityNotFoundException: attachmentNotFound
Here is the code in its current state:
listOfFiles = attachmentApi.findAttachments(FindAttachmentsRequest.builder()
.baseResourceId([UUID.fromString(“9f7b290d-8d1e-4307-b96a-fbdd085f172b”)]) //data dictionaries community
.build())
.getResults()
// – set the date for deletion to today - 30 days
def deleteDate = startDate.minus(7).format(“yyyy-MM-dd”)
loggerApi.info(“Delete Date:” + deleteDate.toString())
for (file in listOfFiles)
{
fileId = file.getFile().getId().toString()
FileName = file.getFile().getName()
}
I’m kind of lost here…
michaelwalter
OP3 years ago · EditedThanks. I will change the date format and try the code you suggested.
arthurburkhardt
·3 years ago · EditedNope, but I’m not sure what are the files management rules on Collibra.
There is the attachment and the file. I imagine the attachment is the link to the asset and the file the actual content, but are files automatically purged when there is no attachment?
As a side note, you might experience bugs because you are comparing strings instead of dates. It would work if you used ISO standards (yyyy-MM-dd), but not with the US format.
“01-01-2023” < “12-28-2022”
I would strongly recommend to keep it to longs or dates.