Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gr812b committed Jan 2, 2025
1 parent 554963a commit 94e3d66
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 169 deletions.
133 changes: 69 additions & 64 deletions backend/src/main/java/com/mcmasterbaja/ExceptionMappers.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.mcmasterbaja;

import java.util.UUID;

import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

import com.mcmasterbaja.exceptions.AnalyzerException;
import com.mcmasterbaja.exceptions.InvalidArgumentException;
import com.mcmasterbaja.exceptions.InvalidColumnException;
Expand All @@ -13,29 +8,31 @@
import com.mcmasterbaja.exceptions.InvalidOutputFileException;
import com.mcmasterbaja.exceptions.StorageException;
import com.mcmasterbaja.model.ErrorResponse;

import jakarta.inject.Inject;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.UUID;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

// Exceptions are mapped in priority of most specific first
public class ExceptionMappers {

@Inject
Logger logger;
@Inject Logger logger;

// Handles invalid arguments
@ServerExceptionMapper(value = { InvalidArgumentException.class })
@ServerExceptionMapper(value = {InvalidArgumentException.class})
public Response invalidArgument(RuntimeException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid argument was passed.",
"INVALID_ARGUMENT",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid argument was passed.",
"INVALID_ARGUMENT",
e.getMessage());

return Response.status(Response.Status.BAD_REQUEST)
.entity(errorResponse)
Expand All @@ -49,12 +46,13 @@ public Response invalidColumn(InvalidColumnException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid column was specified.",
"INVALID_COLUMN",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid column was specified.",
"INVALID_COLUMN",
e.getMessage());

return Response.status(Response.Status.BAD_REQUEST)
.entity(errorResponse)
Expand All @@ -68,12 +66,13 @@ public Response headerException(InvalidHeaderException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Failed to read headers from input file.",
"HEADER_ERROR",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Failed to read headers from input file.",
"HEADER_ERROR",
e.getMessage());

return Response.status(Response.Status.BAD_REQUEST)
.entity(errorResponse)
Expand All @@ -87,12 +86,13 @@ public Response invalidInputFile(InvalidInputFileException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid input file was specified.",
"INVALID_INPUT_FILE",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid input file was specified.",
"INVALID_INPUT_FILE",
e.getMessage());

return Response.status(Response.Status.BAD_REQUEST)
.entity(errorResponse)
Expand All @@ -106,12 +106,13 @@ public Response invalidOutputFile(InvalidOutputFileException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid output file was specified.",
"INVALID_OUTPUT_FILE",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An invalid output file was specified.",
"INVALID_OUTPUT_FILE",
e.getMessage());

return Response.status(Response.Status.BAD_REQUEST)
.entity(errorResponse)
Expand All @@ -125,12 +126,13 @@ public Response mapStorageException(StorageException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Something went wrong. It's probably your fault.",
"STORAGE_EXCEPTION",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Something went wrong. It's probably your fault.",
"STORAGE_EXCEPTION",
e.getMessage());

return Response.status(500).entity(errorResponse).type(MediaType.APPLICATION_JSON).build();
}
Expand All @@ -141,12 +143,13 @@ public Response mapAnalyzerException(AnalyzerException e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An error occurred with the analyzer.",
"ANALYZER_ERROR",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"An error occurred with the analyzer.",
"ANALYZER_ERROR",
e.getMessage());

return Response.status(500).entity(errorResponse).type(MediaType.APPLICATION_JSON).build();
}
Expand All @@ -156,12 +159,13 @@ public Response mapUnsatisfiedLink(UnsatisfiedLinkError e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[6].getClassName() + "." + e.getStackTrace()[6].getMethodName(),
"Failed to link to parser library. Might need to restart the backend.",
"UNSATISFIED_LINK_ERROR",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[6].getClassName() + "." + e.getStackTrace()[6].getMethodName(),
"Failed to link to parser library. Might need to restart the backend.",
"UNSATISFIED_LINK_ERROR",
e.getMessage());

return Response.status(500).entity(errorResponse).type(MediaType.APPLICATION_JSON).build();
}
Expand All @@ -171,13 +175,14 @@ public Response mapUnsatisfiedLink(NoClassDefFoundError e) {
String errorId = UUID.randomUUID().toString();
logger.error("errorId[{}]", errorId, e);

ErrorResponse errorResponse = new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Failed to link to parser library. Probably need to restart your backend, live reload"
+ " for the parser does not work.",
"UNSATISFIED_LINK_ERROR",
e.getMessage());
ErrorResponse errorResponse =
new ErrorResponse(
errorId,
e.getStackTrace()[0].getClassName() + "." + e.getStackTrace()[0].getMethodName(),
"Failed to link to parser library. Probably need to restart your backend, live reload"
+ " for the parser does not work.",
"UNSATISFIED_LINK_ERROR",
e.getMessage());

return Response.status(500).entity(errorResponse).type(MediaType.APPLICATION_JSON).build();
}
Expand Down
21 changes: 9 additions & 12 deletions backend/src/main/java/com/mcmasterbaja/FileAnalyzeResource.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package com.mcmasterbaja;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;

import com.mcmasterbaja.analyzer.Analyzer;
import com.mcmasterbaja.analyzer.AnalyzerFactory;
import com.mcmasterbaja.annotations.OnAnalyzerException;
Expand All @@ -17,14 +9,19 @@
import com.mcmasterbaja.model.MinMax;
import com.mcmasterbaja.services.FileMetadataService;
import com.mcmasterbaja.services.StorageService;

import jakarta.inject.Inject;
import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PATCH;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;

@jakarta.ws.rs.Path("/")
public class FileAnalyzeResource {
Expand Down Expand Up @@ -88,9 +85,9 @@ public Boolean toggleLive() {
Serial.exit = true;
} else {
new Thread(
() -> {
Serial.readLive();
})
() -> {
Serial.readLive();
})
.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja;

import com.mcmasterbaja.exceptions.InvalidInputFileException;
import com.mcmasterbaja.exceptions.FileNotFoundException;
import com.mcmasterbaja.exceptions.InvalidInputFileException;
import com.mcmasterbaja.model.FileInformation;
import com.mcmasterbaja.model.FileTimespan;
import com.mcmasterbaja.services.FileMetadataService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mcmasterbaja.annotations.OnAnalyzerException;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.exceptions.CsvException;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import java.io.BufferedWriter;
Expand All @@ -14,8 +13,6 @@
import java.util.Arrays;
import java.util.List;
import lombok.SneakyThrows;


import org.jboss.logging.Logger;

@Dependent
Expand All @@ -30,8 +27,8 @@ public class AccelCurveAnalyzer extends Analyzer {
// outputFiles are first primary RPM rolling average, then secondary RPM rolling average, then
// interpolated, then accel curve (runs)
@Override
@SneakyThrows
public void analyze(AnalyzerParams params) {
@SneakyThrows
public void analyze(AnalyzerParams params) {
extractParams(params);
logger.info("Combining \"" + inputFiles[0] + "\" and \"" + inputFiles[1] + "\"");
logger.info("sGolay Averaging...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.annotations.OnAnalyzerException;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import java.util.List;
import lombok.SneakyThrows;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import java.util.List;
import lombok.SneakyThrows;
import org.jboss.logging.Logger;

@Dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.mcmasterbaja.annotations.OnAnalyzerException;
import com.mcmasterbaja.exceptions.InvalidHeaderException;
import com.mcmasterbaja.model.AnalyzerParams;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import lombok.SneakyThrows;


import com.mcmasterbaja.model.AnalyzerParams;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import lombok.SneakyThrows;
import org.jboss.logging.Logger;

@Dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

import com.mcmasterbaja.annotations.OnAnalyzerException;
import com.mcmasterbaja.exceptions.InvalidHeaderException;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import lombok.SneakyThrows;


import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvValidationException;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import java.io.IOException;
import lombok.SneakyThrows;
import org.jboss.logging.Logger;

@Dependent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.mcmasterbaja.analyzer;

import java.io.IOException;

import com.mcmasterbaja.annotations.OnAnalyzerException;
import com.mcmasterbaja.exceptions.InvalidHeaderException;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvValidationException;

import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
Expand Down Expand Up @@ -87,7 +81,7 @@ public void cubicMultiply(
double timestamp = Double.parseDouble(nextLine[xAxisIndex]);
double data = Double.parseDouble(nextLine[yAxisIndex]);
double newValue = cubicFunction(data);
writer.writeNext(new String[] { Double.toString(timestamp), Double.toString(newValue) });
writer.writeNext(new String[] {Double.toString(timestamp), Double.toString(newValue)});
}

reader.close();
Expand All @@ -97,4 +91,4 @@ public void cubicMultiply(
private double cubicFunction(double x) {
return this.a * Math.pow(x, 3) + this.b * Math.pow(x, 2) + this.c * x + this.d;
}
}
}
Loading

0 comments on commit 94e3d66

Please sign in to comment.