Search in sources :

Example 6 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project dishevelled-bio by heuermh.

the class TraversePaths method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGfa1File);
        writer = writer(outputGfa1File);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                Gfa1Writer.write(gfa1Record, w);
                if (gfa1Record instanceof Path) {
                    Path path = (Path) gfa1Record;
                    int size = path.getSegments().size();
                    Reference source = null;
                    Reference target = null;
                    String overlap = null;
                    for (int i = 0; i < size; i++) {
                        target = path.getSegments().get(i);
                        if (i > 0) {
                            overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
                        }
                        if (source != null) {
                            Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
                            Gfa1Writer.write(traversal, w);
                        }
                        source = target;
                    }
                }
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Path(org.dishevelled.bio.assembly.gfa1.Path) Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) Reference(org.dishevelled.bio.assembly.gfa1.Reference) BufferedReader(java.io.BufferedReader) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 7 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project cel-java by projectnessie.

the class Checker method resolveOverload.

OverloadResolution resolveOverload(Location loc, Decl fn, Expr.Builder target, List<Expr.Builder> args) {
    List<Type> argTypes = new ArrayList<>();
    if (target != null) {
        Type argType = getType(target);
        if (argType == null) {
            throw new ErrException("Could not resolve type for target '%s'", target);
        }
        argTypes.add(argType);
    }
    for (int i = 0; i < args.size(); i++) {
        Expr.Builder arg = args.get(i);
        Type argType = getType(arg);
        if (argType == null) {
            throw new ErrException("Could not resolve type for argument %d '%s'", i, arg);
        }
        argTypes.add(argType);
    }
    Type resultType = null;
    Reference checkedRef = null;
    for (Overload overload : fn.getFunction().getOverloadsList()) {
        if ((target == null && overload.getIsInstanceFunction()) || (target != null && !overload.getIsInstanceFunction())) {
            // not a compatible call style.
            continue;
        }
        Type overloadType = Decls.newFunctionType(overload.getResultType(), overload.getParamsList());
        if (overload.getTypeParamsCount() > 0) {
            // Instantiate overload's type with fresh type variables.
            Mapping substitutions = newMapping();
            for (String typePar : overload.getTypeParamsList()) {
                substitutions.add(Decls.newTypeParamType(typePar), newTypeVar());
            }
            overloadType = substitute(substitutions, overloadType, false);
        }
        List<Type> candidateArgTypes = overloadType.getFunction().getArgTypesList();
        if (isAssignableList(argTypes, candidateArgTypes)) {
            if (checkedRef == null) {
                checkedRef = newFunctionReference(Collections.singletonList(overload.getOverloadId()));
            } else {
                checkedRef = checkedRef.toBuilder().addOverloadId(overload.getOverloadId()).build();
            }
            // First matching overload, determines result type.
            Type fnResultType = substitute(mappings, overloadType.getFunction().getResultType(), false);
            if (resultType == null) {
                resultType = fnResultType;
            } else if (!isDyn(resultType) && !fnResultType.equals(resultType)) {
                resultType = Decls.Dyn;
            }
        }
    }
    if (resultType == null) {
        errors.noMatchingOverload(loc, fn.getName(), argTypes, target != null);
        // resultType = Decls.Error;
        return null;
    }
    return newResolution(checkedRef, resultType);
}
Also used : CheckerEnv.getObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType) CheckerEnv.isObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType) CheckerEnv.dynElementType(org.projectnessie.cel.checker.CheckerEnv.dynElementType) Type(com.google.api.expr.v1alpha1.Type) MapType(com.google.api.expr.v1alpha1.Type.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType) Expr(com.google.api.expr.v1alpha1.Expr) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) Overload(com.google.api.expr.v1alpha1.Decl.FunctionDecl.Overload) ErrException(org.projectnessie.cel.common.types.Err.ErrException) Reference(com.google.api.expr.v1alpha1.Reference) ArrayList(java.util.ArrayList) Mapping.newMapping(org.projectnessie.cel.checker.Mapping.newMapping)

Example 8 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference 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 9 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference 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 10 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.

the class ReferenceToGridCoverage2DConverterTest method testConversionBase64.

@Test
@org.junit.Ignore("Fails randomly because of GeoTIFF reader not found.")
public void testConversionBase64() throws UnconvertibleObjectException, IOException {
    final WPSObjectConverter<Reference, GridCoverage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, GridCoverage.class);
    final URL coverageBase64 = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/coverage_geotiff_base64");
    assertNotNull(coverageBase64);
    final Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
    parameters.put(AbstractReferenceInputConverter.ENCODING, "base64");
    final Reference reference = new Reference();
    reference.setHref(coverageBase64.toString());
    reference.setMimeType("image/x-geotiff");
    reference.setEncoding("base64");
    final GridCoverage convertedCvg = converter.convert(reference, parameters);
    assertNotNull(convertedCvg);
    final GridCoverage expectedCvg = ConvertersTestUtils.makeCoverage();
    final Envelope convertedEnvelope = convertedCvg.getGridGeometry().getEnvelope();
    final Envelope expectedEnvelope = expectedCvg.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(expectedCvg.render(null), convertedCvg.render(null));
}
Also used : GridCoverage(org.apache.sis.coverage.grid.GridCoverage) HashMap(java.util.HashMap) Reference(org.geotoolkit.wps.xml.v200.Reference) Envelope(org.opengis.geometry.Envelope) URL(java.net.URL) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Aggregations

Reference (org.geotoolkit.wps.xml.v200.Reference)34 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)17 Path (java.nio.file.Path)14 Test (org.junit.Test)11 IOException (java.io.IOException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 JAXBException (javax.xml.bind.JAXBException)6 AbstractWPSConverterTest (org.geotoolkit.wps.converters.AbstractWPSConverterTest)6 ArrayList (java.util.ArrayList)5 Feature (org.opengis.feature.Feature)5 BufferedReader (java.io.BufferedReader)4 DataStoreException (org.apache.sis.storage.DataStoreException)4 Geometry (org.locationtech.jts.geom.Geometry)4 RenderedImage (java.awt.image.RenderedImage)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 Reference (com.google.api.expr.v1alpha1.Reference)2 HashBasedTable (com.google.common.collect.HashBasedTable)2