Search in sources :

Example 1 with Definition

use of org.talend.daikon.definition.Definition in project components by Talend.

the class ServiceSpiFactoryTest method testGetComponentService.

@Test
public void testGetComponentService() throws Exception {
    ComponentService cs = ServiceSpiFactory.getComponentService();
    assertThat(cs, not(nullValue()));
    DefinitionRegistry defReg = ServiceSpiFactory.getDefinitionRegistry();
    assertThat(cs, not(nullValue()));
    Map<String, ComponentFamilyDefinition> families = defReg.getComponentFamilies();
    assertThat(families, hasEntry(is("LocalIO"), isA((Class) LocalIOComponentFamilyDefinition.class)));
    assertThat(families, hasEntry(is("SimpleFileIo"), isA((Class) SimpleFileIOComponentFamilyDefinition.class)));
    Map<String, Definition> definitions = defReg.getDefinitions();
    assertThat(definitions, hasEntry(is("FixedFlowInput"), isA((Class) FixedFlowInputDefinition.class)));
    assertThat(definitions, hasEntry(is("SimpleFileIoDatastore"), isA((Class) SimpleFileIODatastoreDefinition.class)));
    assertThat(definitions, hasEntry(is("SimpleFileIoDataset"), isA((Class) SimpleFileIODatasetDefinition.class)));
    assertThat(definitions, hasEntry(is("SimpleFileIoInput"), isA((Class) SimpleFileIOInputDefinition.class)));
    assertThat(definitions, hasEntry(is("SimpleFileIoOutput"), isA((Class) SimpleFileIOOutputDefinition.class)));
}
Also used : FixedFlowInputDefinition(org.talend.components.localio.fixedflowinput.FixedFlowInputDefinition) SimpleFileIOInputDefinition(org.talend.components.simplefileio.input.SimpleFileIOInputDefinition) ComponentFamilyDefinition(org.talend.components.api.ComponentFamilyDefinition) SimpleFileIODatastoreDefinition(org.talend.components.simplefileio.SimpleFileIODatastoreDefinition) Definition(org.talend.daikon.definition.Definition) SimpleFileIOComponentFamilyDefinition(org.talend.components.simplefileio.SimpleFileIOComponentFamilyDefinition) SimpleFileIODatasetDefinition(org.talend.components.simplefileio.SimpleFileIODatasetDefinition) SimpleFileIOInputDefinition(org.talend.components.simplefileio.input.SimpleFileIOInputDefinition) SimpleFileIOOutputDefinition(org.talend.components.simplefileio.output.SimpleFileIOOutputDefinition) LocalIOComponentFamilyDefinition(org.talend.components.localio.LocalIOComponentFamilyDefinition) FixedFlowInputDefinition(org.talend.components.localio.fixedflowinput.FixedFlowInputDefinition) SimpleFileIOOutputDefinition(org.talend.components.simplefileio.output.SimpleFileIOOutputDefinition) SimpleFileIOComponentFamilyDefinition(org.talend.components.simplefileio.SimpleFileIOComponentFamilyDefinition) ComponentFamilyDefinition(org.talend.components.api.ComponentFamilyDefinition) SimpleFileIOComponentFamilyDefinition(org.talend.components.simplefileio.SimpleFileIOComponentFamilyDefinition) LocalIOComponentFamilyDefinition(org.talend.components.localio.LocalIOComponentFamilyDefinition) SimpleFileIODatasetDefinition(org.talend.components.simplefileio.SimpleFileIODatasetDefinition) LocalIOComponentFamilyDefinition(org.talend.components.localio.LocalIOComponentFamilyDefinition) SimpleFileIODatastoreDefinition(org.talend.components.simplefileio.SimpleFileIODatastoreDefinition) ComponentService(org.talend.components.api.service.ComponentService) DefinitionRegistry(org.talend.components.api.service.common.DefinitionRegistry) Test(org.junit.Test)

Example 2 with Definition

use of org.talend.daikon.definition.Definition in project components by Talend.

the class DefinitionsControllerImpl method listDefinitions.

/**
 * Return all known definitions that match the given type.
 *
 * @param type the wanted definition type.
 * @return all known definitions that match the given type.
 * @returnWrapped java.lang.Iterable<org.talend.components.service.rest.dto.DefinitionDTO>
 */
@Override
public List<DefinitionDTO> listDefinitions(DefinitionType type, String tag) {
    logger.debug("listing definitions for {} ", type);
    // 
    Iterable<? extends Definition> definitionsByType = definitionServiceDelegate.getDefinitionsMapByType(type.getTargetClass()).values();
    Stream<? extends Definition> stream = stream(definitionsByType.spliterator(), false);
    if (tag != null) {
        stream = // 
        stream.filter(c -> HasTags.class.isAssignableFrom(c.getClass())).filter(c -> {
            for (Tag defTag : ((HasTags) c).getTags()) {
                if (TagUtils.hasTag(defTag, tag)) {
                    return true;
                }
            }
            return false;
        });
    }
    return stream.map(c -> {
        if (type == DefinitionType.COMPONENT) {
            return new DefinitionDTO((ComponentDefinition) c);
        } else {
            return new DefinitionDTO((DatastoreDefinition) c);
        }
    }).collect(Collectors.toList());
}
Also used : DefinitionRegistryService(org.talend.daikon.definition.service.DefinitionRegistryService) DefinitionsController(org.talend.components.service.rest.DefinitionsController) Logger(org.slf4j.Logger) HasTags(org.talend.daikon.i18n.tag.HasTags) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Collectors(java.util.stream.Collectors) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) List(java.util.List) Stream(java.util.stream.Stream) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) StreamSupport.stream(java.util.stream.StreamSupport.stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ServiceImplementation(org.talend.daikon.annotation.ServiceImplementation) Tag(org.talend.daikon.i18n.tag.Tag) ConnectorTypology(org.talend.components.service.rest.dto.ConnectorTypology) TagUtils(org.talend.daikon.i18n.tag.TagUtils) DefinitionType(org.talend.components.service.rest.DefinitionType) HasTags(org.talend.daikon.i18n.tag.HasTags) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Tag(org.talend.daikon.i18n.tag.Tag) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 3 with Definition

use of org.talend.daikon.definition.Definition in project components by Talend.

the class MarkLogicFamilyDefinitionTest method testAllComponentsDefinitionsCreated.

@Test
public void testAllComponentsDefinitionsCreated() {
    List<Class> expectedDefinitions = new ArrayList<>();
    expectedDefinitions.add(MarkLogicInputDefinition.class);
    expectedDefinitions.add(MarkLogicOutputDefinition.class);
    expectedDefinitions.add(MarkLogicConnectionDefinition.class);
    expectedDefinitions.add(MarkLogicCloseDefinition.class);
    expectedDefinitions.add(MarkLogicBulkLoadDefinition.class);
    expectedDefinitions.add(MarkLogicWizardDefinition.class);
    expectedDefinitions.add(MarkLogicEditWizardDefinition.class);
    expectedDefinitions.add(MarkLogicDatasetDefinition.class);
    expectedDefinitions.add(MarkLogicDatastoreDefinition.class);
    List<Class> actualDefinitionsNames = new ArrayList<>();
    for (Definition d : familyDefinition.getDefinitions()) {
        actualDefinitionsNames.add(d.getClass());
    }
    assertEquals(expectedDefinitions, actualDefinitionsNames);
}
Also used : ArrayList(java.util.ArrayList) MarkLogicEditWizardDefinition(org.talend.components.marklogic.wizard.MarkLogicEditWizardDefinition) MarkLogicInputDefinition(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputDefinition) MarkLogicDatastoreDefinition(org.talend.components.marklogic.data.MarkLogicDatastoreDefinition) Definition(org.talend.daikon.definition.Definition) MarkLogicConnectionDefinition(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionDefinition) MarkLogicOutputDefinition(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputDefinition) MarkLogicWizardDefinition(org.talend.components.marklogic.wizard.MarkLogicWizardDefinition) MarkLogicCloseDefinition(org.talend.components.marklogic.tmarklogicclose.MarkLogicCloseDefinition) MarkLogicDatasetDefinition(org.talend.components.marklogic.data.MarkLogicDatasetDefinition) MarkLogicBulkLoadDefinition(org.talend.components.marklogic.tmarklogicbulkload.MarkLogicBulkLoadDefinition) Test(org.junit.Test)

Example 4 with Definition

use of org.talend.daikon.definition.Definition in project components by Talend.

the class DefinitionRegistry method registerDefinition.

@Override
public void registerDefinition(Iterable<? extends Definition> defs) {
    for (Definition def : defs) {
        String name = def.getName();
        if (name == null) {
            throw TalendRuntimeException.createUnexpectedException("The definition [" + def.getClass().getName() + "] name cannot be null.");
        }
        // else we are fine keep going
        Definition previousValue = definitions.put(name, def);
        if (previousValue != null) {
            // we cannot have 2 definiions with the same name
            throw TalendRuntimeException.createUnexpectedException("2 definitions have the same name [" + previousValue.getName() + "] but their name must be unique.");
        }
        LOGGER.info("Talend Definition registered :" + name);
    }
}
Also used : ComponentFamilyDefinition(org.talend.components.api.ComponentFamilyDefinition) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition)

Example 5 with Definition

use of org.talend.daikon.definition.Definition in project components by Talend.

the class DefintitionRegistryTest method testAddComponentFamilyDefinition.

@SuppressWarnings("rawtypes")
@Test
public void testAddComponentFamilyDefinition() {
    DefinitionRegistry registry = new DefinitionRegistry();
    ComponentFamilyDefinition def = new TestComponentFamilyDefinition();
    registry.registerComponentFamilyDefinition(def);
    assertThat(registry.getComponentFamilies().keySet(), hasSize(1));
    assertThat(registry.getComponentFamilies(), hasEntry(def.getName(), def));
    // All of the nested definitions were added.
    Iterator<? extends Definition> iterator = def.getDefinitions().iterator();
    assertThat(registry.getDefinitionsMapByType(ComponentDefinition.class).values(), contains((Definition) iterator.next()));
    assertThat(registry.getDefinitionsMapByType(ComponentWizardDefinition.class).values(), contains((ComponentWizardDefinition) iterator.next()));
}
Also used : ComponentFamilyDefinition(org.talend.components.api.ComponentFamilyDefinition) TestComponentFamilyDefinition(org.talend.components.api.service.common.testcomponent.TestComponentFamilyDefinition) ComponentFamilyDefinition(org.talend.components.api.ComponentFamilyDefinition) TestComponentDefinition(org.talend.components.api.service.common.testcomponent.TestComponentDefinition) TestComponentFamilyDefinition(org.talend.components.api.service.common.testcomponent.TestComponentFamilyDefinition) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) TestInjectComponentDefinition(org.talend.components.api.service.common.testcomponent.inject.TestInjectComponentDefinition) SimpleComponentDefinition(org.talend.components.api.test.SimpleComponentDefinition) TestComponentWizardDefinition(org.talend.components.api.service.common.testcomponent.TestComponentWizardDefinition) TestNestedInjectComponentDefinition(org.talend.components.api.service.common.testcomponent.inject.TestNestedInjectComponentDefinition) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) TestComponentWizardDefinition(org.talend.components.api.service.common.testcomponent.TestComponentWizardDefinition) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) TestComponentFamilyDefinition(org.talend.components.api.service.common.testcomponent.TestComponentFamilyDefinition) Test(org.junit.Test)

Aggregations

Definition (org.talend.daikon.definition.Definition)10 Test (org.junit.Test)7 ComponentFamilyDefinition (org.talend.components.api.ComponentFamilyDefinition)5 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)5 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)4 TestComponentDefinition (org.talend.components.api.service.common.testcomponent.TestComponentDefinition)3 TestComponentFamilyDefinition (org.talend.components.api.service.common.testcomponent.TestComponentFamilyDefinition)3 TestComponentWizardDefinition (org.talend.components.api.service.common.testcomponent.TestComponentWizardDefinition)3 TestInjectComponentDefinition (org.talend.components.api.service.common.testcomponent.inject.TestInjectComponentDefinition)3 TestNestedInjectComponentDefinition (org.talend.components.api.service.common.testcomponent.inject.TestNestedInjectComponentDefinition)3 SimpleComponentDefinition (org.talend.components.api.test.SimpleComponentDefinition)3 DatastoreDefinition (org.talend.components.common.datastore.DatastoreDefinition)2 SalesforceInputDefinition (org.talend.components.salesforce.dataprep.SalesforceInputDefinition)2 SalesforceDatasetDefinition (org.talend.components.salesforce.dataset.SalesforceDatasetDefinition)2 SalesforceDatastoreDefinition (org.talend.components.salesforce.datastore.SalesforceDatastoreDefinition)2 TSalesforceBulkExecDefinition (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition)2 TSalesforceConnectionDefinition (org.talend.components.salesforce.tsalesforceconnection.TSalesforceConnectionDefinition)2 TSalesforceGetDeletedDefinition (org.talend.components.salesforce.tsalesforcegetdeleted.TSalesforceGetDeletedDefinition)2 TSalesforceGetServerTimestampDefinition (org.talend.components.salesforce.tsalesforcegetservertimestamp.TSalesforceGetServerTimestampDefinition)2 TSalesforceGetUpdatedDefinition (org.talend.components.salesforce.tsalesforcegetupdated.TSalesforceGetUpdatedDefinition)2