-
Notifications
You must be signed in to change notification settings - Fork 51
fix(QTDI-2215): Add schema/Entry pojo. #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: yyin/QTDI-2215-JsonSchema
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * Copyright (C) 2006-2025 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front.model; | ||
|
|
||
| import java.beans.ConstructorProperties; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public final class Entry { | ||
|
|
||
| private final String name; | ||
|
|
||
| private final String rawName; | ||
|
|
||
| private final Schema.Type type; | ||
|
|
||
| private final boolean nullable; | ||
|
|
||
| private final boolean metadata; | ||
|
|
||
| private final boolean errorCapable; | ||
|
|
||
| private final boolean valid; | ||
|
|
||
| private final Schema elementSchema; | ||
|
|
||
| private final String comment; | ||
|
|
||
| private final Map<String, String> props = new LinkedHashMap<>(0); | ||
|
|
||
| private final Object internalDefaultValue; | ||
|
|
||
| @ConstructorProperties({"name", "rawName", "type", "nullable", "metadata", "errorCapable", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that needed ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javax. json. bind. JsonbException: Entry has no suitable constructor or factory. Cannot deserialize json object value: {"entries":[{"errorCapable":false,"metadata":false... Use Johnzon @ConstructorProperties or @JsonbCreator if constructor arguments are needed |
||
| "valid", "elementSchema", "comment", "props", "internalDefaultValue"}) | ||
| public Entry( | ||
|
Check warning on line 51 in component-server-parent/component-server-model/src/main/java/org/talend/sdk/component/server/front/model/Entry.java
|
||
| final String name, | ||
| final String rawName, | ||
| final Schema.Type type, | ||
| final boolean nullable, | ||
| final boolean metadata, | ||
| final boolean errorCapable, | ||
| final boolean valid, | ||
| final Schema elementSchema, | ||
| final String comment, | ||
| final Map<String, String> props, | ||
| final Object internalDefaultValue) { | ||
| this.name = name; | ||
| this.rawName = rawName; | ||
| this.type = type; | ||
| this.nullable = nullable; | ||
| this.metadata = metadata; | ||
| this.errorCapable = errorCapable; | ||
| this.valid = valid; | ||
| this.elementSchema = elementSchema; | ||
| this.comment = comment; | ||
| this.props.putAll(props); | ||
| this.internalDefaultValue = internalDefaultValue; | ||
| } | ||
|
|
||
| public <T> T getDefaultValue(){ | ||
| return (T) this.getInternalDefaultValue(); | ||
| } | ||
|
|
||
| public String getOriginalFieldName() { | ||
| return rawName != null ? rawName : name; | ||
| } | ||
|
|
||
| public String getProp(final String key) { | ||
| return this.props.get(key); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Copyright (C) 2006-2025 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front.model; | ||
|
|
||
| import java.beans.ConstructorProperties; | ||
| import java.math.BigDecimal; | ||
| import java.time.temporal.Temporal; | ||
| import java.util.Collection; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public final class Schema { | ||
|
|
||
| private final Type type; | ||
|
|
||
| private final Schema elementSchema; | ||
|
|
||
| private final List<Entry> entries; | ||
|
|
||
| private final List<Entry> metadata; | ||
|
|
||
| private final Map<String, String> props; | ||
|
|
||
| @ConstructorProperties({"type", "elementSchema", "entries", "metadata", "props"}) | ||
| public Schema( | ||
| final Type type, | ||
| final Schema elementSchema, | ||
| final List<Entry> entries, | ||
| final List<Entry> metadata, | ||
| final Map<String, String> props) { | ||
| this.type = type; | ||
| this.elementSchema = elementSchema; | ||
| this.entries = entries; | ||
| this.metadata = metadata; | ||
| this.props = props; | ||
| } | ||
|
|
||
| public String getProp(final String key){ | ||
| return this.props.get(key); | ||
| } | ||
|
|
||
| public enum Type { | ||
|
|
||
| RECORD(new Class<?>[] { Record.class }), | ||
| ARRAY(new Class<?>[] { Collection.class }), | ||
| STRING(new Class<?>[] { String.class, Object.class }), | ||
| BYTES(new Class<?>[] { byte[].class, Byte[].class }), | ||
| INT(new Class<?>[] { Integer.class }), | ||
| LONG(new Class<?>[] { Long.class }), | ||
| FLOAT(new Class<?>[] { Float.class }), | ||
| DOUBLE(new Class<?>[] { Double.class }), | ||
| BOOLEAN(new Class<?>[] { Boolean.class }), | ||
| DATETIME(new Class<?>[] { Long.class, Date.class, Temporal.class }), | ||
| DECIMAL(new Class<?>[] { BigDecimal.class }); | ||
|
|
||
| /** | ||
| * All compatibles Java classes | ||
| */ | ||
| private final Class<?>[] classes; | ||
|
|
||
| Type(final Class<?>[] classes) { | ||
| this.classes = classes; | ||
| } | ||
|
|
||
| /** | ||
| * Check if input can be affected to an entry of this type. | ||
| * | ||
| * @param input : object. | ||
| * | ||
| * @return true if input is null or ok. | ||
| */ | ||
| public boolean isCompatible(final Object input) { | ||
| if (input == null) { | ||
| return true; | ||
| } | ||
| for (final Class<?> clazz : classes) { | ||
| if (clazz.isInstance(input)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this configuration has been added ?