Controlling the CADWorker’s Appetite

By default the Windchill CAD worker will attempt to publish all EPMDocuments regardless of whether the EPMDocument is a part, drawing, manufacturing assembly, skeleton, etc.

Due to the extensible nature of Windchill, you can control  what files are published by simply writing a Java method that returns a simple boolean value.  You can add as much business logic into that method as needed. Anything you can do in Java can be included inside that method, as long as the logic boils down to a simple true or false.

The following stub shows the basic outline of the class, namely it needs to contain a public static method that takes an EPMDocument as the only argument and returns a boolean.

/**
 * @(#)PublishFilter.java 1.0 5/10/2012
 *
 * Copyright (c) 2012 Brian Geary, Windchill101.com
 * U.S.A. All rights reserved.
 */
package com.example.pdmlink.epm;

public class PublishFilter
{ 
    public static boolean isPublishable(EPMDocument epmDocument) {       
        return true;
    }
}

How does Windchill know to call this method for the go/no-go decision on whether or not to publish the EPMDocument?  You’ll need to tell it through the wvs.properties file by indicating the class name and method to call.

Add the following line to wvs.properties on all foreground and background servers:

publish.service.filterepmdocumentpublishmethod=com.example.pdmlink.epm.PublishFilter/isPublishable

Notice in the line above that the method name is separated from the class name with the “/” character.

Since xconfmanager can and will re-create the wvs.properties file, make sure to add the following entry to site.xconf:

<Property name="publish.service.filterepmdocumentpublishmethod" overridable="true" targetFile="codebase/wvs.properties" value="com.example.pdmlink.epm.PublishFilter/isPublishable"/>

 That’s it – once you have the above code in place, you have all the pieces needed for adding your business logic.  Below is a fully-functional example class that contains examples for testing which type of EPMDocument is being tested.

/**
 * @(#)PublishFilter.java 1.0 5/10/2012
 *
 * Copyright (c) 2012 Brian Geary, Windchill101.com
 * U.S.A. All rights reserved.
 *
 * @author Brian Geary
 * @version 5/10/2012
 *
 * DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Brian Geary does not warrant or guarantee the individual success developers may have in implementing the sample code on their respective systems.
 *
 * Brian Geary does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. The author disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
 *
 * Brian Geary shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
 */
package com.example.pdmlink.epm;
import wt.epm.EPMDocument;
public class PublishFilter
{
   // set some static variables containing the various types of EPMDocuments to save on typing
   public static final String CADASSEMBLY = "wt.epm.EPMDocumentType.CADASSEMBLY";
   public static final String CADCOMPONENT = "wt.epm.EPMDocumentType.CADCOMPONENT";
   public static final String CADDRAWING = "wt.epm.EPMDocumentType.CADDRAWING";
   public static final String FORMAT = "wt.epm.EPMDocumentType.FORMAT";
   public static final String LAYOUT = "wt.epm.EPMDocumentType.LAYOUT";
   public static final String MANUFACTURING = "wt.epm.EPMDocumentType.MANUFACTURING";
   public static final String MARKUP = "wt.epm.EPMDocumentType.MARKUP";
   public static final String OTHER = "wt.epm.EPMDocumentType.OTHER";
   public static final String REPORT = "wt.epm.EPMDocumentType.REPORT";
   public static final String SKETCH = "wt.epm.EPMDocumentType.SKETCH";
   public static final String UDF = "wt.epm.EPMDocumentType.UDF";

    public static boolean isPublishable(EPMDocument epmDocument) {
        boolean result = false; // let's assume it should not be published
        String number = null;
        String docType = null;

        if (epmDocument == null || (epmDocument instanceof EPMDocument)==false) {
            number = "unknown Document";
            result = false;
        } else {
            number = epmDocument.getNumber().toUpperCase();
            docType = epmDocument.getDocType().getStringValue();

            if (CADCOMPONENT.equals(docType)) {
                result = true;
            } else if (CADASSEMBLY.equals(docType)) {
                // only publish assemblies from selected contexts: ProductA, ProductC, and ProductE
                String containerName = epmDocument.getContainerName(); // ContainerName is the context name
                if ("ProductA".equalsIgnoreCase(containerName)) {
                    result = true;
                } else if ("ProductC".equalsIgnoreCase(containerName)) {
                    result = true;
                } else if ("ProductE".equalsIgnoreCase(containerName)) {
                    result = true;
                } else {
                    result = false;
                }
            } else if (docType.equals(CADDRAWING)) {
                result = true; // passed the first test of file extension
            } else if (docType.equals(MANUFACTURING)) {
                result = false; // we don't want to publish any manufacturing files
            } else if (number.endsWith(".SEC")) {
                result = false; // we don't want to publish any sections
            }

            // filter out Generic EPMDocuments
            if (epmDocument.isGeneric()){
                result = false;
            }
            // filter out by evaluating the number - don't waste time looking if it's already been flagged
            if (result == true) {
                if ((number.length() > 6) && number.endsWith("S")) {
                    //it's a skeleton, based on 'S' at end of more than 6 characters
                    result = false;
                }
            }

            // filter out by context - don't waste time looking at context if it's already been flagged
            if (result == true) {
                String containerName = epmDocument.getContainerName();
                if (containerName != null) {
                    if (containerName.equalsIgnoreCase("Manufacturing"))
                        result = false;
                }
            }
        }

        // log final decision in  MethodServer:
        if (result == true) {
            System.out.println("PublishFilter.isPublishable() - "+number+" has been approved for publishing. Document type is"+docType);
        } else {
            System.out.println("PublishFilter.isPublishable() - "+number+" has been rejected for publishing. Document type is"+docType);
        }

        return result;
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s