use of org.geotoolkit.wps.xml.v200.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 org.geotoolkit.wps.xml.v200.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 org.geotoolkit.wps.xml.v200.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.");
}
use of org.geotoolkit.wps.xml.v200.Reference in project geotoolkit by Geomatys.
the class ComplexAdaptor method toWPS2Input.
/**
* Convert java object to WPS-2 input.
*
* <p>
* Default implementation of this method only support objects of type Reference.
* </p>
*
* @param candidate
* @return
*/
@Override
public DataInput toWPS2Input(T candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy) {
final Reference reference = ((ReferenceProxy) candidate).getReference();
final Reference ref;
if (reference instanceof Reference) {
ref = (Reference) reference;
} else {
ref = new Reference();
ref.setHref(reference.getHref());
ref.setEncoding(reference.getEncoding());
ref.setMimeType(reference.getMimeType());
ref.setSchema(reference.getSchema());
ref.setBody(reference.getBody());
}
final DataInput dit = new DataInput();
dit.setReference(ref);
return dit;
}
throw new UnconvertibleObjectException("Unsupported value.");
}
use of org.geotoolkit.wps.xml.v200.Reference in project eclipselink by eclipse-ee4j.
the class MetadataResource method buildEntitySchemaResponse.
private Response buildEntitySchemaResponse(String version, String persistenceUnit, String entityName, UriInfo uriInfo) {
JPARSLogger.entering(CLASS_NAME, "buildEntitySchemaResponse", new Object[] { "GET", version, persistenceUnit, uriInfo.getRequestUri().toASCIIString() });
final String result;
try {
final PersistenceContext context = getPersistenceContext(persistenceUnit, null, uriInfo.getBaseUri(), version, null);
final ClassDescriptor descriptor = context.getServerSession().getDescriptorForAlias(entityName);
if (descriptor == null) {
JPARSLogger.error(context.getSessionLog(), "jpars_could_not_find_entity_type", new Object[] { entityName, persistenceUnit });
throw JPARSException.classOrClassDescriptorCouldNotBeFoundForEntity(entityName, persistenceUnit);
} else {
final ResourceSchema schema = new ResourceSchema();
schema.setTitle(descriptor.getAlias());
schema.setSchema(HrefHelper.buildEntityMetadataHref(context, descriptor.getAlias()) + "#");
schema.addAllOf(new Reference(HrefHelper.buildBaseRestSchemaRef("#/singularResource")));
// Properties
for (DatabaseMapping databaseMapping : descriptor.getMappings()) {
schema.addProperty(databaseMapping.getAttributeName(), buildProperty(context, databaseMapping));
}
// Links
final String instancesHref = HrefHelper.buildEntityDescribesHref(context, descriptor.getAlias());
schema.setLinks((new ItemLinksBuilder()).addDescribedBy(HrefHelper.buildEntityMetadataHref(context, descriptor.getAlias())).addFind(instancesHref + "/{primaryKey}").addCreate(instancesHref).addUpdate(instancesHref).addDelete(instancesHref + "/{primaryKey}").getList());
result = marshallMetadata(schema, MediaType.APPLICATION_JSON);
}
} catch (JAXBException e) {
throw JPARSException.exceptionOccurred(e);
}
return Response.ok(new StreamingOutputMarshaller(null, result, AbstractResource.APPLICATION_SCHEMA_JSON_TYPE)).build();
}
Aggregations