Advanced Techniques - Importing files
With the
FileUCHelper, any number of files can
can be imported into an Intrexx application as a file attachment. In this
example, a time-controlled process that uses Groovy will be used to search
through a directory for .png files and then write these to an application
as an attachment. You can download an example application, process and four
PNG image files
here.
Unzip the downloaded file. Here, you find the directory
image-files-png that contains four PNG files,
which you can use for testing, and the file
advanced-techniques-import-files-app-process.zip.
These can be
imported as usual.
Further information regarding the class
FileUCHelper
can be found
here. In principle, the following methods are available:
- copyFileToIntrexx()
copies files to Intrexx, without altering them at the file system level
- deleteFileFromIntrexx()
deletes files from Intrexx
- moveFileToIntrexx()
removes files from the file system and adds them to Intrexx
The example application possesses a data group that uses a
GUID as the data type of the primary key.
This data type can be selected when you create a new data group.
Furthermore, the data group has a file data field.
The Overview page has a table that is connected to the data field from
the data group.
The example process has a
Timer with the corresponding
Timer event handler and a
Groovy script action. The
properties dialog of the Groovy script action
can be opened by double-clicking on it. There, switch to the
Script tab and open the Intrexx editor. You'll find
the following Groovy script there.
//The FileUCHelper must be imported as it is not
//directly available in Groovy.
import de.uplanet.lucy.server.businesslogic.util.FileUCHelper
import groovy.io.FileType
// Connection to portal database
def conn = g_dbConnections.systemConnection
// Source directory
def path = 'c:/img/'
// Three sub-directory levels of the source directory should be searched
// for .png and .PNG files
new File(path).traverse(
type:FileType.FILES,
nameFilter:~/.+\.(?i)png$/,
maxDepth:3
){ pngFile ->
// In the closure, each PNG file is made available as a java.io.File under
// the pngFile variable
// For each file, a data record is created which the files will later
// be attached to
// The GUID is the GUID of the data group in the application
def id = newGuid()
g_dbQuery.executeUpdate(conn, "INSERT INTO DATAGROUP('6D717F5376CFF8B1495B3C13C6C61906AA032134') (STRID) VALUES (?)") {
setString(1, id)
}
// Now, the file can be attached to the data set; the GUID here is that
// of the file data field
// The source file will be moved, and will therefore no longer
// be found in the source directory
FileUCHelper.moveFileToIntrexx(g_context, pngFile, "4FB189C11F03607059E658EDBB48602BD7626A04", id, false)
}
Replace the path
c:/img/ with the name of the
directory where the images, which you'd like to import, are stored. You can,
of course, import other file types such as PDF files. The script then needs
to be adjusted accordingly.
|
The executor of the portal service must have write access to the
directory where the files are located. This is especially important
for network drives. If a directory contains more than just png
files, the file extensions need to be checked.
|
Replace the GUIDs for the data group and data field in the Groovy script with
the corresponding GUIDs from your application. You can select your target
application in the area
Application structure and determine the respective GUIDs there. After you've
done that, close the editor and the properties dialog of the Groovy script
action by clicking on
OK. Save the process and
start the Timer from the
context menu.
Below, you can see the files in the target application.