Search in sources :

Example 1 with DefinitionType

use of org.talend.components.service.rest.DefinitionType 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)

Aggregations

Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Logger (org.slf4j.Logger)1 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)1 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)1 DatastoreDefinition (org.talend.components.common.datastore.DatastoreDefinition)1 DefinitionType (org.talend.components.service.rest.DefinitionType)1 DefinitionsController (org.talend.components.service.rest.DefinitionsController)1 ConnectorTypology (org.talend.components.service.rest.dto.ConnectorTypology)1 DefinitionDTO (org.talend.components.service.rest.dto.DefinitionDTO)1 ServiceImplementation (org.talend.daikon.annotation.ServiceImplementation)1 Definition (org.talend.daikon.definition.Definition)1 DefinitionRegistryService (org.talend.daikon.definition.service.DefinitionRegistryService)1 HasTags (org.talend.daikon.i18n.tag.HasTags)1 Tag (org.talend.daikon.i18n.tag.Tag)1