Before creating a Java archive for the user defined indicator, you must define,
in Eclipse, the target platform against which the workspace plugins will be compiled and
tested.
Before you begin
You have selected the
Profiling
perspective.
Procedure
-
Define the target platform:
-
In Eclipse, select Preferences to display the
Preferenceswindow.
-
Expand Plug-in Development, select Target
Platform and click Add... to open a view
where you can create the target definition.
-
Select the Nothing: Start with an empty target
definition option and click Next.
-
In the Name field, enter a name for the new target
definition and click Next.
-
Select Installation from the Add
Content list and click Next.
-
Use the Browse... button to set the path of the
installation directory and click Next.
The new target definition is displayed in the location list.
-
Click Finish to close the dialog box.
-
Create a Java archive for the user defined indicator
-
In Eclipse, check out the project from GIT at https://github.com/Talend/tdq-studio-se/tree/master/sample/test.myudi.
In this Java project, you can find four Java classes that
correspond to the four indicator categories listed in the
Indicator Category view in the
indicator editor.
Each one of these Java classes extends the
UserDefIndicatorImpl
indicator. The figure
below illustrates an example using the
MyAvgLength
Java class.
package test.udi;
import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;
/**
* @author mzhao
*
* A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
* real value. It implements the minimum number of required methods.
*/
public class MyAvgLength extends UserDefIndicatorImpl {
private double length = 0;
@Override
public boolean reset() {
super.reset();
length = 0;
return true;
}
@Override
public boolean handle(Object data) {
super.handle(data);
// an indicator which computes the average text length on data which are more than 2 characters (this means that
// text values with less than 2 characters are not taken into account).
int dataLength = (data != null) ? data.toString().length() : 0;
if (dataLength > 2) {
length += dataLength;
}
return true;
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
*/
@Override
public boolean finalizeComputation() {
value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
return super.finalizeComputation();
}
}
-
Modify the code of the methods that follow each
@Override
according to your needs.
- Optional:
Use the following methods in your code to retrieve the indicator
parameters:
Method |
Description |
Indicator.getParameter()
|
Returns an IndicatorParameters
object |
IndicatorParameters.getIndicatorValidDomain()
|
Returns a Domain object |
Domain.getJavaUDIIndicatorParameter()
|
Returns a list of JavaUDIIndicatorParameter
that stores each key/value pair that defines the
parameter |
-
Save your modifications.
-
Using Eclipse, export this new Java archive.
Results
The Java archive is now ready to be attached to any Java indicator you want to create
in the
Profiling
perspective.