Skip to content

Commit

Permalink
Fixing codacy recommended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoSngular committed Oct 13, 2023
1 parent f82173a commit e7d178c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ private static String readLineByLine(final String filePath) throws IOException {
return contentBuilder.toString();
}

private static List<FieldValueMapping> processSchema(final ParsedSchema parsedSchema) {
return ExtractorFactory.getExtractor(parsedSchema.schemaType()).processSchema(parsedSchema.rawSchema().toString(), SchemaRegistryEnum.CONFLUENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<FieldValueMapping> processSchemaDefault(final Schema schemaReceived)
}

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

public void processField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public final List<FieldValueMapping> processSchema(final Object schema, SchemaRe
return schemaRegistryMap.get(registryEnum).processSchema(schema);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public final List<FieldValueMapping> processSchema(final Object schemaReceived,
return schemaRegistryMap.get(registryEnum).processSchema(schemaReceived);
}

@Override
public ParsedSchema processSchema(String fileContent) {
public final ParsedSchema processSchema(String fileContent) {
return new JsonSchema(fileContent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public final List<FieldValueMapping> processSchema(final Object schemaReceived,
return schemaRegistryMap.get(registryEnum).processSchema(schemaReceived);
}

@Override
public ParsedSchema processSchema(String fileContent) {
public final ParsedSchema processSchema(String fileContent) {
return new ProtobufSchema(fileContent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
Expand All @@ -28,11 +26,8 @@
import com.sngular.kloadgen.extractor.extractors.ExtractorFactory;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.util.AutoCompletion;
import com.sngular.kloadgen.util.PropsKeysHelper;
import com.sngular.kloadgen.util.SchemaRegistryKeyHelper;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
Expand All @@ -48,7 +43,6 @@
import org.apache.jmeter.testbeans.gui.TestBeanGUI;
import org.apache.jmeter.testbeans.gui.TestBeanPropertyEditor;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;

@Slf4j
Expand Down Expand Up @@ -100,18 +94,18 @@ public final void actionFileChooser(final ActionEvent event) {

if (JFileChooser.APPROVE_OPTION == returnValue) {
final File schemaFile = Objects.requireNonNull(fileChooser.getSelectedFile());
try {
final String schemaType = schemaTypeComboBox.getSelectedItem().toString();
ExtractorRegistry extractor = ExtractorFactory.getExtractor(schemaType);
String fileContent = SchemaExtractor.readSchemaFile(schemaFile.getPath());
this.parserSchema = extractor.processSchema(fileContent);
List<FieldValueMapping> schemaFieldList = extractor.processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
buildTable(schemaFieldList);
JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA, fileContent);
JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE, schemaType);
} catch (final IOException e) {
try {
final String schemaType = schemaTypeComboBox.getSelectedItem().toString();
final ExtractorRegistry extractor = ExtractorFactory.getExtractor(schemaType);
final String fileContent = SchemaExtractor.readSchemaFile(schemaFile.getPath());
this.parserSchema = extractor.processSchema(fileContent);
final List<FieldValueMapping> schemaFieldList = extractor.processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
buildTable(schemaFieldList);
JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA, fileContent);
JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE, schemaType);
} catch (final IOException e) {
JOptionPane.showMessageDialog(panel, "Can't read a file : " + e.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES,
JOptionPane.ERROR_MESSAGE);
JOptionPane.ERROR_MESSAGE);
log.error(e.getMessage(), e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/sngular/kloadgen/sampler/SamplerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ public static BaseLoadGenerator configureValueGenerator(final Properties props)
}
}
} else {
try{
try {
generator.setUpGenerator(jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA), (List<FieldValueMapping>) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES));
}catch (final SchemaParseException exc) {
} catch (final SchemaParseException exc) {
generator.setUpGenerator(props.getProperty(PropsKeysHelper.VALUE_SCHEMA), (List<FieldValueMapping>) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES));
}
}
Expand Down Expand Up @@ -473,7 +473,7 @@ public static List<String> populateHeaders(final List<HeaderMapping> kafkaHeader

private static BaseLoadGenerator getLoadGenerator() {
final BaseLoadGenerator generator;
String schemaType = JMeterContextService.getContext().getProperties().getProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE);
final String schemaType = JMeterContextService.getContext().getProperties().getProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE);
if (Objects.nonNull(schemaType)) {
if (JSON_TYPE_SET.contains(schemaType.toLowerCase())) {
generator = new JsonSRLoadGenerator();
Expand Down

0 comments on commit e7d178c

Please sign in to comment.