001/**
002 * Copyright (C) 2006-2021 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.api.service.schema;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.Collections;
021import java.util.List;
022import java.util.Map;
023import java.util.Optional;
024import java.util.stream.Stream;
025
026import javax.json.bind.annotation.JsonbTransient;
027
028import org.talend.sdk.component.api.meta.Partial;
029
030import lombok.AllArgsConstructor;
031import lombok.Data;
032import lombok.NoArgsConstructor;
033
034@Partial("This API should support nested schema but the Studio is not yet ready.\n\n"
035        + "The cloud platform also doesn't use it yet.\n\nAlso prefer to use "
036        + "`org.talend.sdk.component.api.record.Schema` over this partial default implementation.")
037@Data
038@NoArgsConstructor
039@AllArgsConstructor
040@Deprecated // use SchemaBuilder instead of this implementation
041public class Schema implements org.talend.sdk.component.api.record.Schema {
042
043    private List<org.talend.sdk.component.api.record.Schema.Entry> entries;
044
045    // 1.0 compat
046    public Schema(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
047        this.entries = new ArrayList<>(entries);
048    }
049
050    // 1.0 compat
051    public void setEntries(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
052        this.entries = new ArrayList<>(entries);
053    }
054
055    @Override
056    public List<org.talend.sdk.component.api.record.Schema.Entry> getMetadata() {
057        return Collections.emptyList();
058    }
059
060    @Override
061    public Type getType() {
062        return Type.RECORD;
063    }
064
065    @Override
066    public org.talend.sdk.component.api.record.Schema getElementSchema() {
067        return null;
068    }
069
070    @Override
071    public Map<String, String> getProps() {
072        return null;
073    }
074
075    @Override
076    public String getProp(final String property) {
077        return null;
078    }
079
080    @Override
081    public Stream<org.talend.sdk.component.api.record.Schema.Entry> getAllEntries() {
082        return Optional.ofNullable(this.entries).map(List::stream).orElse(Stream.empty());
083    }
084
085    @Data
086    @AllArgsConstructor
087    @NoArgsConstructor
088    @Deprecated
089    public static class Entry implements org.talend.sdk.component.api.record.Schema.Entry {
090
091        private String name;
092
093        private Schema.Type type;
094
095        // 1.0 compat
096        public Entry(final String name, final org.talend.sdk.component.api.service.schema.Type type) {
097            this.name = name;
098            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
099        }
100
101        // 1.0 compat
102        public void setType(final org.talend.sdk.component.api.service.schema.Type type) {
103            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
104        }
105
106        @Override
107        public String getRawName() {
108            return null;
109        }
110
111        @JsonbTransient
112        @Override
113        public String getOriginalFieldName() {
114            return null;
115        }
116
117        @Override
118        public boolean isNullable() {
119            return true;
120        }
121
122        @Override
123        public boolean isMetadata() {
124            return false;
125        }
126
127        @Override
128        public <T> T getDefaultValue() {
129            return null;
130        }
131
132        @Override
133        public org.talend.sdk.component.api.record.Schema getElementSchema() {
134            return null;
135        }
136
137        @Override
138        public String getComment() {
139            return null;
140        }
141
142        @Override
143        public Map<String, String> getProps() {
144            return null;
145        }
146
147        @Override
148        public String getProp(final String property) {
149            return null;
150        }
151    }
152}