Search in sources :

Example 1 with Dependency

use of io.syndesis.common.model.Dependency in project syndesis by syndesisio.

the class GenerateMapperInspectionsMojo method process.

private void process(final Set<File> generated, final Connector connector, final ConnectorAction action, final Optional<DataShape> maybeShape) throws MojoFailureException, MojoExecutionException {
    if (!maybeShape.isPresent()) {
        return;
    }
    if (!connector.getId().isPresent()) {
        return;
    }
    if (!DataShapeKinds.JAVA.equals(maybeShape.get().getKind())) {
        return;
    }
    final DataShape shape = maybeShape.get();
    getLog().info("Generating for connector: " + connector.getId().get() + ", and type: " + shape.getType());
    final File outputFile = new File(outputDir, resourceDir + "/" + connector.getId().get() + "/" + shape.getType() + ".json");
    if (generated.contains(outputFile)) {
        return;
    }
    if (outputFile.getParentFile().mkdirs()) {
        getLog().debug("Created dir: " + outputFile.getParentFile());
    }
    List<String> artifacts = Stream.of(connector, action).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).flatMap(Collection::stream).filter(Dependency::isMaven).map(Dependency::getId).collect(Collectors.toList());
    final GenerateInspectionsMojo generateInspectionsMojo = new GenerateInspectionsMojo();
    generateInspectionsMojo.setLog(getLog());
    generateInspectionsMojo.setPluginContext(getPluginContext());
    generateInspectionsMojo.setSystem(system);
    generateInspectionsMojo.setRemoteRepos(remoteRepos);
    generateInspectionsMojo.setRepoSession(repoSession);
    generateInspectionsMojo.setArtifacts(artifacts);
    generateInspectionsMojo.setClassName(shape.getType());
    generateInspectionsMojo.setArtifacts(artifacts);
    generateInspectionsMojo.setOutputFile(outputFile);
    generateInspectionsMojo.execute();
    generated.add(outputFile);
}
Also used : WithDependencies(io.syndesis.common.model.WithDependencies) GenerateInspectionsMojo(io.atlasmap.maven.GenerateInspectionsMojo) Dependency(io.syndesis.common.model.Dependency) DataShape(io.syndesis.common.model.DataShape) File(java.io.File)

Example 2 with Dependency

use of io.syndesis.common.model.Dependency in project syndesis by syndesisio.

the class IntegrationSupportHandler method export.

@GET
@Path("/export.zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput export(@NotNull @QueryParam("id") @ApiParam(required = true) List<String> requestedIds) throws IOException {
    List<String> ids = requestedIds;
    if (ids == null || ids.isEmpty()) {
        throw new ClientErrorException("No 'integration' query parameter specified.", Response.Status.BAD_REQUEST);
    }
    LinkedHashSet<String> extensions = new LinkedHashSet<>();
    CloseableJsonDB memJsonDB = MemorySqlJsonDB.create(jsonDB.getIndexes());
    if (ids.contains("all")) {
        ids = new ArrayList<>();
        for (Integration integration : dataManager.fetchAll(Integration.class)) {
            ids.add(integration.getId().get());
        }
    }
    for (String id : ids) {
        Integration integration = integrationHandler.getIntegration(id);
        addToExport(memJsonDB, integration);
        resourceManager.collectDependencies(integration.getSteps(), true).stream().filter(Dependency::isExtension).map(Dependency::getId).forEach(extensions::add);
    }
    LOG.debug("Extensions: {}", extensions);
    return out -> {
        try (ZipOutputStream tos = new ZipOutputStream(out)) {
            ModelExport exportObject = ModelExport.of(Schema.VERSION);
            addEntry(tos, EXPORT_MODEL_INFO_FILE_NAME, Json.writer().writeValueAsBytes(exportObject));
            addEntry(tos, EXPORT_MODEL_FILE_NAME, memJsonDB.getAsByteArray("/"));
            memJsonDB.close();
            for (String extensionId : extensions) {
                addEntry(tos, "extensions/" + Names.sanitize(extensionId) + ".jar", IOUtils.toByteArray(extensionDataManager.getExtensionBinaryFile(extensionId)));
            }
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Connection(io.syndesis.common.model.connection.Connection) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) ZipEntry(java.util.zip.ZipEntry) JsonDbDao(io.syndesis.server.jsondb.dao.JsonDbDao) Context(javax.ws.rs.core.Context) Connector(io.syndesis.common.model.connection.Connector) StreamingOutput(javax.ws.rs.core.StreamingOutput) ListResult(io.syndesis.common.model.ListResult) Extension(io.syndesis.common.model.extension.Extension) NotNull(javax.validation.constraints.NotNull) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) ZipOutputStream(java.util.zip.ZipOutputStream) Migrator(io.syndesis.server.jsondb.dao.Migrator) ZipInputStream(java.util.zip.ZipInputStream) GET(javax.ws.rs.GET) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) Names(io.syndesis.common.util.Names) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StreamUtils.nonClosing(org.springframework.util.StreamUtils.nonClosing) DataManager(io.syndesis.server.dao.manager.DataManager) FileDataManager(io.syndesis.server.dao.file.FileDataManager) Api(io.swagger.annotations.Api) MemorySqlJsonDB(io.syndesis.server.jsondb.impl.MemorySqlJsonDB) LinkedHashSet(java.util.LinkedHashSet) SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) WithId(io.syndesis.common.model.WithId) IOException(java.io.IOException) JsonDB(io.syndesis.server.jsondb.JsonDB) ModelExport(io.syndesis.common.model.ModelExport) Dependency(io.syndesis.common.model.Dependency) Component(org.springframework.stereotype.Component) Schema(io.syndesis.common.model.Schema) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) ChangeEvent(io.syndesis.common.model.ChangeEvent) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Integration(io.syndesis.common.model.integration.Integration) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) Dependency(io.syndesis.common.model.Dependency) ZipOutputStream(java.util.zip.ZipOutputStream) ClientErrorException(javax.ws.rs.ClientErrorException) ModelExport(io.syndesis.common.model.ModelExport) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Dependency

use of io.syndesis.common.model.Dependency in project syndesis by syndesisio.

the class ConnectorIconHandler method get.

@GET
@SuppressWarnings("PMD.CyclomaticComplexity")
public Response get() {
    String connectorIcon = connector.getIcon();
    if (connectorIcon == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (connectorIcon.startsWith("db:")) {
        String connectorIconId = connectorIcon.substring(3);
        Icon icon = getDataManager().fetch(Icon.class, connectorIconId);
        if (icon == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        final StreamingOutput streamingOutput = (out) -> {
            try (BufferedSink sink = Okio.buffer(Okio.sink(out));
                Source source = Okio.source(iconDao.read(connectorIconId))) {
                sink.writeAll(source);
            }
        };
        return Response.ok(streamingOutput, icon.getMediaType()).build();
    } else if (connectorIcon.startsWith("extension:")) {
        String iconFile = connectorIcon.substring(10);
        Optional<InputStream> extensionIcon = connector.getDependencies().stream().filter(Dependency::isExtension).map(Dependency::getId).findFirst().flatMap(extensionId -> extensionDataManager.getExtensionIcon(extensionId, iconFile));
        if (extensionIcon.isPresent()) {
            final StreamingOutput streamingOutput = (out) -> {
                final BufferedSink sink = Okio.buffer(Okio.sink(out));
                sink.writeAll(Okio.source(extensionIcon.get()));
                sink.close();
            };
            return Response.ok(streamingOutput, extensionDataManager.getExtensionIconMediaType(iconFile)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
    // font awesome class name), return 404
    if (connectorIcon.startsWith("data:") || !connectorIcon.contains("/")) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    final OkHttpClient httpClient = new OkHttpClient();
    try {
        final okhttp3.Response externalResponse = httpClient.newCall(new Request.Builder().get().url(connectorIcon).build()).execute();
        final String contentType = externalResponse.header(CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM);
        final String contentLength = externalResponse.header(CONTENT_LENGTH);
        final StreamingOutput streamingOutput = (out) -> {
            final BufferedSink sink = Okio.buffer(Okio.sink(out));
            sink.writeAll(externalResponse.body().source());
            sink.close();
        };
        final Response.ResponseBuilder actualResponse = Response.ok(streamingOutput, contentType);
        if (!StringUtils.isEmpty(contentLength)) {
            actualResponse.header(CONTENT_LENGTH, contentLength);
        }
        return actualResponse.build();
    } catch (final IOException e) {
        throw new SyndesisServerException(e);
    }
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) Okio(okio.Okio) BufferedInputStream(java.io.BufferedInputStream) Produces(javax.ws.rs.Produces) Source(okio.Source) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) Consumes(javax.ws.rs.Consumes) BufferedSink(okio.BufferedSink) URLConnection(java.net.URLConnection) DataManager(io.syndesis.server.dao.manager.DataManager) FileDataManager(io.syndesis.server.dao.file.FileDataManager) Api(io.swagger.annotations.Api) Icon(io.syndesis.common.model.icon.Icon) CONTENT_LENGTH(javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH) Request(okhttp3.Request) POST(javax.ws.rs.POST) Connector(io.syndesis.common.model.connection.Connector) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Dependency(io.syndesis.common.model.Dependency) OkHttpClient(okhttp3.OkHttpClient) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Optional(java.util.Optional) MultipartFormDataInput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput) IconDao(io.syndesis.server.dao.file.IconDao) BaseHandler(io.syndesis.server.endpoint.v1.handler.BaseHandler) InputStream(java.io.InputStream) OkHttpClient(okhttp3.OkHttpClient) Optional(java.util.Optional) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Request(okhttp3.Request) StreamingOutput(javax.ws.rs.core.StreamingOutput) BufferedSink(okio.BufferedSink) Dependency(io.syndesis.common.model.Dependency) IOException(java.io.IOException) Source(okio.Source) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Icon(io.syndesis.common.model.icon.Icon) GET(javax.ws.rs.GET)

Example 4 with Dependency

use of io.syndesis.common.model.Dependency in project syndesis by syndesisio.

the class IntegrationResourceManager method collectDependencies.

/**
 * Collect dependencies.
 */
default Collection<Dependency> collectDependencies(Collection<? extends Step> steps, boolean resolveExtensionTags) {
    final List<Dependency> dependencies = new ArrayList<>();
    for (Step step : steps) {
        step.getAction().filter(WithDependencies.class::isInstance).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        List<Dependency> connectorDependencies = step.getConnection().flatMap(Connection::getConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(connectorDependencies);
        List<Dependency> lookedUpConnectorDependecies = step.getConnection().filter(c -> !c.getConnector().isPresent()).map(Connection::getConnectorId).flatMap(this::loadConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(lookedUpConnectorDependecies);
        // Connector extension
        Stream.concat(connectorDependencies.stream(), lookedUpConnectorDependecies.stream()).filter(Dependency::isExtension).map(Dependency::getId).map(this::loadExtension).filter(Optional::isPresent).map(Optional::get).map(Extension::getDependencies).forEach(dependencies::addAll);
        // Step extension
        step.getExtension().map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        step.getExtension().map(Extension::getExtensionId).map(Dependency::extension).ifPresent(dependencies::add);
    }
    if (resolveExtensionTags) {
        return dependencies.stream().flatMap(dep -> {
            if (dep.isExtensionTag()) {
                List<Extension> extensions = this.loadExtensionsByTag(dep.getId());
                Stream<Dependency> extensionDependency = extensions.stream().map(ext -> Dependency.extension(ext.getExtensionId()));
                Stream<Dependency> transitive = extensions.stream().map(Extension::getDependencies).flatMap(Collection::stream);
                return Stream.concat(extensionDependency, transitive);
            } else {
                return Stream.of(dep);
            }
        }).collect(Collectors.toCollection(ArrayList::new));
    } else {
        return dependencies;
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) Step(io.syndesis.common.model.integration.Step) Collection(java.util.Collection) Connector(io.syndesis.common.model.connection.Connector) Extension(io.syndesis.common.model.extension.Extension) WithDependencies(io.syndesis.common.model.WithDependencies) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Dependency(io.syndesis.common.model.Dependency) List(java.util.List) Stream(java.util.stream.Stream) Connection(io.syndesis.common.model.connection.Connection) Optional(java.util.Optional) Integration(io.syndesis.common.model.integration.Integration) Collections(java.util.Collections) InputStream(java.io.InputStream) WithDependencies(io.syndesis.common.model.WithDependencies) Optional(java.util.Optional) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) Dependency(io.syndesis.common.model.Dependency) Step(io.syndesis.common.model.integration.Step)

Aggregations

Dependency (io.syndesis.common.model.Dependency)4 Connector (io.syndesis.common.model.connection.Connector)3 InputStream (java.io.InputStream)3 Optional (java.util.Optional)3 Api (io.swagger.annotations.Api)2 WithDependencies (io.syndesis.common.model.WithDependencies)2 Connection (io.syndesis.common.model.connection.Connection)2 Extension (io.syndesis.common.model.extension.Extension)2 Integration (io.syndesis.common.model.integration.Integration)2 Step (io.syndesis.common.model.integration.Step)2 FileDataManager (io.syndesis.server.dao.file.FileDataManager)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 MediaType (javax.ws.rs.core.MediaType)2