Creating Custom Scheduled Jobs
1. I have a custom scheduled job created but it always runs in context 'site' and always returns null. I understand this is by design.
2. When I try to schedule my custom job in my org, my custom job name does not display in the job listbox to choose. The custom job name only displays when I am in the job administrator scheduler for 'site'.
3. I am struggling how to get my custom job name to display in the job administrator scheduler for my 'org' and have not been able to verify if my custom job java code is correct. See the code below.
Any hints or suggestions are appreciated.
Thanks, Mike
package ext.customers.provisur.customJobs;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.logging.FileHandler;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import wt.doc.WTDocument;
import wt.epm.EPMDocument;
import wt.epm.EPMDocumentMaster;
import wt.epm.build.EPMBuildRule;
import wt.fc.ObjectIdentifier;
import wt.fc.ObjectReference;
import wt.fc.ObjectVector;
import wt.fc.ObjectVectorIfc;
import wt.fc.PagingQueryResult;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.collections.WTArrayList;
import wt.fc.collections.WTList;
import wt.inf.container.ContainerSpec;
import wt.inf.container.WTContained;
import wt.inf.container.WTContainerHelper;
import wt.inf.container.WTContainerRef;
import wt.log4j.LogR;
import wt.org.WTOrganization;
import wt.part.WTPart;
import wt.pds.StatementSpec;
import wt.pom.PersistenceException;
import wt.query.BasicPageableQuerySpec;
import wt.query.ClassAttribute;
import wt.query.PageableQuerySpec;
import wt.query.PagingSessionSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.SubSelectExpression;
import wt.representation.Representable;
import wt.representation.RepresentationHelper;
import wt.util.WTAttributeNameIfc;
import wt.util.WTContext;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.vc.Iterated;
import wt.vc.IterationInfo;
import wt.vc.VersionControlHelper;
import wt.vc.Versioned;
import wt.viewmarkup.DerivedImage;
import com.ptc.wvs.common.util.VSResult;
import com.ptc.wvs.common.util.WVSProperties;
import com.ptc.wvs.server.schedule.ScheduleJobs;
import com.ptc.wvs.server.schedule.ScheduledJobQueries;
import com.ptc.wvs.server.ui.UIHelper;
import com.ptc.wvs.server.util.PublishUtils;
public class PTCustomJobs {
private static String schema;
public static String WTHOME = "D:/ptc/Windchill_11.x/Windchill" ;
public static String FILENAME = "scheduler_Prefix109_" ;
public static PrintWriter theLogFile = null ;
public static String theLogFileName = "";
// Using Logger rather than WVSLogger because WVSLogger is not a Supported API and this
// class double as an example.
private static final Logger logger = LogR.getLogger(PTCustomJobs.class.getName());
static {
boolean verbose = true;
String propValue = WVSProperties.getPropertyValue("publish.service.verbose");
if ((propValue != null) && propValue.equalsIgnoreCase("TRUE")) {
verbose = true;
}
if (verbose && logger.getLevel() == null) {
logger.setLevel(Level.DEBUG);
}
}
// public static WTList PTPrefix109() {
public static QuerySpec PTPrefix109() {
/*
* test to publish only 109-11**
*/
//schema = WTProperties.getLocalProperties().getProperty("wt.erp.schema");
//WTHOME = WTProperties.getLocalProperties().getProperty("wt.home") ;
logger.debug("starting prefix109");
WTList wtl = new WTArrayList();
QuerySpec qs = null;
QueryResult qr = null;
try {
qs = new QuerySpec(EPMDocumentMaster.class);
SearchCondition sc1 = new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.NUMBER,
SearchCondition.LIKE, "109-11%");
/*
SearchCondition sc2 =
new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.DISPLAY_TYPE,
SearchCondition.EQUAL, "Drawing"
);
*/
SearchCondition sc2 =
new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.DOC_TYPE,
SearchCondition.EQUAL, "CADDRAWING"
);
/*
SearchCondition sc3 =
new SearchCondition(WTOrganization.class,
WTOrganization.NAME,
SearchCondition.EQUAL, "Provisur"
);
*/
WTContainerRef cr = ScheduleJobs.getCurrentContainer();
if (cr != null) {
logger.debug("filter CAD drawings by container-" + cr.getName() );
ContainerSpec cs = new ContainerSpec();
cs.addSearchContainer(cr);
qs.setAdvancedQueryEnabled(true);
qs.appendWhere(sc1, new int[] {0});
qs.appendAnd();
qs.appendWhere(sc2, new int[] {0});
//qr = PersistenceHelper.manager.find((StatementSpec) qs);
/*
while (qr.hasMoreElements()) {
//doc = (Representable)((Object[])qr.nextElement())[0];
//wtl.add(doc);
wtl.add(qr.nextElement());
}
*/
}
} catch (Exception e) {
logger.error("proviScheduleJobPrefix109(): ", e);
qr = new QueryResult();
}
//return new WTArrayList(qr);
return qs;
}
}


