001/**
002 * Copyright (C) 2006-2023 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.sample.other;
017
018import static java.util.stream.Collectors.toList;
019
020import java.io.Serializable;
021import java.util.stream.IntStream;
022
023import org.talend.sdk.component.api.configuration.Option;
024import org.talend.sdk.component.api.configuration.action.Proposable;
025import org.talend.sdk.component.api.configuration.type.DataSet;
026import org.talend.sdk.component.api.configuration.type.DataStore;
027import org.talend.sdk.component.api.configuration.ui.OptionsOrder;
028import org.talend.sdk.component.api.configuration.ui.widget.Credential;
029import org.talend.sdk.component.api.input.Emitter;
030import org.talend.sdk.component.api.input.Producer;
031import org.talend.sdk.component.api.service.Service;
032import org.talend.sdk.component.api.service.completion.DynamicValues;
033import org.talend.sdk.component.api.service.completion.Values;
034
035import lombok.Data;
036
037@Emitter(family = "complex", name = "demo")
038public class ComplexComponent implements Serializable {
039
040    private final ComplexDataSet dataset;
041
042    public ComplexComponent(@Option("dataset") final ComplexDataSet dataset) {
043        this.dataset = dataset;
044    }
045
046    @Producer
047    public String value() {
048        return "";
049    }
050
051    @Data
052    @DataStore("complicated")
053    public static class Credentials implements Serializable {
054
055        @Option
056        private String username;
057
058        @Option
059        @Credential
060        private String password;
061    }
062
063    @Data
064    @DataSet("complicated")
065    @OptionsOrder({ "path", "credentials" })
066    public static class ComplexDataSet implements Serializable {
067
068        @Option
069        private Credentials credentials;
070
071        @Option
072        @Proposable("path")
073        private String path;
074    }
075
076    @Service
077    public static class PathService {
078
079        @DynamicValues(family = "complex", value = "path")
080        public Values find(@Option("value") final String value) {
081            return new Values(IntStream
082                    .range(1, 11)
083                    .mapToObj(i -> new Values.Item("file_" + i, "/opt/sample/file_" + i + ".txt"))
084                    .collect(toList()));
085        }
086    }
087}