Custom Task Guide

Custom Task Guide

Implement the validate Method

Implement the validate Method

This method is called by the Project Compiler in
Managed File Transfer
. All projects go through compilation phase before they execute. The compilation of a project will create an object for each component in the project and call it’s validate() method. If any component fails to validate, a compilation error will be reported. 
Please note that the red text denotes the new source added to the example.
package com.example; import java.util.ArrayList; import java.util.List; import com.linoma.commons.StringUtilities; import com.linoma.dpa.Message; import com.linoma.ga.projects.CustomTask; import com.linoma.ga.projects.TaskContainer; import com.linoma.dpa.ValidationException; public class CopyTask extends CustomTask { private static final String TAG_NAME = "example:copy"; private static final String ATTR_SOURCE_FILE = "sourceFile"; private static final String ATTR_DESTINATION_DIRECTORY = "destinationDirectory"; private String sourceFileAttribute = null; private String destinationDirectoryAttribute = null; public CopyTask(TaskContainer parent) { super(parent); label = TAG_NAME; } @Override public String getTagName() { return TAG_NAME; } @Override public String getDisplayString() { return label; } @Override public String getVersion() { return "1.0"; } @Override public String getVendor() { return "Example, Inc."; } public String getSourceFileAttribute() { return sourceFileAttribute; } public void setSourceFileAttribute(String sourceFileAttribute) { this.sourceFileAttribute = sourceFileAttribute; } public String getDestinationDirectoryAttribute() { return destinationDirectoryAttribute; } public void setDestinationDirectoryAttribute( String destinationDirectoryAttribute) { this.destinationDirectoryAttribute = destinationDirectoryAttribute; } @Override public void validateAttributes() throws ValidationException { // A list to hold any validation errors List<Message> errors = new ArrayList<Message>(); // Call the validateAttributes of the super class try { super.validateAttributes(); } catch (ValidationException exp) { // If the attributes on the super class fail to validate, add the // errors to the list. errors.addAll(exp.getMessages()); } // Perform our task-specific validation. if (StringUtilities.isEmpty(sourceFileAttribute)) { errors.add(new Message("Source File is required")); } if (StringUtilities.isEmpty(destinationDirectoryAttribute)) { errors.add(new Message("Destination Directory is required")); } if (!errors.isEmpty()) { throw new ValidationException(errors); }} @Override public void validate() throws ValidationException { // Simply call the validateAttributes to validate all the attributes. validateAttributes(); } }

0 COMMENTS

We’d like to hear from you!