|
Time Estimates for Completion
|
||
|---|---|---|
|
Create a job result handler for the SimpleModelGeometryCheck action.
|
Description:
|
5 minutes
|
|
Lab exercise:
|
15 minutes
|
|
<?xml version="1.0" encoding="utf-8" ?>
<job type="modeling.simplegeometrycheck" version="20.8">.
<element id="BYNP7GNE2VLHYS" timestamp="1196780288000" />
<results modelcheck="model_corrupt">
<result-file format="PKG" mimetype="" zipname="model.pkg" name="model.pkg" />
</results>
</job>
|
|
The EmailJobResultHandler, StoreToDatabaseJobResultHandler, and SaveToFileSystemJobResultHandler check the <result-file> entries for files to e-mail, store to the database, or save to the file system. For information on the supported attributes of the result-file tag, see the AbstractJobResultHandler.ResultFileEntry JavaDoc.
|
package com.acme;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import com.osm.automation.EmailJobResultHandler;
import com.osm.automation.JobExecutionFailedException;
import com.osm.automation.JobResultOutOfDateException;
import com.osm.exception.WMException;
import com.osm.util.Strings;
public class SimpleModelGeometryCheckJobResultHandler extends EmailJobResultHandler {
@Override
public void importJobResultData(String elementElid, Properties jobParams)
throws JobExecutionFailedException, WMException, IOException, JobResultOutOfDateException {
final SimpleModelGeometryCheckJobResultIndex index = (SimpleModelGeometryCheckJobResultIndex) getResultIndex();
if (!index.isModelOK()) {
// only send e-mail if model is not o.k.
super.importJobResultData(elementElid, jobParams);
}
}
@Override
protected JobResultIndex createResultIndex(File indexXmlFile)
throws Exception {
return new SimpleModelGeometryCheckJobResultIndex(indexXmlFile);
}
// special JobResultIndex that evaluates the modelcheck attribute
private static class SimpleModelGeometryCheckJobResultIndex extends JobResultIndex {
private static String XPATH_MODEL_CHECK = "//results/@modelcheck"; //frozen
private String modelcheck;
public SimpleModelGeometryCheckJobResultIndex(File xmlFile)
throws Exception {
super(xmlFile);
}
@Override
protected void parseXml(Document indexDoc) throws Exception {
super.parseXml(indexDoc);
final XPath xpath = XPathFactory.newInstance().newXPath();
this.modelcheck = xpath.evaluate(XPATH_MODEL_CHECK, indexDoc);
}
public boolean isModelOK() {
return !Strings.isEmpty(modelcheck) && modelcheck.equals("model_ok");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Job type="modeling.simplegeometrycheck" has_result_data="true">
<DisplayName>Simple Model Geometry Check</DisplayName>
<UI>
<ActionMenu wm_java_class="com.osm.datamgmt.biz.Model" include_derived="true">
<Name>Simple Model Geometry Check</Name>
<JobGroup>Model Checks</JobGroup>
<Action java_class="com.osm.automation.action.MultiSelectCreateJobScheduleAction">
<Description>Checks a model's geometry</Description>
</Action>
</ActionMenu>
</UI>
<Exporter java_class="com.acme.SimpleModelGeometryCheckJobExporter">
<StartScriptTemplate>SimpleModelGeometryCheckTemplate.lsp</StartScriptTemplate>
<ModelLoadRule catalog="model" msg_num="728">Highest Revisions</ModelLoadRule>
</Exporter>
<ResultHandler java_class="com.acme.SimpleModelGeometryCheckJobResultHandler">
<EmailFiles>
<Subject>Model check had failures</Subject>
<Body> Model check had failures for '{1}'. Annotated model is attached.</Body>
</EmailFiles>
</ResultHandler>
</Job>
<?xml version="1.0" encoding="UTF-8"?>
<Job type="modeling.simplegeometrycheck" has_result_data="true">
<DisplayName>Simple Model Geometry Check</DisplayName>
<UI>
<ActionMenu wm_java_class="com.osm.datamgmt.biz.Model" include_derived="true">
<Name>Simple Model Geometry Check</Name>
<JobGroup>Model Checks</JobGroup>
<Action java_class="com.osm.automation.action.MultiSelectCreateJobScheduleAction">
<Description>Checks a model's geometry</Description>
</Action>
</ActionMenu>
</UI>
<Exporter java_class="com.acme.SimpleModelGeometryCheckJobExporter">
<StartScriptTemplate>SimpleModelGeometryCheckTemplate.lsp</StartScriptTemplate>
<ModelLoadRule catalog="model" msg_num="728">Highest Revisions</ModelLoadRule>
</Exporter>
<ResultHandler java_class="com.osm.automation.CompoundJobResultHandler">
<ResultHandlerOption name="MailOnFailureOption" ignore_errors="false">true
<ResultHandler java_class="com.acme.SimpleModelGeometryCheckJobResultHandler">
<DisplayName>Send e-mail in case of failures</DisplayName>
<EmailFiles>
<Subject>Model check had failures</Subject>
<Body> Model check had failures for '{1}'. Annotated model is attached.</Body>
</EmailFiles>
</ResultHandler>
</ResultHandlerOption>
<ResultHandlerOption name="SaveToFileSystem" ignore_errors="false">true
<ResultHandler java_class="com.osm.automation.SaveToFileSystemJobResultHandler">
<DisplayName>Save annotated model to server directory</DisplayName>
<TargetDirectory>C:\taskagent</TargetDirectory>
</ResultHandler>
</ResultHandlerOption>
</ResultHandler>
</Job>
