Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
isSupportedFormats compares now via equalsIgnoreCase(). This might no…
Browse files Browse the repository at this point in the history
…t be so error-prone.

git-svn-id: https://svn.52north.org/svn/geoprocessing/main/WPS/trunk/WPS@382 15ebfbcb-1bbe-4f7e-88aa-3b0fa5d666c2
  • Loading branch information
oldgitdaddy committed Jun 3, 2008
0 parents commit e9dd249
Show file tree
Hide file tree
Showing 156 changed files with 17,897 additions and 0 deletions.
57 changes: 57 additions & 0 deletions 52n-wps-client-lib/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- $Id$ -->
<parent>
<groupId>org.n52.wps</groupId>
<artifactId>52n-wps-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.n52.wps</groupId>
<artifactId>52n-wps-client-lib</artifactId>
<packaging>jar</packaging>
<name>52north 52n-wps-client library</name>
<description>This module contains some convenient classes to interact with WPS</description>
<scm>
<!-- Specification of the Source-Content-Managmentsystem -->
<connection>scm:cvs:pserver:anonymous:@core-52n.cvs.sourceforge.net:/cvsroot/core-52n:WPS</connection>
</scm>
<build>
<plugins>
<!--plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<configuration>
<excludes>/WEB-INF/</excludes>
</configuration>
</plugin-->
</plugins>

<!-- build-jar should be without version number -->
<!--finalName>52n-wps-io</finalName-->
<!-- resources for tests (log4j.xml,...)-->
<testResources>

</testResources>

</build>

<!-- here are the dependencies of the project -->
<dependencies>
<!-- Dependencies for Scope 'test' -->
<dependency>
<groupId>org.n52.wps</groupId>
<artifactId>52n-wps-io</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.n52.wps</groupId>
<artifactId>52n-wps-xml</artifactId>
<version>1.0.0</version>
</dependency>

</dependencies>
<!-- here are default properties, can be overwritten by profiles -->

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.n52.wps.client;


import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public abstract class AbstractClientGETRequest {
protected Map<String, String> requestParams;

private static String SERVICE_REQ_PARAM_NAME = "Service";
private static String REQUEST_REQ_PARAM_NAME = "Request";
private static String SERVICE_REQ_PARAM_VALUE = "WPS";
private static String VERSION_REQ_PARAM_NAME = "version";
private static String VERSION_REQ_PARAM_VALUE = "1.0.0";

public AbstractClientGETRequest() {
requestParams = new HashMap<String, String>();
requestParams.put(SERVICE_REQ_PARAM_NAME, SERVICE_REQ_PARAM_VALUE);
requestParams.put(VERSION_REQ_PARAM_NAME, VERSION_REQ_PARAM_VALUE);
}

protected void setRequestParamValue(String s) {
requestParams.put(REQUEST_REQ_PARAM_NAME, s);
}

/**
* adds to the url the designated parameter names and values, as configured before.
* @param url
* @return
*/
public String getRequest(String url) {
if(! url.contains("?")) {
url = url + "?";
}
for(Entry<String, String> entry : requestParams.entrySet()) {
url = url + entry.getKey() + "=" + entry.getValue() + "&";
}
return url;
}

public abstract boolean valid();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.n52.wps.client;


public class ClientCapabiltiesRequest extends AbstractClientGETRequest {

private String REQUEST_REQ_PARAM_VALUE = "GetCapabilities";

public ClientCapabiltiesRequest() {
super();
setRequestParamValue(REQUEST_REQ_PARAM_VALUE);
}

public boolean valid() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.n52.wps.client;


public class ClientDescribeProcessRequest extends AbstractClientGETRequest {

private static String IDENTIFIER_REQ_PARAM_NAME = "identifier";
private static String REQUEST_REQ_PARAM_VALUE = "DescribeProcess";

ClientDescribeProcessRequest() {
super();
setRequestParamValue(REQUEST_REQ_PARAM_VALUE);
}

public void setIdentifier(String[] ids) {
String idsString = "";
for(int i = 0; i < ids.length; i++) {
idsString = idsString + ids[i];
if(i != ids.length -1) {
idsString = idsString + ",";
}
}
requestParams.put(IDENTIFIER_REQ_PARAM_NAME, idsString);
}

public boolean valid() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*****************************************************************
Copyright © 2007 52°North Initiative for Geospatial Open Source Software GmbH
Author: foerster
Contact: Andreas Wytzisk,
52°North Initiative for Geospatial Open Source SoftwareGmbH,
Martin-Luther-King-Weg 24,
48155 Muenster, Germany,
info@52north.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; even without the implied WARRANTY OF
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see gnu-gpl v2.txt). If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA or visit the Free
Software Foundation’s web page, http://www.fsf.org.
***************************************************************/
package org.n52.wps.client;

import net.opengis.wps.x100.ComplexDataDescriptionType;
import net.opengis.wps.x100.ExecuteDocument;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.InputType;
import net.opengis.wps.x100.ProcessDescriptionType;
import net.opengis.wps.x100.ExecuteDocument.Execute;

import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.n52.wps.io.GeneratorFactory;
import org.n52.wps.io.IGenerator;
import org.n52.wps.io.IOHandler;
import org.n52.wps.io.xml.AbstractXMLGenerator;
import org.w3c.dom.Node;

/*
* ExecuteRequestBuilder support WPS version 1.0.0
* @author foerster
* TODO: this does not handle referenced datasets
*/

public class ExecuteRequestBuilder {
ProcessDescriptionType processDesc;
ExecuteDocument execute;
String SUPPORTED_VERSION = "1.0.0";

public ExecuteRequestBuilder(ProcessDescriptionType processDesc) {
this.processDesc = processDesc;
execute = ExecuteDocument.Factory.newInstance();
Execute ex = execute.addNewExecute();
ex.setVersion(SUPPORTED_VERSION);
ex.addNewIdentifier().setStringValue(processDesc.getIdentifier().getStringValue());
ex.addNewDataInputs();
}

public void addComplexData(String parameterID, Object value) {
GeneratorFactory fac = StaticDataHandlerRepository.getGeneratorFactory();
InputDescriptionType inputDesc = getParameterDescription(parameterID);
if(inputDesc == null) {
throw new IllegalArgumentException("inputDesription is null for: " + parameterID);
}
if(inputDesc.getComplexData() == null) {
throw new IllegalArgumentException("inputDescription is not of type ComplexData: " + parameterID);
}
String schemaURL = inputDesc.getComplexData().getDefault().getFormat().getSchema();
IGenerator generator = fac.getGenerator(schemaURL, IOHandler.DEFAULT_MIMETYPE, IOHandler.DEFAULT_ENCODING);
if(generator instanceof AbstractXMLGenerator) {
AbstractXMLGenerator xmlGenerator = (AbstractXMLGenerator) generator;
Node node = xmlGenerator.generateXML(value, null);
InputType input = execute.getExecute().getDataInputs().addNewInput();
input.addNewIdentifier().setStringValue(inputDesc.getIdentifier().getStringValue());
try {
input.addNewData().addNewComplexData().set(XmlObject.Factory.parse(node));
}
catch(XmlException e) {
throw new IllegalArgumentException("problem inserting node into execute request", e);
}
}
}

public void addLiteralData(String parameterID, String value) {
InputDescriptionType inputDesc = this.getParameterDescription(parameterID);
if(inputDesc == null) {
throw new IllegalArgumentException("inputDesription is null for: " + parameterID);
}
if(inputDesc.getLiteralData() == null) {
throw new IllegalArgumentException("inputDescription is not of type literalData: " + parameterID);
}
String reference = inputDesc.getLiteralData().getDataType().getReference();
InputType input = execute.getExecute().getDataInputs().addNewInput();
input.addNewIdentifier().setStringValue(parameterID);
input.addNewData().addNewLiteralData().setStringValue(value);
input.getData().getLiteralData().setDataType(reference);
}
/**
* this sets the complexdataReference, if the process description also refers to this schema:
* http://schemas.opengis.net/gml/2.1.2/feature.xsd
* @param parameterID
* @param value
*/
public void addComplexDataReference(String parameterID, String value) {
String supportedSchema = "http://schemas.opengis.net/gml/2.1.2/feature.xsd";
InputDescriptionType inputDesc = getParameterDescription(parameterID);
if(inputDesc == null) {
throw new IllegalArgumentException("inputDesription is null for: " + parameterID);
}
if(inputDesc.getComplexData() == null) {
throw new IllegalArgumentException("inputDescription is not of type complexData: " + parameterID);
}
boolean isSupportedSchema = false;
if(inputDesc.getComplexData().getDefault().getFormat().getSchema().equals(supportedSchema)){
isSupportedSchema = true;
}
if(inputDesc.getComplexData().getSupported() != null && !isSupportedSchema) {
for(ComplexDataDescriptionType dataDesc: inputDesc.getComplexData().getSupported().getFormatArray()) {
if(!isSupportedSchema && dataDesc.getSchema().equals(supportedSchema)) {
isSupportedSchema = true;
}
}
}
if(!isSupportedSchema) {
throw new IllegalArgumentException("complexparameter does not support the default dataEncoding GML2");
}
InputType input = execute.getExecute().getDataInputs().addNewInput();
input.addNewIdentifier().setStringValue(parameterID);
input.addNewReference().setHref(value);
input.getReference().setSchema(supportedSchema);
}

/**
* checks, if the execute, which has been build is valid according to the process description.
* @return
*/
public boolean isExecuteValid() {
return true;
}


public ExecuteDocument getExecute() {
return execute;
}
/**
*
* @param id
* @return the specified parameterdescription. if not available it returns null.
*/
private InputDescriptionType getParameterDescription(String id) {
InputDescriptionType[] inputDescs = processDesc.getDataInputs().getInputArray();
for(InputDescriptionType inputDesc : inputDescs) {
if(inputDesc.getIdentifier().getStringValue().equals(id))
{
return inputDesc;
}
}
return null;
}
}
Loading

0 comments on commit e9dd249

Please sign in to comment.