TIF ENOVIA/3DExperience Connector - Custom Job
You may in some cases need to create a job having customized logic. This is done by defining the class implementing the custom job logic inside the Executor tag as shown below.
<Job>
<Executor className="com.acme.integration.executor.MyJobExecutor" />
</Job>
The old format where the className was expressed as the body text of the Executor element is still supported However, using the className attribute is preferred (see note below about transaction type). |
The class must implement the interface com.technia.tif.enovia.job.JobExecutor
.
This interface is defined like below.
package com.technia.tif.enovia.job;
import com.technia.tif.core.ConfigurationException;
import com.technia.tif.core.ExtractionException;
import com.technia.tif.core.ValidationException;
import com.technia.tif.core.annotation.API;
/**
*
* @author Technia
* @since 31 okt 2012
*/
@API
public interface JobExecutor {
/**
* Executes the job using the provided data as input for the execution
*
* @param job The job to be executed
* @throws ConfigurationException May be thrown to indicate error in the
* configuration
* @throws ExtractionException May be thrown to indicate error while
* extracting data
* @throws ValidationException May be thrown to indicate error when
* validating the data being used/sent.
*/
void perform(EnoviaJob job) throws ExtractionException,
ConfigurationException,
ValidationException;
}
Custom jobs support job events for handling errors etc. Read more in the Job Events chapter.
Transaction Type
By default, TIF does not start a transaction inside the ENOVIA/3DEXPERIENCE database for the custom executor.
To change it, you can do so like the example below illustrates.
<Job>
<Executor className="com.acme.MyExecutor" txType="read" />
...
</Job>
The below table describes values that are accepted for the attribute txType
.
Value | Description |
---|---|
none |
Does not start transaction. |
read |
Starts read transaction. |
update |
Starts update transaction. |
With Context
Per default, the system user context as TIF is configured with will be used when executing the job. However, to customize the context this can be done like shown below:
<Job>
<Executor className="com.acme.MyExecutor">
<WithContext user="specific_user" />
</Executor>
</Job>
The <WithContext>
element controls what context to be used for the operation.
Per default, if omitted, the system user context will be used for the operation.
In most situations, the system user is the person you want to run the use case as in order to not having access rights issues while reading the required data.
However, in some cases you may want to limit the access for some reason.
The <WithContext>
element supports the following attributes.
Attribute | Required | Description |
---|---|---|
user |
No |
If omitted, the super user will be used |
securityContext |
No |
Defines the security context to be used |
useDefaultSecurityContext |
No |
If set to true, the default security context for the user will be used. The used user must have a default security context otherwise an error will be raised. |
Store Payload
It is possible to store outbound payload that is visible in Admin UI. Use com.technia.tif.enovia.job.log.Logger
.
For example:
import com.technia.tif.enovia.job.EnoviaJob;
import com.technia.tif.enovia.job.JobExecutor;
import com.technia.tif.enovia.job.log.Logger;
import com.technia.tif.enovia.payload.PayloadUtils;
public class MyJobExecutor implements JobExecutor {
@Override
public void perform(EnoviaJob job) {
Logger.storeOutboundPayload(job, new PayloadDataBuffer().append("Hello World!"));
}
}
Access Input Payload
Input payload provided by parent job can be accessed using com.technia.tif.enovia.payload.PayloadUtils
utility class.
Example code:
package com.acme.tif.executor;
import com.technia.tif.core.ExtractionException;
import com.technia.tif.enovia.job.EnoviaJob;
import com.technia.tif.enovia.job.JobExecutor;
import com.technia.tif.enovia.payload.PayloadData;
import com.technia.tif.enovia.payload.PayloadUtils;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
public class MyJobExecutor implements JobExecutor {
@Override
public void perform(EnoviaJob job) throws ExtractionException {
PayloadData data = PayloadUtils.getInputPayload(job);
try (InputStream in = data.getInputStream()) {
// TODO: Do something with the input stream, e.g:
String string = IOUtils.toString(in, data.getEncoding());
} catch (IOException e) {
throw new ExtractionException(e);
}
}
}