Versions Compared

Key

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

...

  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);

Implement the DirectoryNotifierContribution class

Add the code below to the DirectoryNotifierViewerContribution class to provide functionality for the interface:

  1. The DirectoryNotifierViewerContribution class requires three class-level private attributes. These attributes store notification data, which is the composite on which any options are placed, as well as the folderField, which is used to enter a file directory address.
         private INotifierData notificationData;
         private Composite body;
         private Text folderField;
  2. The createFormContent attribute creates a new composite and provides a layout template for options and entry fields. The code below adds a label and a text field to the interface:
         public Composite createFormContent (Composite parent, FormToolkit toolkit) body = toolkit.createComposite (parent);
         body.setLayout (new GridLayout ());
         
              toolkit.createLabel (parent, "Target Directory:");

              String folder = notificationData == null ? " " " : notificationData.getNotificationProperties().get (DirectoryNotifierConstants.TARGET_DIRECTORY);
         
              folderField = toolkit.createText (parent, folder, SWT.SINGLE | SWT.BORDER);
              folderField.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
              folderField.addModifyListener (new ModifyListener () {
                   public void modifyText (ModifyEvent e)
              {
                   notificationData.setNotificationPropert (DirectoryNotifierConstants.TARGET_DIRECTORY, folderField.getText().trim() );
              }
         });
         return body;
    The code does the following:
    • Creates a new composite body, and sets it to have a grid layout.
    • Creates a label for the target directory field.
    • Retrieves the folder from the job, if the job is new or unsaved, or defaults to an empty string if the result is null.
    • Initializes the folderField text element and sets it to justify.
    • Adds a listener for changes on the folderField element that updates the notificationData, thus enabling save actions.
    • Returns the body to be added to the DB Change Manager job editor to which this class applies.
  3. Add the setData method using the following code, which is called to update the user interface with job information. This method accepts and stores the new instance of INotifierData containing job-specific data for the notifier. If the folderField has already had something entered, the notification properties are initialized and store the value that was previously entered.
         public void setData (INotifierData notificationData)

              this.notificationData = notificationData;

              if (folderField !=null && !folderField.isDisposed() && folderField.getText().trim().length() > 0))
                   if (notificationData !=null) Map<String, String> propMap notificationData.getNotificationProperties();
                   if (propMap == null)
                   {
                        notificationData.setNotificationProperties(new HashMap<String, String>());

                        propMap = notificationData.getNotificationProperties();
                   }
                   notificationData.setNotificationProperty (DirectoryNotifierConstants.TARGET_DIRECTORY, folderField.getText());
                   }
              }
         }

Register the extensions



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