Search in sources :

Example 1 with ComponentDetail

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

the class ComponentResourceTest method getDetailsMeta.

@Test
void getDetailsMeta() {
    final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.getJdbcId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
    assertEquals(1, details.getDetails().size());
    final ComponentDetail detail = details.getDetails().iterator().next();
    assertEquals("true", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.password")).findFirst().orElseThrow(() -> new IllegalArgumentException("No credential found")).getMetadata().get("ui::credential"));
    assertEquals("0", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.timeout")).findFirst().orElseThrow(() -> new IllegalArgumentException("No timeout found")).getDefaultValue());
    assertNull(detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.url")).findFirst().orElseThrow(() -> new IllegalArgumentException("No url found")).getDefaultValue());
}
Also used : MonoMeecrowaveConfig(org.apache.meecrowave.junit5.MonoMeecrowaveConfig) JarFile(java.util.jar.JarFile) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) WebsocketClient(org.talend.sdk.component.server.test.websocket.WebsocketClient) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) APPLICATION_OCTET_STREAM_TYPE(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE) ComponentClient(org.talend.sdk.component.server.test.ComponentClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Entity.entity(javax.ws.rs.client.Entity.entity) DeploymentException(javax.websocket.DeploymentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) File(java.io.File) Consumer(java.util.function.Consumer) IO(org.apache.ziplock.IO) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentDetail

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

the class ComponentResource method getDetail.

/**
 * Returns the set of metadata about a few components identified by their 'id'.
 *
 * @param language the language for display names/placeholders/....
 * @param ids the component identifiers to request.
 * @return the list of details for the requested components.
 */
// TODO: max ids.length
@GET
// bulk mode to avoid to fetch components one by one when reloading a pipeline/job
@Path("details")
public ComponentDetailList getDetail(@QueryParam("language") @DefaultValue("en") final String language, @QueryParam("identifiers") final String[] ids) {
    if (ids == null || ids.length == 0) {
        return new ComponentDetailList(emptyList());
    }
    final Map<String, ErrorPayload> errors = new HashMap<>();
    final List<ComponentDetail> details = Stream.of(ids).map(id -> ofNullable(componentDao.findById(id)).orElseGet(() -> {
        errors.put(id, new ErrorPayload(COMPONENT_MISSING, "No component '" + id + "'"));
        return null;
    })).filter(Objects::nonNull).map(meta -> {
        final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin());
        if (!plugin.isPresent()) {
            errors.put(meta.getId(), new ErrorPayload(PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "'"));
            return null;
        }
        final Container container = plugin.get();
        final Optional<DesignModel> model = ofNullable(meta.get(DesignModel.class));
        if (!model.isPresent()) {
            errors.put(meta.getId(), new ErrorPayload(DESIGN_MODEL_MISSING, "No design model '" + meta.getId() + "'"));
            return null;
        }
        final Locale locale = localeMapper.mapLocale(language);
        final ComponentDetail componentDetail = new ComponentDetail();
        componentDetail.setLinks(emptyList());
        componentDetail.setId(createMetaId(container, meta));
        componentDetail.setVersion(meta.getVersion());
        componentDetail.setIcon(meta.getIcon());
        componentDetail.setInputFlows(model.get().getInputFlows());
        componentDetail.setOutputFlows(model.get().getOutputFlows());
        componentDetail.setType(ComponentFamilyMeta.ProcessorMeta.class.isInstance(meta) ? "processor" : "input");
        componentDetail.setDisplayName(meta.findBundle(container.getLoader(), locale).displayName().orElse(meta.getName()));
        componentDetail.setProperties(propertiesService.buildProperties(meta.getParameterMetas(), container.getLoader(), locale, null).collect(toList()));
        componentDetail.setActions(actionsService.findActions(meta.getParent().getName(), container, locale, meta));
        return componentDetail;
    }).filter(Objects::nonNull).collect(toList());
    if (!errors.isEmpty()) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(errors).build());
    }
    return new ComponentDetailList(details);
}
Also used : Locale(java.util.Locale) WebApplicationException(javax.ws.rs.WebApplicationException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DesignModel(org.talend.sdk.component.design.extension.DesignModel) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) Container(org.talend.sdk.component.container.Container) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with ComponentDetail

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

the class ComponentResourceTest method getDetails.

@Test
void getDetails() {
    final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.fetchIndex().getComponents().stream().filter(c -> c.getId().getFamily().equals("chain") && c.getId().getName().equals("list")).findFirst().orElseThrow(() -> new IllegalArgumentException("no chain#list component")).getId().getId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
    assertEquals(1, details.getDetails().size());
    final ComponentDetail detail = details.getDetails().iterator().next();
    assertEquals("the-test-component", detail.getId().getPlugin());
    assertEquals("chain", detail.getId().getFamily());
    assertEquals("list", detail.getId().getName());
    assertEquals("The List Component", detail.getDisplayName());
    final Collection<ActionReference> remoteActions = detail.getActions();
    assertEquals(1, remoteActions.size());
    final ActionReference action = remoteActions.iterator().next();
    assertEquals("default", action.getName());
    assertEquals("healthcheck", action.getType());
    assertEquals(6, action.getProperties().size());
    assertValidation("remote.urls", detail, validation -> validation.getMinItems() == 1);
    assertValidation("remote.urls", detail, validation -> validation.getUniqueItems() != null && validation.getUniqueItems());
    assertValidation("remote.user.user", detail, validation -> validation.getMinLength() != null && validation.getMinLength() == 2);
    assertValidation("remote.user.password", detail, validation -> validation.getMaxLength() != null && validation.getMaxLength() == 8);
    assertValidation("remote.user.password", detail, validation -> validation.getRequired() != null && validation.getRequired());
    // for now
    assertEquals(0, detail.getLinks().size());
/*
         * final Link link = detail.getLinks().iterator().next(); assertEquals("Detail", link.getName());
         * assertEquals("/component/...", link.getPath());
         */
}
Also used : MonoMeecrowaveConfig(org.apache.meecrowave.junit5.MonoMeecrowaveConfig) JarFile(java.util.jar.JarFile) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) WebsocketClient(org.talend.sdk.component.server.test.websocket.WebsocketClient) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) APPLICATION_OCTET_STREAM_TYPE(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE) ComponentClient(org.talend.sdk.component.server.test.ComponentClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Entity.entity(javax.ws.rs.client.Entity.entity) DeploymentException(javax.websocket.DeploymentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) File(java.io.File) Consumer(java.util.function.Consumer) IO(org.apache.ziplock.IO) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)3 ComponentDetail (org.talend.sdk.component.server.front.model.ComponentDetail)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 ArrayList (java.util.ArrayList)2 Base64 (java.util.Base64)2 Collection (java.util.Collection)2 Collections.singletonList (java.util.Collections.singletonList)2 Comparator (java.util.Comparator)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 JarFile (java.util.jar.JarFile)2