Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Right-click on your project, and then select New > Class.
    The New Java Class dialog appears.
  2. Enter the appropriate information in the fields provided to define the new Java class:
    1. In the Name field, type “DirectoryNotifier”"DirectoryNotifier".
    2. In the Package field, type “org"org.acme.directorynotifier”directorynotifier".
    3. In the Superclass field, type “com"com.idera.change.notifications.api.AbstractNotifier”AbstractNotifier".
  3. Click Finish to create the new class.

...

  • isReportSupported returns a Boolean value indicating if the notification can include a report. The directory notifier returns true, because reports can be replaced in a directory, but a notification may not support reports. This method is called when creating job editors to determine if the reporting section is shown for this type of notification.
  • sendNotification is called after a job runs and is responsible for the notification. The three parameters are as follows:

    ParameterTypeDescription
    notifierDataiNotifierDataThis instance contains the configuration for the notification of the job just run.
    jobMetaDataMap<String, String>

    This map contains information about the job execution. The keys in the map correspond to entries in the NotificationPropertyEnum.

    For example, to get the data and time of the execution, you would code:

    “jobMetaData"jobMetaData.get(NotificationPropertyEnum.DATE_TIME.getTag())"

    NOTE: The keys are the tag of the enum entries, so ensure that getTag() is called when accessing jobMetaData.

    notificationInfoiReportGeneratorUsed to generate the report and access any DDL or sync script output.

...

In order to add a directory field to the job editor, you write a class that implements the interface named com.idera.change.notifications.api.INotifierViewerContribution.

  • Create a new class named “DirectoryNotifierViewerContribution” "DirectoryNotifierViewerContribution" and follow the same steps you used to create the DirectoryNotifier class class. The exception to this process is that you need to leave the Superclass parameter set to “java"java.lang.Object”Object", as well as adding the interface INotifierViewerContribution INotifierViewerContribution to the list of implemented interfaces.

...

The notifier only allows users to select a directory in which reports and outcomes are written whenever jobs are executed.

The DirectoryNotifierConstants DirectoryNotifierConstants class is a small constants class that stores the property name for storage and retrieval purposes.

  1. Create a new class named DirectoryNotifierConstants.
  2. Enter the following code for the class definition:
    /**
              * Constantsforthisnetworksharenotifier
              */
              publicfinalclassDirectoryNotifierConstants
              {
                         //Overviewfilename publicstatisfinalString OVERVIEW_FILE_NAME=
    “outcome"outcome.txt”txt";
                        //PersistedJobSettingsKey publicstatisfinalSTringTARGET_DIRECTORY=
    “directorynotifier"directorynotifier.targetdir”targetdir";
              /**
              * Constantutilityclasscannotbeinstantiated
              */
              privateDirectoryNotifierConstants()
              {
              }
    }

Implement the DirectoryNotifier class

The DirectoryNotifier class can be coded with two return methods:

  • isReportSupported
  • SendNotification

To implement the isReportSupported method

  • Enter the following code:

public boolean isReportSupported()
{
     return true;
}

To implement the SendNotification method

  1. To add the notifierProperties and assign the targetDirectory to a variable to provide a directory that the user selected for the executed job, add the following code:
         public void sendNotification (INotifierData notifierData, Map<String, String> jobMetaData, notificationInfo
         Map<String, String> notifierProperties = notifierData.getNotificationProperties();
         String targetDirectory = notifierProperties.get (DirectoryNotifierConstants.TARGET_DIRECTORY);
  2. Enter the following code to define that the report and output file need to be placed in a directory whose name is composed of the job execution date and time.

    Info

    If a directory cannot be created, the code below also includes a RuntimeException.

         //Create a new directory named by the execution date and time
              String dateTime = jobMetaData.get (NotificationPropertyEnum.DATE_TIME.getTag() );
              File dir = new File (targetDirectory +  File.seperatorChar + dateTime.replace ( ':', '-' ) );
              boolean createdDirectory = dir.mkdir();
              if (!createdDirectory )
              {
              throw new RuntimeException ("Create Failed: " +  dir.getAbsolutePath () );

              }


  3. Enter the following code to define the outcome file, which includes each of the job execution parameters:
         try
         {
              //Write the results to an output file
              File f = new File (dir.getAbsolutePath() + File.seperatorChar +
              DirectoryNotifierConstants.OVERVIEW_FILE_NAME );
              f.createNewFIle();

              BufferedWriter writer = new BufferedWriter (new FileWriter (f) );
              String newLine = System.getProperty ("line.seperator");
              writer.write ("Outcome: " + jobMetaDAta.get
                   (NotificationPropertyEnum.JOB_OUTCOME.getTag() ) + newLine);
                   writer.write (newLine);
              writer.write ("Date & TimeL" + jobMetaData.get (
                   NotificationPropertyEnum.DATE_TIME.getTag() ) + newLine);
              writer.write ("Elapsed Time: " +  jobMetaData.get (
                   NotificationPropertyEnum.ELAPSED_TIME.getTag() ) + newLine);
                   writer.write newLine );
              writer.write ("Name: " + jobMetaDAta.get (
                   NotificationPropertyEnum.JOB_NAME.getTag() ) + newLine);
                   writer.write (newLine);
              writer.write ("Host: " + jobMetaData.get (
                   NotificationPropertyEnum.JOB_HOST.getTag() ) + newLine);
              writer.write ("Job Type: " + jobMetaData.get (
                   NotificationPropertyEnum.JOB_TYPE.getTag() ) _  newLine);
              writer.write ("Module: " + jobMetaData.get (
                   NotificationPropertyEnum.MODULE.getTag() ) +  newLine);
                   writer.write (newLine);
              writer.write ("Sources: " + jobMetaData.get (
                   NotificationPropertyEnum.JOB_SOURCES.getTag() ) + newLine);
              writer.write ("Targets: " + jobMetaData.get (
                   NotificationPropertyEnum.JOB_TARGETS.getTag() ) + newLine);
                   writer.write (newLine);
              writer.write ("Job Notes: " + jobMetaDAta.get (
                   NotificationPropertyEnum.JOB_NOTES.getTag() ) + newLine );
                   writer.flush();
                   writer.close();
         }
         catch (Throwable t)
         {
              throw new RuntimeException (t);
         }

  4. Enter the following code to generate the report. This code also provides a null report if the report type is set to none at execution time.
         //Create the report if required
         File reportFile = notificationInfo.getReport() ;

         if (reportFile !=null)
         {
              File destinationReportFile = new File dir.getAbsolutePath() + File.seperatorChar +
              reportFile.getName()); eportFile.renameTo (destinationReportFile);
         }

  5. Finally, output any DDL or synchronization SQL:
         //Write the script File scriptFile=notificationInfo.getScript();
         
         if ( scriptFile !=null) File DestinationScriptFIle = new File (dir.getAbsolutePath() +
              File.separatorChar + scriptFile.getName () );
              scriptFile.renameTo (destinationScriptFile);



Scroll Ignore
scroll-pdftrue
scroll-officetrue
scroll-chmtrue
scroll-docbooktrue
scroll-eclipsehelptrue
scroll-epubtrue
scroll-htmltrue
Newtabfooter
aliasIDERA
urlhttp://www.idera.com
 | 
Newtabfooter
aliasProducts
urlhttps://www.idera.com/productssolutions/sqlserver
 
Newtabfooter
aliasPurchase
urlhttps://www.idera.com/buynow/onlinestore
 | 
Newtabfooter
aliasSupport
urlhttps://idera.secure.force.com/
 | 
Newtabfooter
aliasCommunity
urlhttp://community.idera.com
 
|
 
Newtabfooter
aliasResources
urlhttp://www.idera.com/resourcecentral
 | 
Newtabfooter
aliasAbout Us
urlhttp://www.idera.com/about/aboutus
 
Newtabfooter
aliasLegal
urlhttps://www.idera.com/legal/termsofuse