Skip to main content Skip to complementary content

Creating a Java archive for the user-defined indicator

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

  1. Define the target platform:
    1. In Eclipse, select Preferences to display the Preferences window.
    2. Expand Plug-in Development, select Target Platform and click Add... to open a view where you can create the target definition.
    3. Select the Nothing: Start with an empty target definition option and click Next.
    4. In the Name field, enter a name for the new target definition and click Next.
    5. Select Installation from the Add Content list and click Next.
    6. Use the Browse... button to set the path of the installation directory and click Next.
      Location of the Browse... button.

      The new target definition is displayed in the location list.

      The new target definition is listed in the Locations tab.
    7. Click Finish to close the dialog box.
  2. Create a Java archive for the user defined indicator
    1. In Eclipse, check out the project from Git.

      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.

      Example of the four Java classes from the Java project.

      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();
          }
      
      }
    2. Modify the code of the methods that follow each @Override according to your needs.
    3. 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
    4. Save your modifications.
    5. 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.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!