Search in sources :

Example 36 with Path

use of com.reprezen.kaizen.oasparser.model3.Path 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 37 with Path

use of com.reprezen.kaizen.oasparser.model3.Path in project dishevelled-bio by heuermh.

the class TruncatePaths 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) {
                if (gfa1Record instanceof Path) {
                    Path path = (Path) gfa1Record;
                    Gfa1Writer.write(new Path(path.getName(), EMPTY_SEGMENTS, null, path.getAnnotations()), w);
                } else {
                    Gfa1Writer.write(gfa1Record, w);
                }
                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) BufferedReader(java.io.BufferedReader) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 38 with Path

use of com.reprezen.kaizen.oasparser.model3.Path in project ets-ogcapi-features10 by opengeospatial.

the class ApiDefinition method apiDefinitionValidation.

/**
 * <pre>
 * Abstract Test 6: /ats/core/api-definition-success
 * Test Purpose: Validate that the API Definition complies with the required structure and contents.
 * Requirement: /req/core/api-definition-success
 *
 * Test Method: Validate the API Definition document against an appropriate schema document.
 * </pre>
 *
 * @param testContext
 *            never <code>null</code>
 * @throws MalformedURLException
 *             if the apiUrl is malformed
 */
@Test(description = "Implements A.2.3. API Definition Path {root}/api (link), Abstract Test 6 (Requirement /req/core/api-definition-success)", groups = "apidefinition", dependsOnMethods = "openapiDocumentRetrieval")
public void apiDefinitionValidation(ITestContext testContext) throws MalformedURLException {
    OpenApi3Parser parser = new OpenApi3Parser();
    OpenApi3 apiModel = parser.parse(response, new URL(apiUrl), true);
    assertTrue(apiModel.isValid(), createValidationMsg(apiModel));
    testContext.getSuite().setAttribute(API_MODEL.getName(), apiModel);
}
Also used : OpenApi3Parser(com.reprezen.kaizen.oasparser.OpenApi3Parser) OpenApi3(com.reprezen.kaizen.oasparser.model3.OpenApi3) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 39 with Path

use of com.reprezen.kaizen.oasparser.model3.Path in project ets-ogcapi-features10 by opengeospatial.

the class OpenApiUtils method identifyServerUrls.

/**
 * A.4.3.2. Identify Server URIs:
 *
 * a) Purpose: To identify all server URIs applicable to an OpenAPI Operation Object
 *
 * b) Pre-conditions:
 *
 * Server Objects from the root level of the OpenAPI document have been obtained
 *
 * A Path Item Object has been retrieved
 *
 * An Operation Object has been retrieved
 *
 * The Operation Object is associated with the Path Item Object
 *
 * A list of URLs for the servers to be included in the compliance test has been provided
 *
 * c) Method:
 *
 * 1) Identify the Server Objects which are in-scope for this operationObject
 *
 * IF Server Objects are defined at the Operation level, then those and only those Server Objects apply to that
 * Operation.
 *
 * IF Server Objects are defined at the Path Item level, then those and only those Server Objects apply to that Path
 * Item.
 *
 * IF Server Objects are not defined at the Operation level, then the Server Objects defined for the parent Path
 * Item apply to that Operation.
 *
 * IF Server Objects are not defined at the Path Item level, then the Server Objects defined for the root level
 * apply to that Path.
 *
 * IF no Server Objects are defined at the root level, then the default server object is assumed as described in the
 * OpenAPI specification.
 *
 * 2) Process each Server Object using A.4.3.3.
 *
 * 3) Delete any Server URI which does not reference a server on the list of servers to test.
 *
 * d) References: None
 *
 * @param apiModel
 *            never <code>null</code>
 * @param iut
 *            never <code>null</code>
 * @param pathItemObjects
 *            never <code>null</code>
 */
private static List<PathItemAndServer> identifyServerUrls(OpenApi3 apiModel, URI iut, List<Path> pathItemObjects) {
    List<PathItemAndServer> pathItemAndServers = new ArrayList<>();
    for (Path pathItemObject : pathItemObjects) {
        Map<String, Operation> operationObjects = pathItemObject.getOperations();
        for (Operation operationObject : operationObjects.values()) {
            List<String> serverUrls = identifyServerObjects(apiModel, pathItemObject, operationObject);
            for (String serverUrl : serverUrls) {
                if (DEFAULT_SERVER_URL.equalsIgnoreCase(serverUrl)) {
                    serverUrl = iut.toString();
                } else if (serverUrl.startsWith("/")) {
                    URI resolvedUri = iut.resolve(serverUrl);
                    serverUrl = resolvedUri.toString();
                }
                PathItemAndServer pathItemAndServer = new PathItemAndServer(pathItemObject, operationObject, serverUrl);
                pathItemAndServers.add(pathItemAndServer);
            }
        }
    }
    return pathItemAndServers;
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) ArrayList(java.util.ArrayList) Operation(com.reprezen.kaizen.oasparser.model3.Operation) URI(java.net.URI)

Example 40 with Path

use of com.reprezen.kaizen.oasparser.model3.Path in project ets-ogcapi-features10 by opengeospatial.

the class OpenApiUtils method isParameterSupportedForCollection.

public static boolean isParameterSupportedForCollection(OpenApi3 apiModel, URI iut, String collectionName, String queryParam) {
    String requestedPath = createCollectionPath(apiModel, iut, collectionName);
    List<Path> paths = identifyTestPoints(apiModel, requestedPath, new PathMatcher());
    for (Path path : paths) {
        Collection<Parameter> parameters = path.getGet().getParameters();
        for (Parameter parameter : parameters) {
            if (queryParam.equalsIgnoreCase(parameter.getName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter)

Aggregations

Path (com.reprezen.kaizen.oasparser.model3.Path)24 Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)21 Operation (com.reprezen.kaizen.oasparser.model3.Operation)16 ArrayList (java.util.ArrayList)8 Path (org.dishevelled.bio.assembly.gfa1.Path)7 Schema (com.reprezen.kaizen.oasparser.model3.Schema)6 BufferedReader (java.io.BufferedReader)5 OpenApi3 (com.reprezen.kaizen.oasparser.model3.OpenApi3)4 PrintWriter (java.io.PrintWriter)4 HashMap (java.util.HashMap)4 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)4 OpenApi3Parser (com.reprezen.kaizen.oasparser.OpenApi3Parser)3 LinkedList (java.util.LinkedList)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 Test (org.testng.annotations.Test)3 HashBasedTable (com.google.common.collect.HashBasedTable)2 Table (com.google.common.collect.Table)2 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)2 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)2 TlvException (es.gob.jmulticard.asn1.TlvException)2