2016-10-25 12:46:50 +02:00
|
|
|
package org.gcube.data.analysis.dataminermanagercl.server.dmservice.wps;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import net.opengis.ows.x11.AllowedValuesDocument.AllowedValues;
|
|
|
|
import net.opengis.ows.x11.DomainMetadataType;
|
|
|
|
import net.opengis.ows.x11.ValueType;
|
|
|
|
import net.opengis.wps.x100.ComplexDataDescriptionType;
|
|
|
|
import net.opengis.wps.x100.InputDescriptionType;
|
|
|
|
import net.opengis.wps.x100.LiteralInputType;
|
|
|
|
import net.opengis.wps.x100.LiteralOutputType;
|
|
|
|
import net.opengis.wps.x100.OutputDescriptionType;
|
|
|
|
import net.opengis.wps.x100.SupportedComplexDataInputType;
|
|
|
|
import net.opengis.wps.x100.SupportedComplexDataType;
|
|
|
|
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.exception.ServiceException;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnListParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnParameter;
|
2019-03-28 18:10:56 +01:00
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Coordinates;
|
2016-10-25 12:46:50 +02:00
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.DateParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.EnumParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.FileParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ListParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ObjectParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularListParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TimeParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.WKTGeometryType;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.WKTParameter;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2016-10-25 12:46:50 +02:00
|
|
|
public class WPS2DM {
|
|
|
|
private final static String SEPARATOR = "|";
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(WPS2DM.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param title
|
2017-05-10 12:44:22 +02:00
|
|
|
* title
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param minOcc
|
2018-05-03 14:43:24 +02:00
|
|
|
* min occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param maxOcc
|
2018-05-03 14:43:24 +02:00
|
|
|
* max occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param rangeOccs
|
2018-05-03 14:43:24 +02:00
|
|
|
* range occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param id
|
2017-05-10 12:44:22 +02:00
|
|
|
* id
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param crs
|
2017-05-10 12:44:22 +02:00
|
|
|
* crs
|
2018-05-03 14:43:24 +02:00
|
|
|
* @return parameter
|
2016-10-25 12:46:50 +02:00
|
|
|
*/
|
2017-05-10 12:44:22 +02:00
|
|
|
public static Parameter manageBoundingBoxInformation(String title, int minOcc, int maxOcc, int rangeOccs, String id,
|
|
|
|
String crs) {
|
2016-10-25 12:46:50 +02:00
|
|
|
Parameter converted = null;
|
2017-05-10 12:44:22 +02:00
|
|
|
title = "Bounding Box Input in OGC 06-121r3 spec. E.g. 102,46,103,47,urn:ogc:def:crs:EPSG:4328 " + title;
|
2016-10-25 12:46:50 +02:00
|
|
|
if (crs != null && crs.length() > 0)
|
|
|
|
title += " Supported CRS " + crs;
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
title = buildParameterDescription(title, null, null, minOcc, maxOcc, null);
|
2016-10-25 12:46:50 +02:00
|
|
|
if ((maxOcc == 1) || (maxOcc < 0) || (maxOcc == 0))
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ObjectParameter(id, title, String.class.getName(), " ");
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
else
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ListParameter(id, title, String.class.getName(), SEPARATOR);
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param title
|
2017-05-10 12:44:22 +02:00
|
|
|
* title
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param minOcc
|
2018-05-03 14:43:24 +02:00
|
|
|
* min occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param maxOcc
|
2017-05-10 12:44:22 +02:00
|
|
|
* max occurences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param rangeOccs
|
2017-05-10 12:44:22 +02:00
|
|
|
* range occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param defaultValue
|
2017-05-10 12:44:22 +02:00
|
|
|
* default value
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param id
|
2017-05-10 12:44:22 +02:00
|
|
|
* id
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param uoms
|
2017-05-10 12:44:22 +02:00
|
|
|
* uoms
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param type
|
2017-05-10 12:44:22 +02:00
|
|
|
* type
|
2018-05-03 14:43:24 +02:00
|
|
|
* @return parameter
|
2016-10-25 12:46:50 +02:00
|
|
|
*/
|
2017-05-10 12:44:22 +02:00
|
|
|
public static Parameter manageLiteral(String title, int minOcc, int maxOcc, int rangeOccs, String defaultValue,
|
|
|
|
String id, String uoms, DomainMetadataType type) {
|
2016-10-25 12:46:50 +02:00
|
|
|
Parameter converted = null;
|
|
|
|
logger.debug("WPS type:" + type.getStringValue());
|
|
|
|
String guessedType = guessWPSLiteralType(type);
|
|
|
|
logger.debug("Guessed type: " + guessedType);
|
|
|
|
|
|
|
|
// rebuild title
|
|
|
|
if ((defaultValue == null || defaultValue.trim().length() == 0))
|
|
|
|
defaultValue = guessDefaultValue(guessedType);
|
|
|
|
|
|
|
|
logger.debug("Guessed default value: " + defaultValue);
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
title = buildParameterDescription(title, null, uoms, minOcc, maxOcc, defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
if ((maxOcc == 1) || (maxOcc < 0) || (maxOcc == 0)) {
|
|
|
|
if (title != null && !title.isEmpty()) {
|
|
|
|
if (title.contains("[a sequence of names of columns from ")) {
|
|
|
|
Pattern pattern = Pattern
|
|
|
|
.compile("a sequence of names of columns from (\\w+) separated by (\\p{ASCII})");
|
|
|
|
Matcher matcher = pattern.matcher(title);
|
|
|
|
logger.debug("Machter title: " + title);
|
|
|
|
logger.debug("Machter find: " + matcher.find());
|
|
|
|
logger.debug("Machter group: " + matcher.group());
|
|
|
|
logger.debug("Machter start: " + matcher.start());
|
|
|
|
logger.debug("Machter end: " + matcher.end());
|
|
|
|
logger.debug("Machter Group Count: " + matcher.groupCount());
|
|
|
|
String referredTabularParameterName = matcher.group(1);
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Matcher referredTabularParameterName: " + referredTabularParameterName);
|
2016-10-25 12:46:50 +02:00
|
|
|
String separator = matcher.group(2);
|
|
|
|
logger.debug("Matcher separator: " + separator);
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ColumnListParameter(id, title, referredTabularParameterName, separator);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[the name of a column from ")) {
|
2017-05-10 12:44:22 +02:00
|
|
|
Pattern pattern = Pattern.compile("the name of a column from (\\w+)");
|
2016-10-25 12:46:50 +02:00
|
|
|
Matcher matcher = pattern.matcher(title);
|
|
|
|
logger.debug("Machter title: " + title);
|
|
|
|
logger.debug("Machter find: " + matcher.find());
|
|
|
|
logger.debug("Machter group: " + matcher.group());
|
|
|
|
logger.debug("Machter start: " + matcher.start());
|
|
|
|
logger.debug("Machter end: " + matcher.end());
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Machter Group Count: " + matcher.groupCount());
|
2016-10-25 12:46:50 +02:00
|
|
|
String referredTabularParameterName = matcher.group(1);
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Matcher referredTabularParameterName: " + referredTabularParameterName);
|
2016-10-25 12:46:50 +02:00
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ColumnParameter(id, title, referredTabularParameterName, defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
2017-05-10 12:44:22 +02:00
|
|
|
if (title.contains("[a sequence of values separated by ")) {
|
|
|
|
Pattern pattern = Pattern.compile("a sequence of values separated by (\\p{ASCII})");
|
2016-10-25 12:46:50 +02:00
|
|
|
Matcher matcher = pattern.matcher(title);
|
|
|
|
logger.debug("Machter title: " + title);
|
|
|
|
logger.debug("Machter find: " + matcher.find());
|
|
|
|
logger.debug("Machter group: " + matcher.group());
|
|
|
|
logger.debug("Machter start: " + matcher.start());
|
|
|
|
logger.debug("Machter end: " + matcher.end());
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Machter Group Count: " + matcher.groupCount());
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
String separator = matcher.group(1);
|
|
|
|
logger.debug("Matcher separator: " + separator);
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ListParameter(id, title, guessedType, separator);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_")) {
|
|
|
|
logger.debug("WKT parameter: " + title);
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = retrieveWKTParameter(id, title, defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[DATE]")) {
|
|
|
|
logger.debug("DATE parameter: " + title);
|
|
|
|
title = title.replace("[DATE]", "");
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new DateParameter(id, title, defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[TIME]")) {
|
|
|
|
logger.debug("TIME parameter: " + title);
|
|
|
|
title = title.replace("[TIME]", "");
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new TimeParameter(id, title, defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ObjectParameter(id, title, guessPrimitiveType(guessedType),
|
2016-10-25 12:46:50 +02:00
|
|
|
defaultValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ObjectParameter(id, title, guessPrimitiveType(guessedType), defaultValue);
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:32:47 +01:00
|
|
|
} else {
|
2017-05-10 12:44:22 +02:00
|
|
|
if (guessedType.compareTo(Boolean.class.getName()) == 0) {
|
2016-11-22 14:32:47 +01:00
|
|
|
converted = new ObjectParameter(id, title, guessedType, defaultValue);
|
|
|
|
} else {
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ListParameter(id, title, String.class.getName(), SEPARATOR);
|
2016-11-22 14:32:47 +01:00
|
|
|
}
|
2017-05-10 12:44:22 +02:00
|
|
|
|
2016-11-22 14:32:47 +01:00
|
|
|
}
|
2016-10-25 12:46:50 +02:00
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
private static Parameter retrieveWKTParameter(String id, String title, String defaultValue) {
|
2016-10-25 12:46:50 +02:00
|
|
|
|
2019-03-28 18:10:56 +01:00
|
|
|
WKTGeometryType wktGeometryType = WKTGeometryType.Polygon;
|
|
|
|
|
2016-10-25 12:46:50 +02:00
|
|
|
if (title.contains("[WKT_POINT]")) {
|
|
|
|
title = title.replace("[WKT_POINT]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Point;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_LINESTRING]")) {
|
|
|
|
title = title.replace("[WKT_LINESTRING]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.LineString;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_POLYGON]")) {
|
|
|
|
title = title.replace("[WKT_POLYGON]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Polygon;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_CIRCLE]")) {
|
|
|
|
title = title.replace("[WKT_CIRCLE]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Circle;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_TRIANGLE]")) {
|
|
|
|
title = title.replace("[WKT_TRIANGLE]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Triangle;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_SQUARE]")) {
|
|
|
|
title = title.replace("[WKT_SQUARE]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Square;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_PENTAGON]")) {
|
|
|
|
title = title.replace("[WKT_PENTAGON]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Pentagon;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_HEXAGON]")) {
|
2017-05-10 12:44:22 +02:00
|
|
|
title = title.replace("[WKT_HEXAGON]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Hexagon;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[WKT_BOX]")) {
|
2017-05-10 12:44:22 +02:00
|
|
|
title = title.replace("[WKT_BOX]", "");
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Box;
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
2019-03-28 18:10:56 +01:00
|
|
|
wktGeometryType = WKTGeometryType.Polygon;
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 18:10:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
Coordinates coordinates = retrieveCoordinates(title);
|
|
|
|
String wktDescription= cleanWKTDescription(title);
|
|
|
|
WKTParameter wktParameter = new WKTParameter(id, wktDescription, wktGeometryType, coordinates, defaultValue);
|
|
|
|
logger.debug("Retrieved WKTParameter: " + wktParameter);
|
|
|
|
return wktParameter;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Coordinates retrieveCoordinates(String title) {
|
|
|
|
logger.debug("Retrieve Coordinates");
|
|
|
|
Coordinates coordinates = null;
|
|
|
|
if (title != null && !title.isEmpty() && title.contains("[COORDS_")) {
|
|
|
|
Pattern pattern = Pattern.compile("\\[COORDS_(.*?)_(.*?)_(.*?)_(.*?)\\]");
|
|
|
|
Matcher matcher = pattern.matcher(title);
|
|
|
|
if (matcher.find()) {
|
|
|
|
logger.debug("Coords Match found");
|
|
|
|
coordinates = new Coordinates(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.debug("Retrieved Coordinates: " + coordinates);
|
|
|
|
return coordinates;
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 18:10:56 +01:00
|
|
|
private static String cleanWKTDescription(String title) {
|
|
|
|
if (title != null && !title.isEmpty()) {
|
|
|
|
int indexStart = title.indexOf("[COORDS_");
|
|
|
|
if (indexStart > -1 && indexStart < title.length()) {
|
|
|
|
String subTitle = title.substring(indexStart);
|
|
|
|
logger.debug("Title without the initial part: " + subTitle);
|
|
|
|
int indexEnd = subTitle.indexOf("]");
|
|
|
|
if (indexEnd > -1 && indexEnd < subTitle.length()) {
|
|
|
|
StringBuilder titleCleaned = new StringBuilder();
|
|
|
|
titleCleaned.append(title.substring(0, indexStart));
|
|
|
|
if (indexEnd + 1 < subTitle.length()) {
|
|
|
|
titleCleaned.append(subTitle.substring(indexEnd + 1));
|
|
|
|
}
|
|
|
|
title = new String(titleCleaned.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.debug("Cleaned Description: " + title);
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2016-10-25 12:46:50 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param maxMegaBytes
|
2017-05-10 12:44:22 +02:00
|
|
|
* max mega bytes
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param title
|
2017-05-10 12:44:22 +02:00
|
|
|
* title
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param minOcc
|
2018-05-03 14:43:24 +02:00
|
|
|
* min occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param maxOcc
|
2018-05-03 14:43:24 +02:00
|
|
|
* max occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param rangeOccs
|
2018-05-03 14:43:24 +02:00
|
|
|
* range occurrences
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param id
|
2017-05-10 12:44:22 +02:00
|
|
|
* id
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param defaultType
|
2017-05-10 12:44:22 +02:00
|
|
|
* default type
|
|
|
|
* @param supportedTypes
|
2018-05-03 14:43:24 +02:00
|
|
|
* supported type
|
|
|
|
* @return parameter
|
2016-10-25 12:46:50 +02:00
|
|
|
*/
|
2017-05-10 12:44:22 +02:00
|
|
|
public static Parameter manageComplexData(String maxMegaBytes, String title, int minOcc, int maxOcc, int rangeOccs,
|
|
|
|
String id, ComplexDataDescriptionType defaultType, ComplexDataDescriptionType[] supportedTypes) {
|
2016-10-25 12:46:50 +02:00
|
|
|
Parameter converted = null;
|
|
|
|
String mimeType = null;
|
|
|
|
String schema = null;
|
|
|
|
String encoding = null;
|
|
|
|
ArrayList<String> supportedMimeTypes = new ArrayList<String>();
|
|
|
|
|
|
|
|
// GenericFileDataConstants.MIME_TYPE_TEXT_XML
|
|
|
|
mimeType = defaultType.getMimeType();
|
|
|
|
schema = defaultType.getSchema();
|
|
|
|
encoding = defaultType.getEncoding();
|
|
|
|
|
|
|
|
logger.debug("Default MimeType: " + mimeType);
|
|
|
|
logger.debug("Default Schema: " + schema);
|
|
|
|
logger.debug("Default Encoding: " + encoding);
|
|
|
|
|
|
|
|
for (ComplexDataDescriptionType supported : supportedTypes) {
|
|
|
|
supportedMimeTypes.add(supported.getMimeType());
|
|
|
|
}
|
|
|
|
// rebuild title
|
2017-05-10 12:44:22 +02:00
|
|
|
title = buildParameterDescription(title, maxMegaBytes, null, minOcc, maxOcc, null);
|
2016-10-25 12:46:50 +02:00
|
|
|
if ((maxOcc == 1) || (maxOcc < 0) || (maxOcc == 0)) {
|
|
|
|
if (title != null && !title.isEmpty()) {
|
|
|
|
if (title.contains("[a http link to a table")) {
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new TabularParameter(id, title, " ", new ArrayList<String>(), mimeType,
|
2016-10-25 12:46:50 +02:00
|
|
|
supportedMimeTypes);
|
|
|
|
} else {
|
|
|
|
if (title.contains("[a http link to a file")) {
|
2018-05-03 14:43:24 +02:00
|
|
|
if (title.contains("[NETCDF]")) {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, true);
|
|
|
|
} else {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, false);
|
|
|
|
}
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
|
|
|
if (title.contains("[a sequence of http links")) {
|
2017-05-10 12:44:22 +02:00
|
|
|
Pattern pattern = Pattern.compile(
|
|
|
|
"\\[a sequence of http links separated by (\\p{ASCII}) , each indicating a table");
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
Matcher matcher = pattern.matcher(title);
|
|
|
|
boolean match = false;
|
|
|
|
if (match = matcher.find()) {
|
|
|
|
logger.debug("Machter title: " + title);
|
|
|
|
logger.debug("Machter find: " + match);
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Machter group: " + matcher.group());
|
|
|
|
logger.debug("Machter start: " + matcher.start());
|
2016-10-25 12:46:50 +02:00
|
|
|
logger.debug("Machter end: " + matcher.end());
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Machter Group Count: " + matcher.groupCount());
|
2016-10-25 12:46:50 +02:00
|
|
|
String separator = matcher.group(1);
|
|
|
|
logger.debug("Matcher separator: " + separator);
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new TabularListParameter(id, title, separator, mimeType,
|
|
|
|
supportedMimeTypes);
|
2016-10-25 12:46:50 +02:00
|
|
|
} else {
|
2018-05-03 14:43:24 +02:00
|
|
|
if (title.contains("[NETCDF]")) {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, true);
|
|
|
|
} else {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, false);
|
|
|
|
}
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-03 14:43:24 +02:00
|
|
|
if (title.contains("[NETCDF]")) {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, true);
|
|
|
|
} else {
|
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, false);
|
|
|
|
}
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-03 14:43:24 +02:00
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, false);
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-03 14:43:24 +02:00
|
|
|
converted = new FileParameter(id, title, mimeType, supportedMimeTypes, false);
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
public static Parameter convert2DMType(InputDescriptionType wpsType) throws ServiceException {
|
2016-10-25 12:46:50 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
String id = wpsType.getIdentifier().getStringValue();
|
|
|
|
|
2017-05-10 12:44:22 +02:00
|
|
|
String title = wpsType.getTitle() != null ? wpsType.getTitle().getStringValue() : "";
|
2016-10-25 12:46:50 +02:00
|
|
|
int minOcc = wpsType.getMinOccurs().intValue();
|
|
|
|
int maxOcc = wpsType.getMaxOccurs().intValue();
|
|
|
|
int rangeOccs = maxOcc - minOcc;
|
|
|
|
if (rangeOccs == 0)
|
|
|
|
rangeOccs = 1;
|
|
|
|
|
|
|
|
// default
|
2017-05-10 12:44:22 +02:00
|
|
|
Parameter converted = new ObjectParameter(id, title, String.class.getName(), " ");
|
2016-10-25 12:46:50 +02:00
|
|
|
if (rangeOccs > 1)
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = new ListParameter(id, title, String.class.getName(), SEPARATOR);
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
// Bounding Boxes
|
|
|
|
if (wpsType.isSetBoundingBoxData()) {
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Conversion to DM Type->" + id + " is a Bounding Box Input");
|
|
|
|
converted = manageBoundingBoxInformation(title, minOcc, maxOcc, rangeOccs, id,
|
|
|
|
wpsType.getBoundingBoxData().getDefault().getCRS());
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
// Literals
|
|
|
|
else if (wpsType.isSetLiteralData()) {
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Conversion to DM Type->" + id + " is a Literal Input");
|
2016-10-25 12:46:50 +02:00
|
|
|
LiteralInputType literal = wpsType.getLiteralData();
|
2017-05-10 12:44:22 +02:00
|
|
|
String uoms = literal.getUOMs() == null ? "" : literal.getUOMs().getDefault().getUOM().getStringValue();
|
2016-10-25 12:46:50 +02:00
|
|
|
String defaultValue = literal.getDefaultValue();
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = manageLiteral(title, minOcc, maxOcc, rangeOccs, defaultValue, id, uoms,
|
|
|
|
literal.getDataType());
|
2016-10-25 12:46:50 +02:00
|
|
|
AllowedValues allowedValues = literal.getAllowedValues();
|
|
|
|
if (allowedValues != null) {
|
|
|
|
ValueType[] values = allowedValues.getValueArray();
|
|
|
|
logger.debug("ValueType[]:" + Arrays.toString(values));
|
|
|
|
List<String> enumValues = new ArrayList<>();
|
|
|
|
|
|
|
|
for (ValueType v : values) {
|
|
|
|
enumValues.add(v.getStringValue());
|
|
|
|
}
|
|
|
|
if (values.length > 1) {
|
|
|
|
ObjectParameter conv = (ObjectParameter) converted;
|
2017-05-10 12:44:22 +02:00
|
|
|
if (conv.getType() != null && !conv.getType().isEmpty()
|
|
|
|
&& conv.getType().compareToIgnoreCase(Boolean.class.getName()) != 0) {
|
|
|
|
converted = new EnumParameter(conv.getName(), conv.getDescription(), enumValues,
|
2016-11-22 14:32:47 +01:00
|
|
|
conv.getDefaultValue());
|
|
|
|
}
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (wpsType.isSetComplexData()) {
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Conversion to DM Type->" + id + " is a Complex Input");
|
|
|
|
SupportedComplexDataInputType complex = wpsType.getComplexData();
|
|
|
|
String maxMegaBytes = complex.getMaximumMegabytes() != null ? complex.getMaximumMegabytes().toString()
|
|
|
|
: "1";
|
2016-10-25 12:46:50 +02:00
|
|
|
logger.debug("Max Megabytes: " + maxMegaBytes);
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = manageComplexData(maxMegaBytes, title, minOcc, maxOcc, rangeOccs, id,
|
|
|
|
complex.getDefault().getFormat(), complex.getSupported().getFormatArray());
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("Conversion to DM Type->Name=" + id);
|
|
|
|
logger.debug("Conversion to DM Type->Title=" + title);
|
2017-05-10 12:44:22 +02:00
|
|
|
logger.debug("Conversion to DM Type->Number of Inputs to Manage=" + rangeOccs);
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
return converted;
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
throw new ServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Parameter convert2DMType(OutputDescriptionType wpsType) {
|
|
|
|
|
|
|
|
String id = wpsType.getIdentifier().getStringValue();
|
2017-05-10 12:44:22 +02:00
|
|
|
String title = wpsType.getTitle() != null ? wpsType.getTitle().getStringValue() : "";
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
// default
|
2017-05-10 12:44:22 +02:00
|
|
|
Parameter converted = new ObjectParameter(id, title, String.class.getName(), " ");
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
logger.debug("Conversion to DM Type->Output id:" + id);
|
|
|
|
logger.debug("Conversion to DM Type->Title:" + title);
|
|
|
|
|
|
|
|
// Bounding Boxes
|
|
|
|
if (wpsType.isSetBoundingBoxOutput()) {
|
|
|
|
logger.debug("Bounding Box Output");
|
|
|
|
converted = manageBoundingBoxInformation(title, -1, -1, -1, id, "");
|
|
|
|
}
|
|
|
|
// Literals
|
|
|
|
else if (wpsType.isSetLiteralOutput()) {
|
|
|
|
logger.debug("Literal Output");
|
|
|
|
LiteralOutputType literal = wpsType.getLiteralOutput();
|
2017-05-10 12:44:22 +02:00
|
|
|
String uoms = literal.getUOMs() == null ? "" : literal.getUOMs().toString();
|
|
|
|
converted = manageLiteral(title, -1, -1, -1, "", id, uoms, literal.getDataType());
|
2016-10-25 12:46:50 +02:00
|
|
|
} else if (wpsType.isSetComplexOutput()) {
|
|
|
|
logger.debug("Complex Output");
|
|
|
|
SupportedComplexDataType complex = wpsType.getComplexOutput();
|
2017-05-10 12:44:22 +02:00
|
|
|
converted = manageComplexData("", title, -1, -1, -1, id, complex.getDefault().getFormat(),
|
|
|
|
complex.getSupported().getFormatArray());
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param title
|
2017-05-10 12:44:22 +02:00
|
|
|
* title
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param maxMegabytes
|
2017-05-10 12:44:22 +02:00
|
|
|
* max mega bytes
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param UoM
|
2018-05-03 14:43:24 +02:00
|
|
|
* UoM
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param minElements
|
2017-05-10 12:44:22 +02:00
|
|
|
* min elements
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param maxElements
|
2017-05-10 12:44:22 +02:00
|
|
|
* max elements
|
2016-10-25 12:46:50 +02:00
|
|
|
* @param defaultValue
|
2017-05-10 12:44:22 +02:00
|
|
|
* default value
|
|
|
|
* @return description
|
2016-10-25 12:46:50 +02:00
|
|
|
*/
|
2017-05-10 12:44:22 +02:00
|
|
|
public static String buildParameterDescription(String title, String maxMegabytes, String UoM, int minElements,
|
|
|
|
int maxElements, String defaultValue) {
|
2016-10-25 12:46:50 +02:00
|
|
|
|
|
|
|
String description = title;
|
|
|
|
/*
|
|
|
|
* String innerDescription = "";
|
|
|
|
*
|
|
|
|
* if (maxMegabytes != null && maxMegabytes.trim().length() > 0) {
|
|
|
|
* innerDescription += "Max MB Size:" + maxMegabytes.trim() + "; "; } if
|
|
|
|
* (UoM != null && UoM.trim().length() > 0) { innerDescription +=
|
|
|
|
* "Unit of Measure:" + UoM.trim() + "; "; } if (minElements > 0) {
|
|
|
|
* innerDescription += "Min N. of Entries:" + minElements + "; "; } if
|
|
|
|
* (maxElements > 0) { innerDescription += "Max N. of Entries:" +
|
|
|
|
* maxElements + "; "; } if (defaultValue != null &&
|
|
|
|
* defaultValue.trim().length() > 0) { innerDescription += "default:" +
|
|
|
|
* defaultValue.trim() + "; "; }
|
|
|
|
*
|
|
|
|
* if (innerDescription.length() > 0) description += " [" +
|
|
|
|
* innerDescription.substring(0,
|
|
|
|
* innerDescription.lastIndexOf(";")).trim() + "]";
|
|
|
|
*/
|
|
|
|
return description;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String guessWPSLiteralType(DomainMetadataType type) {
|
|
|
|
|
|
|
|
if (type == null || type.getStringValue() == null)
|
|
|
|
return String.class.getName();
|
|
|
|
else {
|
|
|
|
String typeS = type.getReference().trim();
|
|
|
|
if (typeS.length() == 0)
|
|
|
|
return String.class.getName();
|
2017-05-10 12:44:22 +02:00
|
|
|
else if (typeS.contains("float") || typeS.contains("double") || typeS.contains("decimal"))
|
2016-10-25 12:46:50 +02:00
|
|
|
return Double.class.getName();
|
|
|
|
else if (typeS.contains("int"))
|
|
|
|
return Integer.class.getName();
|
|
|
|
else if (typeS.contains("long"))
|
|
|
|
return Long.class.getName();
|
|
|
|
else if (typeS.contains("short"))
|
|
|
|
return Short.class.getName();
|
2016-11-22 14:32:47 +01:00
|
|
|
else if (typeS.contains("boolean"))
|
|
|
|
return Boolean.class.getName();
|
2017-05-10 12:44:22 +02:00
|
|
|
|
2016-10-25 12:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return String.class.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String guessDefaultValue(String type) {
|
|
|
|
if (type.equals(String.class.getName()))
|
|
|
|
return " ";
|
|
|
|
else
|
|
|
|
return "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String guessPrimitiveType(String type) {
|
2017-05-10 12:44:22 +02:00
|
|
|
|
2016-10-25 12:46:50 +02:00
|
|
|
if (type.equals(Integer.class.getName())) {
|
|
|
|
return Integer.class.getName();
|
|
|
|
} else if (type.equals(String.class.getName())) {
|
|
|
|
return String.class.getName();
|
|
|
|
} else if (type.equals(Boolean.class.getName())) {
|
|
|
|
return Boolean.class.getName();
|
|
|
|
} else if (type.equals(Double.class.getName())) {
|
|
|
|
return Double.class.getName();
|
|
|
|
} else if (type.equals(Float.class.getName())) {
|
|
|
|
return Float.class.getName();
|
|
|
|
} else
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|