Example Custom Source Configuration Type

Following is an example of a custom source configuration type.

Note: You can download this example in a text file from Knowledgebase item S142231.
package <user.defined.package>;

import com.microfocus.da.sct.annotations.*;
import com.microfocus.da.sct.dtos.VersionInfo;
import com.microfocus.da.sct.interfaces.CommonIntegrator;
import com.microfocus.da.sct.interfaces.ComponentInfo;

import java.io.File;
import java.io.PrintWriter;
import java.util.*;

@SourceConfigTypeConfig(name="All UI Type File Creator", versionNumber = "1.0", description = "Contains all the UI elements and creates a file")
@VersionParams(versionParams = { @VersionParam(displayName = "Revision", name = "revision", description = "Revision to download")})
public class AllUITypeFileCreator implements CommonIntegrator {

    @SourceConfigTypeParam(displayName = "File Name", description = "Name of the file", required = true, readOnly = true)
    private String fileName;

    @SourceConfigTypeParam(displayName = "File content", description = "Content for creating the file", required = true, readOnly = true, dataType = DataType.TEXTAREA)
    private String fileContent;

    @SourceConfigTypeParam(displayName = "Skip Content Creation", description = "If selected, skips the content creation",
            required = true, readOnly = true, dataType = DataType.CHECKBOX)
    private Boolean skipContentCreation;

    @SourceConfigTypeParam(displayName = "Append Date", description = "Append date with the content",
            required = true, readOnly = true, dataType = DataType.SELECT, allowedValues= {@AllowedValue(label = "YES", value = "YES"),
            @AllowedValue(label = "NO", value = "NO")})
    private String appendDate;

    @SourceConfigTypeParam(displayName = "Secure Content", description = "Secure Content", required = true, readOnly = true, dataType = DataType.SECURE)
    private String secureContent;

    @SourceConfigTypeParam(displayName = "Multi Select", description = "Select Multiple",
            required = true, readOnly = true, dataType = DataType.SELECT, allowedValues= {@AllowedValue(label = "One", value = "One"),
            @AllowedValue(label = "Two", value = "Two")})
    private String multiSelect;

    private ComponentInfo info;

    public Collection<VersionInfo> getNextVersionInfo(Properties properties) throws Exception {

        if(properties == null)
            return null;

        List<VersionInfo> infoList = new ArrayList<VersionInfo>();
        VersionInfo inf = new VersionInfo(properties.getProperty("revision"));
        inf.setVersionProps(properties);
        infoList.add(inf);

        return infoList;
    }


    public String getMultiSelect() {
        return multiSelect;
    }

    public void setMultiSelect(String multiSelect) {
        this.multiSelect = multiSelect;
    }

    public void downloadVersionContent(VersionInfo versionInfo, File processingDirectoryLocation) throws Exception {

        try {

            // Code for download content
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }


    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileContent() {
        return fileContent;
    }

    public void setFileContent(String fileContent) {
        this.fileContent = fileContent;
    }

    public Boolean getSkipContentCreation() {
        return skipContentCreation;
    }

    public ComponentInfo getInfo() {
        return info;
    }

    public void setInfo(ComponentInfo info) {
        this.info = info;
    }

    public void setSkipContentCreation(Boolean skipContentCreation) {
        this.skipContentCreation = skipContentCreation;
    }

    public String getAppendDate() { return appendDate; }

    public void setAppendDate(String appendDate) {
        this.appendDate = appendDate;
    }

    public String getSecureContent() {
        return secureContent;
    }

    public void setSecureContent(String secureContent) {
        this.secureContent = secureContent;
    }

    @Override
    public String toString() {
        return "AllUITypeFileCreator{" +
                "fileName='" + fileName + '\'' +
                ", fileContent='" + fileContent + '\'' +
                ", skipContentCreation=" + skipContentCreation +
                ", appendDate='" + appendDate + '\'' +
                ", secureContent='" + secureContent + '\'' +
                ", multiSelect='" + multiSelect + '\'' +
                ", info=" + info +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AllUITypeFileCreator)) return false;

        AllUITypeFileCreator that = (AllUITypeFileCreator) o;

        if (fileName != null ? !fileName.equals(that.fileName) : that.fileName != null) return false;
        if (fileContent != null ? !fileContent.equals(that.fileContent) : that.fileContent != null) return false;
        if (skipContentCreation != null ? !skipContentCreation.equals(that.skipContentCreation) : that.skipContentCreation != null)
            return false;
        if (appendDate != null ? !appendDate.equals(that.appendDate) : that.appendDate != null) return false;
        if (secureContent != null ? !secureContent.equals(that.secureContent) : that.secureContent != null)
            return false;
        if (multiSelect != null ? !multiSelect.equals(that.multiSelect) : that.multiSelect != null) return false;
        return info != null ? info.equals(that.info) : that.info == null;
    }

    @Override
    public int hashCode() {
        int result = fileName != null ? fileName.hashCode() : 0;
        result = 31 * result + (fileContent != null ? fileContent.hashCode() : 0);
        result = 31 * result + (skipContentCreation != null ? skipContentCreation.hashCode() : 0);
        result = 31 * result + (appendDate != null ? appendDate.hashCode() : 0);
        result = 31 * result + (secureContent != null ? secureContent.hashCode() : 0);
        result = 31 * result + (multiSelect != null ? multiSelect.hashCode() : 0);
        result = 31 * result + (info != null ? info.hashCode() : 0);
        return result;
    }
}