use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class UrlConnectionToReferenceConverter method convert.
@Override
public Reference convert(URLConnection source, Map<String, Object> params) throws UnconvertibleObjectException {
final Reference reference = new Reference();
reference.setHref(source.getURL().toString());
mapParameters(reference, params);
return reference;
}
use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class UrlToReferenceConverter method convert.
@Override
public Reference convert(URL source, Map<String, Object> params) throws UnconvertibleObjectException {
final Reference reference = new Reference();
reference.setHref(source.toString());
mapParameters(reference, params);
return reference;
}
use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class CoverageToReferenceConverter method convert.
/**
* {@inheritDoc}
*/
@Override
public Reference convert(final GridCoverage source, final Map<String, Object> params) throws UnconvertibleObjectException {
if (params.get(TMP_DIR_PATH) == null) {
throw new UnconvertibleObjectException("The output directory should be defined.");
}
if (source == null) {
throw new UnconvertibleObjectException("The output data should be defined.");
}
Reference reference = new Reference();
final String encodingStr = (String) params.get(ENCODING);
final String mimeStr = (String) params.get(MIME) != null ? (String) params.get(MIME) : WPSMimeType.IMG_GEOTIFF.val();
final WPSMimeType mime = WPSMimeType.customValueOf(mimeStr);
reference.setMimeType(mimeStr);
reference.setEncoding(encodingStr);
reference.setSchema((String) params.get(SCHEMA));
final String formatName;
final String[] formatNames = XImageIO.getFormatNamesByMimeType(mimeStr, true, true);
formatName = (formatNames.length < 1) ? "GEOTIFF" : formatNames[0];
final String randomFileName = UUID.randomUUID().toString();
try {
final Path imageFile = buildPath(params, randomFileName);
if (encodingStr != null && encodingStr.equals(WPSEncoding.BASE64.getValue())) {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
CoverageIO.write(source, formatName, baos);
baos.flush();
byte[] bytesOut = baos.toByteArray();
IOUtilities.writeString(Base64.getEncoder().encodeToString(bytesOut), imageFile);
}
} else {
// Note : do not do OutputStream out = Files.newOutputStream(imageFile, StandardOpenOption.CREATE, WRITE, TRUNCATE_EXISTING)
// Most coverage writer do not support stream writing properly, it is better to work with a file.
// This also avoid keeping large files in memory if byte buffer seeking is needed by the writer.
Files.deleteIfExists(imageFile);
CoverageIO.write(source, formatName, imageFile);
}
final String relLoc = getRelativeLocation(imageFile, params);
reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
} catch (IOException | DataStoreException ex) {
throw new UnconvertibleObjectException("Error during writing the coverage in the output file.", ex);
}
return reference;
}
use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class WPSConvertersUtils method featureToParameterGroup.
/**
* Convert a feature into a ParameterValueGroup.
*
* This function will try to convert objects if their types doesn't match between feature and parameter.
* Then fill a ParameterValueGroup which contains data of the feature in parameter.
*
* @param version WPS version
* @param toConvert The feature to transform.
* @param toFill The descriptor of the ParameterValueGroup which will be created.
*/
public static void featureToParameterGroup(String version, Feature toConvert, ParameterValueGroup toFill) throws UnconvertibleObjectException {
ArgumentChecks.ensureNonNull("feature", toConvert);
ArgumentChecks.ensureNonNull("ParameterGroup", toFill);
final WPSConverterRegistry registry = WPSConverterRegistry.getInstance();
final Parameters toFill2 = Parameters.castOrWrap(toFill);
for (final GeneralParameterDescriptor gpd : toFill.getDescriptor().descriptors()) {
if (gpd instanceof ParameterDescriptor) {
final Property prop = toConvert.getProperty(gpd.getName().getCode());
if (prop == null && gpd.getMinimumOccurs() > 0) {
throw new UnconvertibleObjectException("A mandatory attribute can't be found");
}
final ParameterDescriptor desc = (ParameterDescriptor) gpd;
if (prop.getValue().getClass().isAssignableFrom(desc.getValueClass()) || desc.getValueClass().isAssignableFrom(prop.getValue().getClass())) {
toFill2.getOrCreate(desc).setValue(prop.getValue());
} else {
if (prop.getValue().getClass().isAssignableFrom(URI.class)) {
Reference type = UriToReference(version, (URI) prop.getValue(), WPSIO.IOType.INPUT, null);
WPSObjectConverter converter = registry.getConverter(type.getClass(), desc.getValueClass());
toFill2.getOrCreate(desc).setValue(converter.convert(type, null));
}
}
} else if (gpd instanceof ParameterDescriptorGroup) {
final Collection<Feature> propCollection = (Collection<Feature>) toConvert.getPropertyValue(gpd.getName().getCode());
int filledGroups = 0;
for (Feature complex : propCollection) {
ParameterValueGroup childGroup = toFill.addGroup(gpd.getName().getCode());
featureToParameterGroup(version, complex, childGroup);
filledGroups++;
}
if (filledGroups < gpd.getMinimumOccurs()) {
throw new UnconvertibleObjectException("Not enough attributes have been found.");
}
} else {
throw new UnconvertibleObjectException("Parameter type is not managed.");
}
}
}
use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class GMLAdaptor method fromWPS2Input.
@Override
public Object fromWPS2Input(DataOutput candidate) throws UnconvertibleObjectException {
final Reference ref = candidate.getReference();
if (ref != null) {
return WPSConvertersUtils.convertFromReference(ref, FeatureSet.class);
}
final Data data = candidate.getData();
if (data != null) {
return WPSConvertersUtils.convertFromComplex(gmlVersion, data, FeatureSet.class);
}
throw new UnconvertibleObjectException("Niether reference or data is filled.");
}
Aggregations