use of org.geotoolkit.wps.xml.v200.Description in project geotoolkit by Geomatys.
the class WPS2ProcessDescriptor method create.
public static ProcessDescriptor create(WPSProcessingRegistry registry, final String processIdentifier) throws Exception {
final ProcessOfferings offerings = registry.getClient().getDescribeProcess(Collections.singletonList(processIdentifier));
final List<ProcessOffering> offeringList = offerings.getProcessOffering();
if (offeringList == null || offeringList.isEmpty()) {
throw new RuntimeException("No process description has been found for identifier " + processIdentifier);
} else if (offeringList.size() != 1) {
throw new RuntimeException(String.format("We asked for exactly one process descriptor (%s), but we've got %d results.", processIdentifier, offeringList.size()));
}
final ProcessOffering offering = offeringList.get(0);
return create(registry, offering);
}
use of org.geotoolkit.wps.xml.v200.Description in project geotoolkit by Geomatys.
the class WPS2ProcessDescriptor method toDescriptor.
/**
* Convert Description to GeneralParameterDescriptor.
*
* @throws UnsupportedOperationException if data type could not be mapped
*/
private static GeneralParameterDescriptor toDescriptor(String processId, Description input) throws UnsupportedParameterException {
final List<? extends Description> subInputs;
final DataDescription dataDescType;
final int min;
final int max;
if (input instanceof InputDescription) {
final InputDescription id = (InputDescription) input;
subInputs = id.getInput();
dataDescType = id.getDataDescription();
max = id.getMaxOccurs();
min = id.getMinOccurs();
} else if (input instanceof OutputDescription) {
final OutputDescription od = (OutputDescription) input;
subInputs = od.getOutput();
dataDescType = od.getDataDescription();
min = 1;
max = 1;
} else {
throw new IllegalArgumentException("Unexpected description type " + input.getClass());
}
final String inputName = input.getIdentifier().getValue();
final String title = input.getFirstTitle();
final String remarks = input.getFirstAbstract();
Map userObject = new HashMap();
for (MetadataType meta : input.getMetadata()) {
if (meta instanceof AdditionalParametersType) {
AdditionalParametersType params = (AdditionalParametersType) meta;
for (AdditionalParameter param : params.getAdditionalParameter()) {
userObject.put(param.getName().getValue(), param.getValue());
}
}
}
if (dataDescType instanceof LiteralData) {
final LiteralData cd = (LiteralData) dataDescType;
for (LiteralDataDomain domain : cd.getLiteralDataDomain()) {
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
if (adaptor == null)
continue;
String defaultValueValue = null;
final ValueType defaultValue = domain.getDefaultValue();
if (defaultValue != null)
defaultValueValue = defaultValue.getValue();
final Unit unit = getUnit(domain.getUOM());
Object[] allowedValues = null;
if (domain.getAllowedValues() != null && domain.getAllowedValues().getStringValues() != null) {
allowedValues = new Object[domain.getAllowedValues().getStringValues().size()];
int i = 0;
for (String value : domain.getAllowedValues().getStringValues()) {
allowedValues[i] = adaptor.convert(value);
i++;
}
}
try {
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), adaptor.convert(defaultValueValue), allowedValues, userObject);
} catch (UnconvertibleObjectException ex2) {
throw new UnsupportedParameterException(processId, inputName, "Can't convert the default literal input value.", ex2);
}
}
throw new UnsupportedParameterException(processId, inputName, "Unidentifiable literal input " + inputName);
} else if (dataDescType instanceof ComplexData) {
final ComplexData cdt = (ComplexData) dataDescType;
// ensure default format is first in the list
Collections.sort(cdt.getFormat(), (Format o1, Format o2) -> {
boolean d1 = Boolean.TRUE.equals(o1.isDefault());
boolean d2 = Boolean.TRUE.equals(o2.isDefault());
if (d1 == d2)
return 0;
return d1 ? -1 : +1;
});
// find a complexe type adaptor
DataAdaptor adaptor = null;
for (Format format : cdt.getFormat()) {
adaptor = ComplexAdaptor.getAdaptor(format);
if (adaptor != null)
break;
}
if (adaptor == null) {
final StringBuilder sb = new StringBuilder();
for (Format format : cdt.getFormat()) {
if (sb.length() != 0)
sb.append(", ");
sb.append(format.getMimeType()).append(' ');
sb.append(format.getEncoding()).append(' ');
sb.append(format.getSchema());
}
throw new UnsupportedParameterException(processId, inputName, "No compatible format found for parameter " + inputName + " formats : " + sb);
}
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), null, null, userObject);
} else if (dataDescType instanceof BoundingBoxData) {
final BboxAdaptor adaptor = BboxAdaptor.create((BoundingBoxData) dataDescType);
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, Envelope.class, null, null, userObject);
} else if (!subInputs.isEmpty()) {
// sub group type
final List<GeneralParameterDescriptor> params = new ArrayList<>();
for (Description dt : subInputs) {
params.add(toDescriptor(processId, dt));
}
return new ParameterBuilder().addName(inputName).addName(title).setRemarks(remarks).createGroup(params.toArray(new GeneralParameterDescriptor[0]));
} else {
throw new UnsupportedParameterException(processId, inputName, "Unidentifiable input " + inputName + " " + dataDescType);
}
}
use of org.geotoolkit.wps.xml.v200.Description in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method initPath.
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
setMode(Mode.ARCHIVE);
pathToDescriptionMap = new HashMap<>();
wsdlArchiveExtractedPath = path;
WSDLReader reader;
try {
reader = getWsdlFactoryInstance().newWSDLReader();
} catch (WSDLException e) {
throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
}
reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
File folderToImport = new File(path);
Collection<File> foundWSDLFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, "wsdl");
if (log.isDebugEnabled()) {
log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
}
try {
for (File file : foundWSDLFiles) {
if (log.isDebugEnabled()) {
log.debug("Processing WSDL file: " + file.getAbsolutePath());
}
Document document = getSecuredParsedDocumentFromPath(file.getAbsolutePath());
WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
Description description = reader.readWSDL(wsdlSource);
pathToDescriptionMap.put(file.getAbsolutePath(), description);
}
if (foundWSDLFiles.isEmpty()) {
setError(ExceptionCodes.NO_WSDL_FOUND_IN_WSDL_ARCHIVE);
}
if (log.isDebugEnabled()) {
log.debug("Successfully processed all WSDL files in path " + path);
}
} catch (WSDLException e) {
// This implementation class cannot process the WSDL. Continuing after setting canProcess = false
log.debug(this.getClass().getName() + " was unable to process the WSDL Files for the path: " + path, e);
setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
}
return !hasError;
}
use of org.geotoolkit.wps.xml.v200.Description in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method updateEndpointsOfWSDLArchive.
/**
* Update the endpoint information of the WSDL (WSDL archive scenario) when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfWSDLArchive(API api, String environmentName, String environmentType) throws APIMgtWSDLException {
for (Map.Entry<String, Description> entry : pathToDescriptionMap.entrySet()) {
Description description = entry.getValue();
if (log.isDebugEnabled()) {
log.debug("Updating endpoints of WSDL: " + entry.getKey());
}
updateEndpointsOfSingleWSDL(api, environmentName, environmentType, description);
if (log.isDebugEnabled()) {
log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
}
try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
writer.writeWSDL(description.toElement(), wsdlFileOutputStream);
} catch (IOException | WSDLException e) {
throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getId().getName() + ":" + api.getId().getVersion() + " for environment " + environmentName, e, ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
}
}
}
use of org.geotoolkit.wps.xml.v200.Description in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method getEndpoints.
/**
* Get endpoints defined in WSDL file(s).
*
* @return a Map of endpoint names and their URIs.
* @throws APIMgtWSDLException if error occurs while reading endpoints
*/
private Map<String, String> getEndpoints() throws APIMgtWSDLException {
if (Mode.SINGLE.equals(getMode())) {
return getEndpoints(wsdlDescription);
} else {
Map<String, String> allEndpointsOfAllWSDLs = new HashMap<>();
for (Description description : pathToDescriptionMap.values()) {
Map<String, String> wsdlEndpoints = getEndpoints(description);
allEndpointsOfAllWSDLs.putAll(wsdlEndpoints);
}
return allEndpointsOfAllWSDLs;
}
}
Aggregations