Skip to main content

Other Files

Execute a series of SQL statements, stored in the specified file.​

Syntax

var rows = utils.executeSqlFile(
sqlFile,
dataSourceId,
separatedTransaction,
interruptExecution,
params
)

Details

ArgumentDescription
rowsint value: number of processed rows
sqlFileabsolute path + file name, related to the SQL script to execute
dataSourceIdnum value; it can be null and used to specify a different db to use with the sql statement
separatedTransactionboolean value; if true, the SQL instruction is executed on a separated transaction which is immediately committed (as for a REQUIRE_NEW EJB directive)
interruptExecutionboolean value; if true, an erroneous SQL instruction fires an exception that will interrupt the javascript execution; if false, the js execution will continue
paramsthis is optional: you can omit it at all, or you can specify a series of arguments separated by a comma (do not use []); these additional parameters represent values which replace ? symbols in the sql statement.

An :XXX variable can be replaced by vo or params values

Send a list of files stored to an FTP server inside the specified remote folder​

Files to send must be in the server side file system

Syntax

var ok = utils.sendFiles(protocol, host, port, useSSL, username, password, toDir, filePaths);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
portFTP server port
useSSL - boolean flag, used to specify if FTPS must be used
ArgumentDescription
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
toDirremote folder, within the FTP server, where files must be copied
filePathslist of files stored in the server side file system (expressed with absolute path) to copy within the FTP server

Send a single file to the FTP server and store it in the specified folder​

Syntax

var ok = utils.sendFile(protocol, host, port, useSSL, username, password, destFile, sourceFile);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
portFTP server port (e.g. 21)
useSSL - boolean flag, used to specify if FTPS must be used
ArgumentDescription
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
destFilefolder in the FTP server + destination file name where storing the file
sourceFilesourceFile absolute path in the server file system + file name, related to the file to read

Read a remote file from FTP server and copy it​

Read a remote file, stored within the FTP server and copy it into the specified absolute file, related to the server.

Syntax

var ok = utils.getFile(protocol, host, port, useSSL, username, password, ftpDir, ftpFileName, localFile);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
port

FTP server port (e.g. 21)

useSSLboolean flag, used to specify if FTPS must be used
ArgumentDescription
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
ftpDirremote folder, within the FTP server, where the file to retrieve is currently stored
ftpFileNamefile name to retrieve, stored within the specified remote folder
localFilepath+file name, where the remote file must be copied, in the server file system

Read a list of remote file names​

all files must be stored in the same remote folder within the FTP server; file names are filtered according to the specified filter condition.

Syntax

var listOfFileNames = utils.getFiles(protocol, host, port, useSSL, username, password, remoteDir, fileFilter);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
portFTP server port (e.g. 21)Argument
useSSLflag used to define whether using SSL
Description
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
remoteDirremote folder, within the FTP server, where files are stored
fileFilter(optional) parameter to use to filter files to read (e.g. *.jpg)
listOfFileNameslist of file names (String objects) which satisfy the filter condition

Delete a single file to the FTP server​

Syntax

var ok = utils.deleteFTPFile(protocol, host, port, useSSL, username, password, remoteDir, fileName);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
portFTP server port (e.g. 21)
useSSLboolean flag, used to specify if FTPS must be used
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
remoteDirfolder in the FTP server
fileNamefile name

Rename or move a single file to the FTP server​

Syntax

var ok = utils.renameFTPFile(protocol, host, port, useSSL, username, password, fromFileName, toFileName);

Details

ArgumentDescription
protocolFTP, FTPS, SFTP
hostFTP server host
portFTP server port (e.g. 21)
useSSLboolean flag, used to specify if FTPS must be used
usernameusername to use to authenticate to the FTP server
passwordpassword to use to authenticate to the FTP server
fromFileNameabsolute path with file name in the FTP server
toFileNamenew absolute path with file name in the FTP server

Extract a file from Alfresco and save it to the specified local file path.​

Syntax

var success = utils.getAlfrescoDocument(id, fileName, destPath);

Details

ArgumentDescription
idUUID value which identifies the file to retrieve from Alfresco CMS
fileNamefile name related to the specified if
destPathabsolute path related to the A.S. file system, where the file will be saved, once extracted from Alfresco CMS

Read the specified file from the source directory and extract signed data and the embedded document​

The source file is identified starting from the source directory id + fileName.

The embedded document is then saved in the destination directory. The embedded file, if recognized with a MIME type, is renamed to a name having the original name + its real extension. Otherwise, it is saved with the original source file name.

Syntax

var obj = utils.getCertMessage(srcDirectoryId, destDirectoryId, fileName);

Details

ArgumentDescription
srcDirectoryIdid used to identify a source folder in the server file system where the file to read has been stored
destDirectoryIdid used to identify a folder in the server file system when the extracted document will be saved
fileNamefile name inside the specified folder
objembedded document, expressed as a javascript object

The returned javascript object contains the following attributes:

  • expirationDate
  • firstName
  • lastName
  • personId
  • signerCountry
  • signerId
  • signerOrganization
  • personalVatNumber
  • corporateVatNumber
  • corporateName
  • personCountry
  • mimeType - MIME type for the embedded file; e.g. application/xml, application/pdf, etc.
  • destFilePath - absolute path + file name, related to the embedded file

Read the specified file and extract signed data and the embedded document​

The source file is identified through the "srcFileName", containing both the absolute path and the the file name.

The embedded document is then saved in the destination directory. The embedded file, if recognized with a MIME type, is renamed to a name having the original name + its real extension. Otherwise, it is saved with the original source file name.

Syntax

var obj = utils.getCertMessage(srcFileName, destFolder);

Details

ArgumentDescription
srcFileNamepath + file name to analyze
destFolderdestination folder; if not specified, the srcFolder will be used
objembedded document, expressed as a javascript object

The returned javascript object contains the following attributes:

  • expirationDate
  • firstName
  • lastName
  • personId
  • signerCountry
  • signerId
  • signerOrganization
  • personalVatNumber
  • corporateVatNumber
  • corporateName
  • personCountry
  • mimeType - MIME type for the embedded file; e.g. application/xml, application/pdf, etc.
  • destFilePath - absolute path + file name, related to the embedded file

Read a signed PDF file and extract data coming from the embedded certificate​

The source PDF file is identified starting from the source directory id + fileName.

The specified PDF file is signed file, i.e. it contains a certificate; this certificate is then extracted and saved in the destination directory. The certificate file, if recognized with a MIME type, is renamed to a name having the original name + its real extension. Otherwise, it is saved with the original source file name.

Syntax

var obj = utils.getCertMessageFromPdf(Long srcDirectoryId,Long destDirectoryId,String fileName);

Details

ArgumentDescription
srcDirectoryIdid used to identify a source folder in the server file system where the PDF signed file to read has been stored
destDirectoryIdid used to identify a folder in the server file system when the extracted document (the certificate) will be saved
fileNamefile name inside the specified folder
objembedded document, expressed as a javascript object

The returned javascript object contains the following attributes:

  • expirationDate
  • firstName
  • lastName
  • personId
  • signerCountry
  • signerId
  • signerOrganization
  • personalVatNumber
  • corporateVatNumber
  • corporateName
  • personCountry
  • mimeType - MIME type for the embedded file; e.g. application/xml, application/pdf, etc.
  • destFilePath - absolute path + file name, related to the embedded file
  • signDate - the sign date, expressed as a javascript Date

Create a zip file containing the list of passed files ​

Syntax

var ok = utils.zipFiles(baseDir,files,zipFile,deleteFilesAfterZip);

Details

ArgumentDescription
baseDirbase dir used to calculate the entry in the zip (i.e. "C:/xxx/yyy/")
filesfiles to zip (each including an absolute path, "C:/xxx/yyy/fileName.csv")
zipFilezip file to create, including the absolute path (i.e. "C:/aaa/bbb/zipFileName.zip")
deleteFilesAfterZipflag used to decide if input files must be deleted after the zip creation

Copy the source file to the destination file ​

Since "destFile" contains a file name too, the source file can be renamed when copied.

Syntax

var ok = utils.copyFile(srcFile, destFile, replaceExistingFile, deleteSourceFile);

Details

ArgumentDescription
srcFileabsolute path + file name
destFileabsolute path + file name
replaceExistingFileflag used to replace the already existing destination file; if set to false and the destination file already exists, the copy process would be interrupted and the returned value would be false
deleteSourceFileflag used to delete the source file, once the file has been copied to the destination path

Delete a file previously stored in a specific path ​

Syntax

var outcome = utils.deleteFile(String fileName,Long directoryId);

Details

ArgumentDescription
fileNameit can includes a subpath to append to the base path specified through directoryId
directoryIddirectory identifier, used to define the absolute path, in the central server, where the file will be stored; if null, there must be one only entry for this application
outcometrue in case of the operation has beenexecuted successfully, an exception otherwise

Read the specified URL and convert the HTML content to an image and save it to the server file system.​

Syntax

utils.convertUrlToImage(String url, String imagePath);

Details

url: URL to read, related to HTML content
imagePath: absolute path + image file name where saving the image
fire an exception in case of errors.

Reading the HTML content and convert it to an image and save the image to the server file system.​

Syntax

utils.convertHtmlToImage(String html, String imagePath);

Details

html: HTML content to read
imagePath: absolute path + image file name where saving the image
fire an exception in case of errors.

Retrieving the file length​

In case you need to retrieve the dimension of a file stored in the server file system, you can use this method (since 6.0.2).

Syntax

var length = utils.getFileLength(String absolutePath);