Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions component-server-parent/component-server-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,102 @@

<build>
<plugins>
<plugin>
Copy link
Contributor Author

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 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because Entry need more than 10 parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, usually we can do some exception by configuration but it seems not possible for number of parameter as you probably already checked. I had the same issue few days ago, and instead of duplicate all the configuration from the parent I have simply deactivate checkstyle on the methode. In the Entry class you can do:

    @ConstructorProperties({ "name", "rawName", "type", "nullable", "metadata", "errorCapable",
            "valid", "elementSchema", "comment", "props", "internalDefaultValue" })
    // Checkstyle off to let have 11 parameters to this constructor (normally 10 max)
    // CHECKSTYLE:OFF
    public Entry(
            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) {
        // CHECKSTYLE:ON

It is to authorize an exception, the issue with copying the whole configuration is that if we change something the parent, it will not be reflected in this module.

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<excludes>**/HelpMojo*,**/maven/legacy/model/**</excludes>
<checkstyleRules>
<module name="Checker">
<module name="FileLength">
<property name="max" value="3500" />
<property name="fileExtensions" value="java" />
</module>
<module name="FileTabCharacter" />
<module name="LineLength">
<property name="max" value="180" />
<property name="ignorePattern" value="@version|@see" />
</module>
<module name="TreeWalker">
<module name="SuppressionCommentFilter" />
<module name="FinalParameters" />
<module name="ConstantName">
<property name="format" value="^_?((log)|(logger)|([a-z][a-zA-Z]*ThreadLocal)|([A-Z][A-Z0-9]*(_[A-Z0-9]+)*))$" />
</module>
<module name="LocalVariableName" />
<module name="MethodName">
<property name="format" value="^_?[a-z][a-zA-Z0-9]*$" />
</module>
<module name="PackageName" />
<module name="LocalFinalVariableName" />
<module name="ParameterName" />
<module name="StaticVariableName" />
<module name="TypeName">
<property name="format" value="^_?[A-Z][a-zA-Z0-9]*$" />
</module>
<module name="AvoidStarImport">
<property name="excludes" value="java.io,java.net,java.util,javax.enterprise.inject.spi,javax.enterprise.context" />
</module>
<module name="IllegalImport" />
<module name="RedundantImport" />
<module name="UnusedImports" />
<module name="MethodLength">
<property name="max" value="250" />
</module>
<module name="ParameterNumber">
<property name="max" value="11" />
</module>
<module name="EmptyBlock">
<property name="option" value="text" />
</module>
<module name="NeedBraces" />
<module name="LeftCurly">
<property name="option" value="EOL" />
</module>
<module name="RightCurly">
<property name="option" value="SAME" />
</module>
<module name="EmptyStatement" />
<module name="EqualsHashCode" />
<module name="DefaultComesLast" />
<module name="MissingSwitchDefault" />
<module name="FallThrough" />
<module name="MultipleVariableDeclarations" />
<module name="com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck">
<property name="severity" value="ignore" />
</module>
<!-- using lombok this constraint is not accurate
<module name="HideUtilityClassConstructor" />
-->
<module name="com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck">
<property name="packageAllowed" value="false" />
<property name="protectedAllowed" value="true" />
<property name="publicMemberPattern" value="^serialVersionUID" />
<property name="severity" value="warning" />
</module>
<module name="UpperEll" />
<module name="ImportOrder">
<property name="groups" value="*,java,javafx,javax,jakarta,jdk,com,crawlercommons,org,orgomg,brave,com.jcraft,freemarker,io,zipkin2,routines,lombok" />
<property name="ordered" value="true" />
<property name="separated" value="true" />
<property name="option" value="top" />
<property name="sortStaticImportsAlphabetically" value="true" />
</module>
</module>
</module>
</checkstyleRules>
</configuration>
<executions>
<execution>
<id>verify-style</id>
<goals>
<goal>check</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
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",
"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

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-server-parent/component-server-model/src/main/java/org/talend/sdk/component/server/front/model/Entry.java#L51

Constructor has 11 parameters, which is greater than 7 authorized.
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a java doc to explain that this class is only for deserialization usage and should be used as a DTO not as a real TCK schema since it doesn't implement SChama interface and doesn't have some business rule as the SchemaImpl from component-runtime-impl has.

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;
}
}
}
6 changes: 6 additions & 0 deletions component-server-parent/component-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Loading
Loading