Search in sources :

Example 11 with Data

use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.

the class LiteralAdaptorTest method booleanWPS2.

@Test
public void booleanWPS2() {
    final DomainMetadataType metaType = new DomainMetadataType(null, "xs:boolean");
    final LiteralDataDomain domain = new LiteralDataDomain();
    domain.setDataType(metaType);
    final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
    assertEquals(Boolean.class, adaptor.getValueClass());
    final DataOutput output = new DataOutput();
    final LiteralValue lit = new LiteralValue();
    lit.setValue("true");
    final Data data = new Data(lit);
    output.setData(data);
    final Object result = adaptor.fromWPS2Input(output);
    assertEquals(true, result);
}
Also used : DomainMetadataType(org.geotoolkit.ows.xml.v200.DomainMetadataType) DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) Data(org.geotoolkit.wps.xml.v200.Data) LiteralDataDomain(org.geotoolkit.wps.xml.v200.LiteralDataDomain) Test(org.junit.Test)

Example 12 with Data

use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.

the class ConvertersTestUtils method initAndRunOutputConversion.

/**
 * Helper method to initialize a converter and run with its parameters.
 *
 * The converters are the one that convert Geometry or Feature types to
 * Complex or Reference.
 *
 * The method is in charge of setting up the parameters map, the resource
 * (either a java URL or String containg json datas) and calling conversion
 * method.
 *
 * @param <SourceType> type of the input data in the conversion
 * @param <TargetType> type of the output data in the conversion
 * @param sourceClass class of the input data in the conversion
 * @param targetClass class of the output dat in the conversion
 * @param resource resource to give as input to the converter (must be of the
 * same type as SourceType)
 * @param mimeType mime type of the input data
 * @param encoding encoding of the input data
 *
 * @return an instance of TargetType which is the result of a call to the converter
 *
 * @throws IOException on reading the test resource
 * @throws IllegalArgumentException when mimeType or encoding is empty
 * @throws NullArgumentException when an argument is null
 */
public static <SourceType, TargetType> TargetType initAndRunOutputConversion(Class sourceClass, Class targetClass, Object resource, String mimeType, String encoding) throws IOException {
    ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
    ArgumentChecks.ensureNonNull("targetClass", targetClass);
    ArgumentChecks.ensureNonNull("resource", resource);
    ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
    ArgumentChecks.ensureNonEmpty("encoding", encoding);
    // Get converter
    final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
    // Setup the parameters map
    Path tmpDirPath;
    Map<String, Object> parametersMap = null;
    if (targetClass.equals(Data.class))
        parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding);
    else if (targetClass.equals(Reference.class)) {
        tmpDirPath = Files.createTempDirectory(UUID.randomUUID().toString());
        parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding, tmpDirPath.toUri().toString(), WPSIO.IOType.OUTPUT.toString());
    } else
        fail();
    return converter.convert((SourceType) resource, parametersMap);
}
Also used : Path(java.nio.file.Path) Reference(org.geotoolkit.wps.xml.v200.Reference) GeoJSONObject(org.geotoolkit.internal.geojson.binding.GeoJSONObject)

Example 13 with Data

use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.

the class ConvertersTestUtils method initAndRunInputConversion.

/**
 * Helper method to initialize a converter and run with its parameters.
 *
 * The converters are the ones that convert Complex or reference to Geometry
 * or Feature types.
 *
 * The method is in charge of setting up the parameters map, the resource
 * (either a java URL or String containg json datas) and calling conversion
 * method.
 *
 * @param <SourceType> type of the input data in the conversion
 * @param <TargetType> type of the output data in the conversion
 * @param sourceClass class of the input data in the conversion
 * @param targetClass class of the output dat in the conversion
 * @param resourcePath url to the resource file to read
 * @param mimeType mime type of the input data
 * @param encoding encoding of the input data
 * @param schema schema for the input data (only arguments that can be null)
 * @return an instance of TargetType which is the result of a call to the converter
 * @throws IOException on reading the test resource
 * @throws IllegalArgumentException when one of the String arguments is null
 * @throws NullArgumentException when one of the arguments is null
 */
public static <SourceType, TargetType> TargetType initAndRunInputConversion(Class sourceClass, Class targetClass, String resourcePath, String mimeType, String encoding, String schema) throws IOException {
    ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
    ArgumentChecks.ensureNonNull("targetClass", targetClass);
    ArgumentChecks.ensureNonEmpty("resourcePath", resourcePath);
    ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
    ArgumentChecks.ensureNonEmpty("encoding", encoding);
    // Get the converter to test
    final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
    // Setup parameters map
    final Map<String, Object> param = ConvertersTestUtils.createParameters(mimeType, encoding);
    // Setup the resource and run conversion
    if (sourceClass.equals(Data.class)) {
        final String resource = ConvertersTestUtils.getTestResource(ConvertersTestUtils.class, resourcePath);
        final Data complex = ConvertersTestUtils.createComplex(mimeType, encoding, schema, resource);
        return converter.convert((SourceType) complex, param);
    } else if (sourceClass.equals(Reference.class)) {
        final URL resource = ConvertersTestUtils.class.getResource(resourcePath);
        final Reference reference = ConvertersTestUtils.createReference("1.0.0", mimeType, encoding, schema, resource);
        return converter.convert((SourceType) reference, param);
    } else {
        fail();
        return null;
    }
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference) GeoJSONObject(org.geotoolkit.internal.geojson.binding.GeoJSONObject) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) URL(java.net.URL) TMP_DIR_URL(org.geotoolkit.wps.converters.WPSObjectConverter.TMP_DIR_URL)

Example 14 with Data

use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.

the class ComplexToCoverageConverterTest method testConversion.

@Test
@org.junit.Ignore("Fails randomly because of GeoTIFF reader not found.")
public void testConversion() throws UnconvertibleObjectException, IOException, InterruptedException {
    final WPSObjectConverter<Data, GridCoverage> converter = WPSConverterRegistry.getInstance().getConverter(Data.class, GridCoverage.class);
    final InputStream expectedStream = ComplexToRenderedImageConvereterTest.class.getResourceAsStream("/expected/coverage_base64");
    assertNotNull(expectedStream);
    final String encodedCoverage = IOUtilities.toString(expectedStream);
    final Map<String, Object> param = new HashMap<String, Object>();
    param.put(WPSObjectConverter.MIME, "image/x-geotiff");
    param.put(WPSObjectConverter.ENCODING, "base64");
    final Format format = new Format("base64", "image/x-geotiff", null, null);
    final Data complex = new Data(format, encodedCoverage);
    complex.getContent().add(encodedCoverage);
    final GridCoverage convertedCoverage = converter.convert(complex, param);
    assertNotNull(convertedCoverage);
    final GridCoverage expectedCoverage = ConvertersTestUtils.makeCoverage();
    final Envelope convertedEnvelope = convertedCoverage.getGridGeometry().getEnvelope();
    final Envelope expectedEnvelope = expectedCoverage.getGridGeometry().getEnvelope();
    assertTrue(Utilities.equalsIgnoreMetadata(expectedEnvelope.getCoordinateReferenceSystem(), convertedEnvelope.getCoordinateReferenceSystem()));
    assertTrue(expectedEnvelope.getMinimum(0) == convertedEnvelope.getMinimum(0));
    assertTrue(expectedEnvelope.getMinimum(1) == convertedEnvelope.getMinimum(1));
    assertTrue(expectedEnvelope.getMaximum(0) == convertedEnvelope.getMaximum(0));
    assertTrue(expectedEnvelope.getMaximum(1) == convertedEnvelope.getMaximum(1));
    Assert.assertRasterEquals(expectedCoverage.render(null), convertedCoverage.render(null));
}
Also used : Format(org.geotoolkit.wps.xml.v200.Format) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Data(org.geotoolkit.wps.xml.v200.Data) Envelope(org.opengis.geometry.Envelope) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 15 with Data

use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.

the class FeatureCollectionToComplexConverterTest method testJSONConversion.

@Test
public void testJSONConversion() throws Exception {
    // Get test resource
    Object testResource = ConvertersTestUtils.loadTestResource("/inputs/featurecollection.json");
    Data complex = ConvertersTestUtils.initAndRunOutputConversion(FeatureCollection.class, Data.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
    // Test complex
    ConvertersTestUtils.assertFormatMatch(complex, WPSEncoding.UTF8.getValue(), WPSMimeType.APP_GEOJSON.val(), null);
    ConvertersTestUtils.useDataContentAsFile(complex, file -> {
        // that we gave as input to the converter
        try {
            FeatureSet readFeatureCollection = WPSConvertersUtils.readFeatureCollectionFromJson(file.toUri());
            ConvertersTestUtils.assertFeatureCollectionIsValid(readFeatureCollection);
        } catch (DataStoreException | URISyntaxException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Data(org.geotoolkit.wps.xml.v200.Data) FeatureSet(org.apache.sis.storage.FeatureSet) UncheckedIOException(java.io.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Data (org.geotoolkit.wps.xml.v200.Data)42 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)33 IOException (java.io.IOException)25 Test (org.junit.Test)19 Reference (org.geotoolkit.wps.xml.v200.Reference)16 Path (java.nio.file.Path)15 DataInput (org.geotoolkit.wps.xml.v200.DataInput)15 Format (org.geotoolkit.wps.xml.v200.Format)14 DataStoreException (org.apache.sis.storage.DataStoreException)12 HashMap (java.util.HashMap)11 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)11 JAXBException (javax.xml.bind.JAXBException)9 ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)9 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)8 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)8 Feature (org.opengis.feature.Feature)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)7 Geometry (org.locationtech.jts.geom.Geometry)7 DataOutput (org.geotoolkit.wps.xml.v200.DataOutput)6