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.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    @Override
086    public Builder toBuilder() {
087        throw new UnsupportedOperationException("#toBuilder()");
088    }
089
090    @Override
091    public EntriesOrder naturalOrder() {
092        throw new UnsupportedOperationException("#naturalOrder()");
093    }
094
095    @Data
096    @AllArgsConstructor
097    @NoArgsConstructor
098    @Deprecated
099    public static class Entry implements org.talend.sdk.component.api.record.Schema.Entry {
100
101        private String name;
102
103        private Schema.Type type;
104
105        // 1.0 compat
106        public Entry(final String name, final org.talend.sdk.component.api.service.schema.Type type) {
107            this.name = name;
108            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
109        }
110
111        // 1.0 compat
112        public void setType(final org.talend.sdk.component.api.service.schema.Type type) {
113            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
114        }
115
116        @Override
117        public String getRawName() {
118            return null;
119        }
120
121        @JsonbTransient
122        @Override
123        public String getOriginalFieldName() {
124            return null;
125        }
126
127        @Override
128        public boolean isNullable() {
129            return true;
130        }
131
132        @Override
133        public boolean isMetadata() {
134            return false;
135        }
136
137        @Override
138        public <T> T getDefaultValue() {
139            return null;
140        }
141
142        @Override
143        public org.talend.sdk.component.api.record.Schema getElementSchema() {
144            return null;
145        }
146
147        @Override
148        public String getComment() {
149            return null;
150        }
151
152        @Override
153        public Map<String, String> getProps() {
154            return null;
155        }
156
157        @Override
158        public String getProp(final String property) {
159            return null;
160        }
161
162        @Override
163        public Builder toBuilder() {
164            throw new UnsupportedOperationException("#toBuilder()");
165        }
166    }
167
168}