Search in sources :

Example 1 with Dependencies

use of org.talend.sdk.component.server.front.model.Dependencies in project component-runtime by Talend.

the class ComponentResource method getDependency.

/**
 * Return a binary of the dependency represented by `id`.
 * It can be maven coordinates for dependencies or a component id.
 *
 * @param id the dependency identifier.
 * @return the dependency binary (jar).
 */
@GET
@Path("dependency/{id}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput getDependency(@PathParam("id") final String id) {
    final ComponentFamilyMeta.BaseMeta<?> component = componentDao.findById(id);
    final File file;
    if (component != null) {
        // local dep
        file = componentManagerService.manager().findPlugin(component.getParent().getPlugin()).orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No plugin matching the id: " + id)).build())).getContainerFile().orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No dependency matching the id: " + id)).build()));
    } else {
        // just try to resolve it locally, note we would need to ensure some security here
        // .map(Artifact::toPath).map(localDependencyRelativeResolver
        final Artifact artifact = Artifact.from(id);
        file = componentManagerService.manager().getContainer().resolve(artifact.toPath());
    }
    if (!file.exists()) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No file found for: " + id)).build());
    }
    return output -> {
        // 5k
        final byte[] buffer = new byte[40960];
        try (final InputStream stream = new BufferedInputStream(new FileInputStream(file), buffer.length)) {
            int count;
            while ((count = stream.read(buffer)) >= 0) {
                if (count == 0) {
                    continue;
                }
                output.write(buffer, 0, count);
            }
        }
    };
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Produces(javax.ws.rs.Produces) PropertiesService(org.talend.sdk.component.server.service.PropertiesService) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Path(javax.ws.rs.Path) Icon(org.talend.sdk.component.server.front.model.Icon) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ComponentManagerService(org.talend.sdk.component.server.service.ComponentManagerService) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) QueryParam(javax.ws.rs.QueryParam) Collectors.toMap(java.util.stream.Collectors.toMap) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) ComponentId(org.talend.sdk.component.server.front.model.ComponentId) ComponentFamilyDao(org.talend.sdk.component.server.dao.ComponentFamilyDao) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Collections.emptyList(java.util.Collections.emptyList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StreamingOutput(javax.ws.rs.core.StreamingOutput) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) ErrorDictionary(org.talend.sdk.component.server.front.model.ErrorDictionary) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) DESIGN_MODEL_MISSING(org.talend.sdk.component.server.front.model.ErrorDictionary.DESIGN_MODEL_MISSING) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) LocaleMapper(org.talend.sdk.component.server.service.LocaleMapper) PLUGIN_MISSING(org.talend.sdk.component.server.front.model.ErrorDictionary.PLUGIN_MISSING) RequestKey(org.talend.sdk.component.server.front.base.internal.RequestKey) ActionsService(org.talend.sdk.component.server.service.ActionsService) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Container(org.talend.sdk.component.container.Container) Optional.ofNullable(java.util.Optional.ofNullable) Artifact(org.talend.sdk.component.dependencies.maven.Artifact) COMPONENT_MISSING(org.talend.sdk.component.server.front.model.ErrorDictionary.COMPONENT_MISSING) DesignModel(org.talend.sdk.component.design.extension.DesignModel) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) FileInputStream(java.io.FileInputStream) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) IconResolver(org.talend.sdk.component.server.service.IconResolver) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) ComponentDao(org.talend.sdk.component.server.dao.ComponentDao) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) InputStream(java.io.InputStream) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) WebApplicationException(javax.ws.rs.WebApplicationException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) File(java.io.File) Artifact(org.talend.sdk.component.dependencies.maven.Artifact) FileInputStream(java.io.FileInputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Dependencies

use of org.talend.sdk.component.server.front.model.Dependencies in project component-runtime by Talend.

the class ComponentResourceTest method getDependencies.

@Test
void getDependencies() {
    final String compId = client.getJdbcId();
    final Dependencies dependencies = base.path("component/dependencies").queryParam("identifier", compId).request(APPLICATION_JSON_TYPE).get(Dependencies.class);
    assertEquals(1, dependencies.getDependencies().size());
    final DependencyDefinition definition = dependencies.getDependencies().get(compId);
    assertNotNull(definition);
    assertEquals(1, definition.getDependencies().size());
    assertEquals("org.apache.tomee:ziplock:jar:7.0.4", definition.getDependencies().iterator().next());
}
Also used : Dependencies(org.talend.sdk.component.server.front.model.Dependencies) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

Dependencies (org.talend.sdk.component.server.front.model.Dependencies)2 DependencyDefinition (org.talend.sdk.component.server.front.model.DependencyDefinition)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1