Search in sources :

Example 46 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class AbstractReferenceInputConverter method connect.

protected static URLConnection connect(final Reference ref) throws UnconvertibleObjectException {
    final String brutHref;
    if (ref == null || (brutHref = ref.getHref()) == null) {
        throw new UnconvertibleObjectException("Null reference given.");
    }
    final URL href;
    try {
        final String decoded = URLDecoder.decode(brutHref, "UTF-8");
        href = new URL(decoded);
    } catch (UnsupportedEncodingException | MalformedURLException ex) {
        throw new UnconvertibleObjectException("Invalid reference href: " + brutHref, ex);
    }
    final URLConnection connection;
    try {
        connection = href.openConnection();
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Cannot connect to reference url:" + href, ex);
    }
    for (final Reference.Header header : ref.getHeader()) {
        connection.addRequestProperty(header.getKey(), header.getValue());
    }
    addBody(connection, ref.getBody(), ref.getBodyReference());
    return connection;
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) MalformedURLException(java.net.MalformedURLException) Reference(org.geotoolkit.wps.xml.v200.Reference) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 47 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class BooleanToReferenceConverter method convert.

@Override
public Reference convert(final Boolean 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();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    reference.setSchema((String) params.get(SCHEMA));
    reference.setMimeType("text/plain");
    reference.setEncoding("UTF-8");
    reference.setSchema(null);
    final String randomFileName = UUID.randomUUID().toString();
    try {
        // create file
        final Path literalFile = buildPath(params, randomFileName);
        IOUtilities.writeString(String.valueOf(source), literalFile);
        final String relLoc = getRelativeLocation(literalFile, params);
        reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Error occure during image writing.", ex);
    }
    return reference;
}
Also used : Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference) IOException(java.io.IOException)

Example 48 with Reference

use of com.google.api.expr.v1alpha1.Reference in project dishevelled-bio by heuermh.

the class ReassemblePaths 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;
        final List<Path> paths = new ArrayList<Path>();
        final ListMultimap<String, Traversal> traversalsByPathName = ArrayListMultimap.create();
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                if (gfa1Record instanceof Path) {
                    Path path = (Path) gfa1Record;
                    paths.add(path);
                } else if (gfa1Record instanceof Traversal) {
                    Traversal traversal = (Traversal) gfa1Record;
                    traversalsByPathName.put(traversal.getPathName(), traversal);
                } else {
                    Gfa1Writer.write(gfa1Record, w);
                }
                return true;
            }
        });
        for (Path path : paths) {
            List<Traversal> traversals = traversalsByPathName.get(path.getName());
            Collections.sort(traversals, new Comparator<Traversal>() {

                @Override
                public int compare(final Traversal t0, final Traversal t1) {
                    return t0.getOrdinal() - t1.getOrdinal();
                }
            });
            List<Reference> segments = new ArrayList<Reference>();
            List<String> overlaps = new ArrayList<String>();
            for (Traversal traversal : traversals) {
                if (segments.isEmpty()) {
                    segments.add(traversal.getSource());
                }
                segments.add(traversal.getTarget());
                if (traversal.hasOverlap()) {
                    overlaps.add(traversal.getOverlap());
                }
            }
            Gfa1Writer.write(new Path(path.getName(), segments, overlaps.isEmpty() ? null : overlaps, path.getAnnotations()), w);
        }
        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) Reference(org.dishevelled.bio.assembly.gfa1.Reference) ArrayList(java.util.ArrayList) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) BufferedReader(java.io.BufferedReader) PrintWriter(java.io.PrintWriter)

Example 49 with Reference

use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.

the class Env method residualAst.

/**
 * ResidualAst takes an Ast and its EvalDetails to produce a new Ast which only contains the
 * attribute references which are unknown.
 *
 * <p>Residual expressions are beneficial in a few scenarios:
 *
 * <ul>
 *   <li>Optimizing constant expression evaluations away.
 *   <li>Indexing and pruning expressions based on known input arguments.
 *   <li>Surfacing additional requirements that are needed in order to complete an evaluation.
 *   <li>Sharing the evaluation of an expression across multiple machines/nodes.
 * </ul>
 *
 * <p>For example, if an expression targets a 'resource' and 'request' attribute and the possible
 * values for the resource are known, a PartialActivation could mark the 'request' as an unknown
 * interpreter.AttributePattern and the resulting ResidualAst would be reduced to only the parts
 * of the expression that reference the 'request'.
 *
 * <p>Note, the expression ids within the residual AST generated through this method have no
 * correlation to the expression ids of the original AST.
 *
 * <p>See the PartialVars helper for how to construct a PartialActivation.
 *
 * <p>TODO: Consider adding an option to generate a Program.Residual to avoid round-tripping to an
 * Ast format and then Program again.
 */
public Ast residualAst(Ast a, EvalDetails details) {
    Expr pruned = pruneAst(a.getExpr(), details.getState());
    String expr = astToString(parsedExprToAst(ParsedExpr.newBuilder().setExpr(pruned).build()));
    AstIssuesTuple parsedIss = parse(expr);
    if (parsedIss.hasIssues()) {
        throw parsedIss.getIssues().err();
    }
    if (!a.isChecked()) {
        return parsedIss.ast;
    }
    AstIssuesTuple checkedIss = check(parsedIss.ast);
    if (checkedIss.hasIssues()) {
        throw checkedIss.getIssues().err();
    }
    return checkedIss.ast;
}
Also used : ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) Expr(com.google.api.expr.v1alpha1.Expr) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) CEL.astToParsedExpr(org.projectnessie.cel.CEL.astToParsedExpr) CEL.astToString(org.projectnessie.cel.CEL.astToString)

Example 50 with Reference

use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.

the class Checker method setReference.

void setReference(Expr.Builder e, Reference r) {
    Reference old = references.get(e.getId());
    if (old != null && !old.equals(r)) {
        throw new IllegalStateException(String.format("Reference already exists for expression: %s(%d) old:%s, new:%s", e, e.getId(), old, r));
    }
    references.put(e.getId(), r);
}
Also used : Reference(com.google.api.expr.v1alpha1.Reference)

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 Geometry (org.locationtech.jts.geom.Geometry)4 Type (com.google.api.expr.v1alpha1.Type)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DataStoreException (org.apache.sis.storage.DataStoreException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)2 Decl (com.google.api.expr.v1alpha1.Decl)2