Skip to content

Commit

Permalink
Checkstile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoSngular committed Oct 31, 2023
1 parent 44171b2 commit 0feef97
Show file tree
Hide file tree
Showing 49 changed files with 373 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

package com.sngular.kloadgen.config.schemaregistry;

import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME;
import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES;
import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -83,7 +79,7 @@ private void serializeProperties() {

private Map<String, String> getProperties() {
final Map<String, String> result = new HashMap<>();
final JMeterProperty property = getProperty(SCHEMA_REGISTRY_PROPERTIES);
final JMeterProperty property = getProperty(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES);
if (Objects.nonNull(property)) {
result.putAll(
this.fromTestElementToPropertiesMap((List<TestElementProperty>) property.getObjectValue()));
Expand All @@ -94,15 +90,15 @@ private Map<String, String> getProperties() {
}

private String getRegistryName() {
String registryName = getPropertyAsString(SCHEMA_REGISTRY_NAME);
String registryName = getPropertyAsString(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME);
if (StringUtils.isBlank(registryName)) {
registryName = this.schemaRegistryName;
}
return registryName;
}

private String getRegistryUrl() {
String registryUrl = getPropertyAsString(SCHEMA_REGISTRY_URL);
String registryUrl = getPropertyAsString(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL);
if (StringUtils.isBlank(registryUrl)) {
registryUrl = this.schemaRegistryUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.sngular.kloadgen.config.schemaregistry;

import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME;
import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES;
import static com.sngular.kloadgen.config.schemaregistry.SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL;

import java.beans.PropertyDescriptor;

Expand All @@ -26,22 +23,23 @@ public SchemaRegistryConfigElementBeanInfo() {

super(SchemaRegistryConfigElement.class);

createPropertyGroup("schema_registry_config", new String[]{SCHEMA_REGISTRY_NAME, SCHEMA_REGISTRY_URL, SCHEMA_REGISTRY_PROPERTIES});
createPropertyGroup("schema_registry_config", new String[]{SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME,
SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL, SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES});

final PropertyDescriptor schemaRegistryName = property(SCHEMA_REGISTRY_NAME);
final PropertyDescriptor schemaRegistryName = property(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME);
schemaRegistryName.setPropertyEditorClass(SchemaRegistryNamePropertyEditor.class);
schemaRegistryName.setValue(NOT_UNDEFINED, Boolean.TRUE);
schemaRegistryName.setValue(DEFAULT, SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME_DEFAULT);
schemaRegistryName.setValue(NOT_EXPRESSION, Boolean.FALSE);

final PropertyDescriptor schemaRegistryUrl = property(SCHEMA_REGISTRY_URL);
final PropertyDescriptor schemaRegistryUrl = property(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL);
schemaRegistryUrl.setPropertyEditorClass(SchemaRegistryConfigPropertyEditor.class);
schemaRegistryUrl.setValue(NOT_UNDEFINED, Boolean.TRUE);
schemaRegistryUrl.setValue(DEFAULT, SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL_DEFAULT);
schemaRegistryUrl.setValue(NOT_EXPRESSION, Boolean.FALSE);

final TypeEditor tableEditor = TypeEditor.TableEditor;
final PropertyDescriptor tableProperties = property(SCHEMA_REGISTRY_PROPERTIES, tableEditor);
final PropertyDescriptor tableProperties = property(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES, tableEditor);
tableProperties.setValue(TableEditor.CLASSNAME, PropertyMapping.class.getName());
tableProperties.setValue(TableEditor.HEADERS, new String[]{"Property Name", "Property Value"});
tableProperties.setValue(TableEditor.OBJECT_PROPERTIES, new String[]{PropertyMapping.PROPERTY_NAME, PropertyMapping.PROPERTY_VALUE});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sngular.kloadgen.extractor;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -14,18 +13,18 @@
import io.confluent.kafka.schemaregistry.ParsedSchema;
import org.apache.commons.lang3.tuple.Pair;

public class SchemaExtractor {
public class SchemaExtractor {

private SchemaRegistryEnum type;

public SchemaExtractor() {
}

public SchemaRegistryEnum getType(){
public final SchemaRegistryEnum getType() {
return type;
}

public void setType(SchemaRegistryEnum type){
public final void setType(final SchemaRegistryEnum type) {
this.type = type;
}

Expand All @@ -37,10 +36,6 @@ public static List<FieldValueMapping> flatPropertiesList(final ParsedSchema pars
return ExtractorFactory.getExtractor(parserSchema.schemaType()).processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
}

public static List<String> schemaTypesList(final File schemaFile, final String schemaType, final SchemaRegistryEnum schemaRegistryEnum) throws IOException {
return ExtractorFactory.getExtractor(schemaType).getSchemaNameList(readLineByLine(schemaFile.getPath()), schemaRegistryEnum);
}

public static String readSchemaFile(final String filePath) throws IOException {
return readLineByLine(filePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static ExtractorRegistry getExtractor(final String schemaType) {
switch (SchemaTypeEnum.valueOf(schemaType.toUpperCase())) {
case JSON:
response = JSON_EXTRACTOR;
break; case AVRO:
break;
case AVRO:
response = AVRO_EXTRACTOR;
break;
case PROTOBUF:
Expand All @@ -51,7 +52,7 @@ public static ExtractorRegistry getExtractor(final String schemaType) {
}
}

public static SchemaRegistryEnum getSchemaRegistry(String schemaRegistryEnum) {
public static SchemaRegistryEnum getSchemaRegistry(final String schemaRegistryEnum) {
if (schemaRegistryEnum != null && EnumUtils.isValidEnum(SchemaRegistryEnum.class, schemaRegistryEnum.toUpperCase())) {
return SchemaRegistryEnum.valueOf(schemaRegistryEnum.toUpperCase());
} else {
Expand All @@ -67,7 +68,7 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
final String schemaType = parsedSchemaAdapter.getType();

List<FieldValueMapping> attributeList = new ArrayList<>();
SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());
final SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());

Object schema = null;
//TODO change parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public abstract class AbstractAvroFileExtractor {
protected AbstractAvroFileExtractor() {
}

public List<FieldValueMapping> processSchemaDefault(final Schema schemaReceived) {
public final List<FieldValueMapping> processSchemaDefault(final Schema schemaReceived) {
final var attributeList = new ArrayList<FieldValueMapping>();
Schema aux = null;
if (checkIfUnion(schemaReceived)) {
aux = schemaReceived.getTypes().get(schemaReceived.getTypes().size() - 1);
} else if (checkIfRecord(schemaReceived)) {
aux = schemaReceived;
}
if(aux != null && (checkIfUnion(schemaReceived) || checkIfRecord(schemaReceived))){
if (aux != null && (checkIfUnion(schemaReceived) || checkIfRecord(schemaReceived))) {
aux.getFields().forEach(field -> processField(field, attributeList, true, true));
}
return attributeList;
}

public List<String> getSchemaNameList(Schema schema) {
public final List<String> getSchemaNameList(final Schema schema) {
return new ArrayList<>(extractSchemaNames(schema));
}

public void processField(
public final void processField(
final Schema.Field innerField, final List<FieldValueMapping> completeFieldList, final boolean isAncestorRequired, final boolean isAncestor) {
if (checkIfRecord(innerField.schema())) {
processRecordFieldList(innerField.name(), ".", processFieldList(innerField.schema().getFields(), isAncestorRequired), completeFieldList);
Expand Down Expand Up @@ -352,8 +352,8 @@ private boolean checkIfRequiredField(final Schema innerSchema) {
return result;
}

private Set<String> extractSchemaNames(Schema schema) {
Set<String> schemaNames = new HashSet<>();
private Set<String> extractSchemaNames(final Schema schema) {
final Set<String> schemaNames = new HashSet<>();
if (checkIfRecord(schema)) {
schemaNames.add(schema.getName());
} else if (checkIfArray(schema)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.sngular.kloadgen.extractor.extractors.avro;

import static com.sngular.kloadgen.common.SchemaRegistryEnum.APICURIO;
import static com.sngular.kloadgen.common.SchemaRegistryEnum.CONFLUENT;

import java.util.List;
import java.util.Map;

Expand All @@ -15,18 +12,18 @@

public class AvroExtractor implements ExtractorRegistry<Object> {

static Map<SchemaRegistryEnum, Extractor> schemaRegistryMap = Map.of(CONFLUENT, new AvroConfluentExtractor(), APICURIO,
static Map<SchemaRegistryEnum, Extractor> schemaRegistryMap = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO,
new AvroApicurioExtractor());

public final List<FieldValueMapping> processSchema(final Object schema, SchemaRegistryEnum registryEnum) {
public final List<FieldValueMapping> processSchema(final Object schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).processSchema(schema);
}

public final ParsedSchema processSchema(final String fileContent) {
return new AvroSchema(fileContent);
}

public final List<String> getSchemaNameList(final String schema, SchemaRegistryEnum registryEnum) {
public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).getSchemaNameList(schema);
}

Expand Down
Loading

0 comments on commit 0feef97

Please sign in to comment.