Permalink
Browse files

Toolwrapper adapted for BorderRemoval4 service

  • Loading branch information...
1 parent d02fec0 commit 36f768177f031b3ce3665f47b2141dfec1653902 Sven Schlarb committed Nov 25, 2011
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<toolspec model="0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="c:\owndata\scape\toolspec.xsd">
+ <id>borderremoval</id>
+ <name>BorderRemoval</name>
+ <homepage>http://www.impact-project.eu/taa/tech/imgenh/bm</homepage>
+ <version>4</version>
+ <installation>
+ <os type="linux">
+
+ </os>
+ <os type="windows">
+
+ </os>
+ </installation>
+ <services>
+ <service sid="1" name="BorderRemoval" type="migrate" servicepackage="eu.impact_project.iif.service" contextpathprefix="/wimpactservices">
+ <description>Service for copying files</description>
+ <operations>
+ <operation oid="1" name="removeBorder">
+ <description>Remove the border from an input image file</description>
+ <command>C:\\Programme\\IMPACTBorderRemovalV4\\Border_Detection_v4.exe ${pagesplit} ${infile} ${outfile1} ${outfile2}</command>
+ <inputs>
+ <input name="infile">
+ <Datatype>xsd:anyURI</Datatype>
+ <Required>true</Required>
+ <Default>http://fue.onb.ac.at/impact/testdata/19080603_0001.tif</Default>
+ <CliMapping>infile</CliMapping>
+ <Documentation>URL reference to input file</Documentation>
+ </input>
+ <input name="pagesplit">
+ <Datatype>xsd:boolean</Datatype>
+ <Required>true</Required>
+ <Default>false</Default>
+ <CliMapping>pagesplit</CliMapping>
+ <Documentation>Indicates if a page should be split or not (if an image represents two book pages)</Documentation>
+ </input>
+ </inputs>
+ <outputs>
+ <output name="outfile1">
+ <Datatype>xsd:anyURI</Datatype>
+ <CliMapping>outfile1</CliMapping>
+ <Required>false</Required>
+ <Documentation>URL reference to first output file</Documentation>
+ <Extension>tif</Extension>
+ </output>
+ <output name="outfile2">
+ <Datatype>xsd:anyURI</Datatype>
+ <CliMapping>outfile2</CliMapping>
+ <Required>false</Required>
+ <Documentation>URL reference to first output file</Documentation>
+ <Extension>tif</Extension>
+ </output>
+ </outputs>
+ </operation>
+ </operations>
+ <deployto>
+ <deployref default="true" ref="local"/>
+ </deployto>
+ </service>
+ </services>
+ <deployments>
+ <deployment id="local">
+ <identifier>http://localhost:8080/impact/instances/tomcat1</identifier>
+ <host>localhost</host>
+ <ports>
+ <port type="http">8080</port>
+ <port type="https">8043</port>
+ </ports>
+ <manager>
+ <user>tomcat</user>
+ <password>tomcat</password>
+ <path>manager</path>
+ </manager>
+ <dataexchange>
+ <accessdir>../webapps/ROOT/impact/tmp/</accessdir>
+ <accessurl>http://localhost:8080/impact/tmp/</accessurl>
+ </dataexchange>
+ </deployment>
+ </deployments>
+</toolspec>
@@ -79,14 +79,14 @@ private void createOperationCode(Operation operation) throws IOException, Genera
List<Input> inputs = operation.getInputs().getInput();
for (Input input : inputs) {
addDataSection(operation, oc, IOType.INPUT, input.getDatatype(),
- input.getName(), input.getCliMapping(), null, null, false, input.getRestriction());
+ input.getName(), input.getCliMapping(), null, null, false, input.getRestriction(), input.getRequired());
}
List<Output> outputs = operation.getOutputs().getOutput();
for (Output output : outputs) {
addDataSection(operation, oc, IOType.OUTPUT, output.getDatatype(),
output.getName(), output.getCliMapping(),
output.getPrefixFromInput(), output.getExtension(),
- (output.isAutoExtension() != null && output.isAutoExtension()), null);
+ (output.isAutoExtension() != null && output.isAutoExtension()), null, output.getRequired());
}
oc.put("inputsection", oc.getInputSection());
@@ -123,14 +123,18 @@ private void createOperationCode(Operation operation) throws IOException, Genera
* @param dataType Data type (xsd:string, xsd:integer, etc.)
* @throws GeneratorException
*/
- protected void addDataSection(Operation operation, OperationCode oc, IOType iotype, String dataType, String nodeName, String cliMapping, String prefixFromInput, String extension, boolean autoExtension, Restriction restriction) throws GeneratorException {
-
+ protected void addDataSection(Operation operation, OperationCode oc, IOType iotype, String dataType, String nodeName, String cliMapping, String prefixFromInput, String extension, boolean autoExtension, Restriction restriction, String required) throws GeneratorException {
+
+ boolean isRequired = (required != null && required.equalsIgnoreCase("true"));
String opid = String.valueOf(operation.getOid());
// code template for the current leaf node
boolean isMultiple = restriction != null && restriction.isMultiple();
String template = "tmpl/datatypes/" + iotype + "_"
+ StringConverterUtil.typeToFilename(dataType)
+(isMultiple?"_restricted_list":"")
+ +(isMultiple?"_restricted_list":"")
+ +((iotype.equals(iotype.OUTPUT) && dataType.equals("xsd:anyURI")
+ && !isRequired)?"_opt":"")
+ ".vm";
logger.debug("Using template \"" + template + "\" for node \"" + nodeName
+ "\" in operation " + opid);
@@ -249,7 +253,7 @@ private String getCliMapping(IOType iotype, String cliMappingVar, String dataTyp
mappingVal = "Integer.toString(" + nodeName + ")";
}
if (dataType.equals("xsd:boolean")) {
- mappingVal = nodeName;
+ mappingVal = "Boolean.toString("+nodeName+")";
}
if (dataType.equals("xsd:string")) {
mappingVal = nodeName;
@@ -0,0 +1,38 @@
+ // Output: ${output_variable}
+ File ${output_variable}File = new File(${output_variable}FileName${autoextension});
+ boolean isCreated${output_variable} = false;
+ if (!${output_variable}File.exists() || ${output_variable}File.length() == 0) {
+ infolog("The expected output file " + ${output_variable}File.getName() + " is empty or has not been created");
+ } else {
+ infolog("Output file of size " + ${output_variable}File.length() + " has been created successfully");
+ isCreated${output_variable} = true;
+ }
+ File ${output_variable}PublicFile =
+ new File(publicHttpAccessDir + ${output_variable}File.getName());
+ if (!new File(publicHttpAccessDir).isDirectory()) {
+ errorlog("The output directory " + publicHttpAccessDir + " does not exist. Check "
+ + "publicHttpAccessDir parameter in the service configuration");
+ return ${operationname}Result(fac, omNs);
+ }
+ infolog("Public output file: " + ${output_variable}PublicFile.toString());
+ try {
+ if(isCreated${output_variable})
+ org.apache.commons.io.FileUtils.copyFile(${output_variable}File, ${output_variable}PublicFile);
+ } catch (IOException _) {
+ infolog("No outputfile created in the public access directory for '${output_variable}'");
+ }
+ URL ${output_variable}FileUrl;
+ try {
+ if(isCreated${output_variable})
+ ${output_variable}FileUrl = new URL(publicHttpAccessUrl + ${output_variable}PublicFile.getName());
+ else
+ ${output_variable}FileUrl = new URL("http://null");
+ } catch (MalformedURLException ex) {
+ errorlog("Malformed URL for binary result resource. Verify"
+ + "publicHttpAccessUrl parameter in the "
+ + "resources/services.xml. Exception message: "
+ + ex.getMessage());
+ return ${operationname}Result(fac, omNs);
+ }
+ if(isCreated${output_variable})
+ infolog("Output URL: " + ${output_variable}FileUrl.toString());

0 comments on commit 36f7681

Please sign in to comment.