001/**
002 * Copyright (C) 2006-2026 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("""
035         This API should support nested schema but the Studio is not yet ready.
036
037         The cloud platform also doesn't use it yet.
038
039         Also prefer to use \
040         `org.talend.sdk.component.api.record.Schema` over this partial default implementation.""")
041@Data
042@NoArgsConstructor
043@AllArgsConstructor
044@Deprecated // use SchemaBuilder instead of this implementation
045public class Schema implements org.talend.sdk.component.api.record.Schema {
046
047    private List<org.talend.sdk.component.api.record.Schema.Entry> entries;
048
049    // 1.0 compat
050    public Schema(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
051        this.entries = new ArrayList<>(entries);
052    }
053
054    // 1.0 compat
055    public void setEntries(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
056        this.entries = new ArrayList<>(entries);
057    }
058
059    @Override
060    public List<org.talend.sdk.component.api.record.Schema.Entry> getMetadata() {
061        return Collections.emptyList();
062    }
063
064    @Override
065    public Type getType() {
066        return Type.RECORD;
067    }
068
069    @Override
070    public org.talend.sdk.component.api.record.Schema getElementSchema() {
071        return null;
072    }
073
074    @Override
075    public Map<String, String> getProps() {
076        return null;
077    }
078
079    @Override
080    public String getProp(final String property) {
081        return null;
082    }
083
084    @Override
085    public Stream<org.talend.sdk.component.api.record.Schema.Entry> getAllEntries() {
086        return Optional.ofNullable(this.entries).map(List::stream).orElse(Stream.empty());
087    }
088
089    @Override
090    public Builder toBuilder() {
091        throw new UnsupportedOperationException("#toBuilder()");
092    }
093
094    @Override
095    public EntriesOrder naturalOrder() {
096        throw new UnsupportedOperationException("#naturalOrder()");
097    }
098
099    @Data
100    @AllArgsConstructor
101    @NoArgsConstructor
102    @Deprecated
103    public static class Entry implements org.talend.sdk.component.api.record.Schema.Entry {
104
105        private String name;
106
107        private Schema.Type type;
108
109        // 1.0 compat
110        public Entry(final String name, final org.talend.sdk.component.api.service.schema.Type type) {
111            this.name = name;
112            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
113        }
114
115        // 1.0 compat
116        public void setType(final org.talend.sdk.component.api.service.schema.Type type) {
117            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
118        }
119
120        @Override
121        public String getRawName() {
122            return null;
123        }
124
125        @JsonbTransient
126        @Override
127        public String getOriginalFieldName() {
128            return null;
129        }
130
131        @Override
132        public boolean isNullable() {
133            return true;
134        }
135
136        @Override
137        public boolean isErrorCapable() {
138            return false;
139        }
140
141        @Override
142        public boolean isMetadata() {
143            return false;
144        }
145
146        @Override
147        public <T> T getDefaultValue() {
148            return null;
149        }
150
151        @Override
152        public org.talend.sdk.component.api.record.Schema getElementSchema() {
153            return null;
154        }
155
156        @Override
157        public String getComment() {
158            return null;
159        }
160
161        @Override
162        public Map<String, String> getProps() {
163            return null;
164        }
165
166        @Override
167        public String getProp(final String property) {
168            return null;
169        }
170
171        @Override
172        public Builder toBuilder() {
173            throw new UnsupportedOperationException("#toBuilder()");
174        }
175
176        @Override
177        public boolean isValid() {
178            return true;
179        }
180
181    }
182
183}