Data import-export
To let external software to exchange data with his database, Opera mainly relay on the exchange of XML files.
Both operac tool and OperaJM GUI can natively import and export data using XML files.
For ntve import/export functions a dedicated table (OPERAFED) contains a list of import/export activities nmed FED.
Every activty contains several fields. Here the most important:
-
Name
-
Type - the type field tells Opera the type of data to exchange and the direction of the communication
-
Target directory - a path where to get or put the data on the desired format
-
Driver directory - Where the resources are located. Resources can be any kind file often like:
-
scripts like batch files or PowerShell scripts
-
images like logos
-
Extensible Stylesheet Language files (.xsl) used to translate XML content on other formats like text, csv, SQL or XML with a different structure
- Script - a commnd-line cript to execute
The import-export table is accessible from OperaJM main menu through the Tools->Data import/export choice.
To trigger the FED several modes are supported:
-
GUI - OperaJM shows the export button on the jobs management and to execute the export activity on click.
-
Command-line -
operac.exewill exec the export. A specific command line switch will tell operac the name of the FED to execute. This shell command can also be added to the Windows Scheduler. -
Status - OperaJM automatically exports all the jobs in a certain job status and once exportes change the job status to another to avoid to export the same job again and again. Ex. the job status
Export to CSVtriggers the activity and once finshed with no errors the job status will be changed inExported -
On Save - Every time a job is saved is exported
Export formats
Using a XML parser like Apache xalan you can fetch the data from the XML structure and place it on any kind of format. The most popular formats by the Opera users:
-
CSV
-
Excel - For this format the FED script create a intermediate CSV on the temporary folder and the uses the
csv2xls.exeOpera command-line tool to create a .xls or a .xlsx file -
SQL - The FED script creates a SQL file cntaining SQL INSERT statements and sabe it on the tmporary directory. Than execute the SQL client command-line tool to pass the SQL commnds to the database server
-
API interface - The FED script uses
curlto fetch or to post contents to through the APIs and uses xalan and the Operajson2xml.exeor thexml2json.exetools to manipulate the data
Example
Task: Create a FED to export an existing job on a TAB separated csv file. The CSV file must contain the code of the client and the list of the items with the sell price
FED values
Name: `Job Sales Order Export`
Type: `Jobs`
Directory: `C:\OPERA\exports`
Driver dir: `+sales_orders`
Program: `call "%driverdir%create_csv.bat" "%~1" "%dir%%filename%.csv"`
The predefine keyword Jobs on the Type field tells OperaJM that this FED is about a single job and is in export direction.
Resources
The create_csv.bat file looks like:
set source_XML_file="%~1"
set target_CSV_file="%~2"
xalan\xml-xalan\xalan.exe -o %target_CSV_file% %source_XML_file% %driverdir%opera_job_xml2csv.xsl
The opera_job_xml2csv.xsl file will look like:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
<xsl:output method="text" omit-xml-declaration="yes" indent="no" encoding="UTF-8"/>
<xsl:template match="jobs">
<xsl:text>Job	Client	Position	Description	Quantity	Price	 </xsl:text>
<xsl:for-each select="job">
<xsl:variable name="job" select="."/>
<xsl:for-each select="job_components/component">
<!-- Job -->
<xsl:value-of select="concat($job/job_id,'/',$job/job_year)"/>
<xsl:text>	</xsl:text>
<!-- Client -->
<xsl:value-of select="$job/job_customer/cst_code"/>
<xsl:text>	</xsl:text>
<!-- Position -->
<xsl:value-of select="cmp_position"/>
<xsl:text>	</xsl:text>
<!-- Description -->
<xsl:value-of select="cmp_description"/>
<xsl:text>	</xsl:text>
<!-- Quantity -->
<xsl:value-of select="cmp_quantity"/>
<xsl:text>	</xsl:text>
<!-- Price -->
<xsl:value-of select="cmp_price"/>
<xsl:text>	</xsl:text>
<!-- CRLF -->
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Before executing the script OperaJM will create a temporary directory to store the XML file. Once the execution is finshed the temporary directory will be erased.
Before to exec the script it creates a shell environment with this environment variables:
-
%WORKDIR%- the full path of the temporary directory -
%driverdir%- the full path of the resources. If the Driver dir field of the FED starts with a + the + will be replaced by the Export Filters directory specified on the configuration -
%dir%- the target directory. -
%destination%- like the %dir% when the target in not a directory, like a URL or a database name
then the script is executed and if it's a batch file must be invoked with the command call as it will be invoked from an automatic generated batch file. All the environment varibales containing a filesystem path are \ terminated.