Search in sources :

Example 1 with IPubSubDatasetRuntime

use of org.talend.components.pubsub.runtime.IPubSubDatasetRuntime in project components by Talend.

the class PubSubDatasetProperties method beforeSubscription.

public ValidationResult beforeSubscription() {
    PubSubDatasetDefinition definition = new PubSubDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IPubSubDatasetRuntime runtime = (IPubSubDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> topics = new ArrayList<>();
        for (String topicName : runtime.listSubscriptions()) {
            topics.add(new SimpleNamedThing(topicName, topicName));
        }
        subscription.setPossibleValues(topics);
        return ValidationResult.OK;
    } catch (Exception e) {
        return new ValidationResult(new ComponentException(e));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) IPubSubDatasetRuntime(org.talend.components.pubsub.runtime.IPubSubDatasetRuntime) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException)

Example 2 with IPubSubDatasetRuntime

use of org.talend.components.pubsub.runtime.IPubSubDatasetRuntime in project components by Talend.

the class PubSubDatasetProperties method beforeTopic.

public ValidationResult beforeTopic() {
    PubSubDatasetDefinition definition = new PubSubDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IPubSubDatasetRuntime runtime = (IPubSubDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> topics = new ArrayList<>();
        for (String topicName : runtime.listTopics()) {
            topics.add(new SimpleNamedThing(topicName, topicName));
        }
        topic.setPossibleValues(topics);
        return ValidationResult.OK;
    } catch (Exception e) {
        return new ValidationResult(new ComponentException(e));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) IPubSubDatasetRuntime(org.talend.components.pubsub.runtime.IPubSubDatasetRuntime) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException)

Aggregations

ArrayList (java.util.ArrayList)2 ComponentException (org.talend.components.api.exception.ComponentException)2 IPubSubDatasetRuntime (org.talend.components.pubsub.runtime.IPubSubDatasetRuntime)2 NamedThing (org.talend.daikon.NamedThing)2 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)2 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)2