Skip to content

Commit

Permalink
refactor: fix sonarcloud code smells for injection issues (#142)
Browse files Browse the repository at this point in the history
* refactor: fix sonarcloud code smells for injection issues

* refactor: fix sonarcloud code smells

* refactor: spotless fixes

* refactor: sonar issues

* refactor: implemented comments
  • Loading branch information
Kammerlo committed May 3, 2024
1 parent 49c59b6 commit f0a1a52
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 26 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

---

# :rotating_light: This Repository is under active development. :rotating_light:
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cardano-foundation_cardano-rosetta-java&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cardano-foundation_cardano-rosetta-java)

# Cardano Rosetta API Java implementation
This repository provides a lightweight java implementation of the Rosetta API. It uses [Yaci-Store](https://github.com/bloxbean/yaci-store) as an indexer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ private String convert(CertificateType model) {
if (model == null) {
return null;
} else {
return model.equals(CertificateType.STAKE_REGISTRATION)
? OperationType.STAKE_KEY_REGISTRATION.getValue() :
model.equals(CertificateType.STAKE_DEREGISTRATION)
? OperationType.STAKE_KEY_DEREGISTRATION.getValue() : null;
return switch (model) {
case CertificateType.STAKE_REGISTRATION -> OperationType.STAKE_KEY_REGISTRATION.getValue();
case CertificateType.STAKE_DEREGISTRATION -> OperationType.STAKE_KEY_DEREGISTRATION.getValue();
default -> null;
};
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class ProtocolParams {

private BigInteger minPoolCost; //16
private BigInteger adaPerUtxoByte; //17
//private String nonce;

//Alonzo changes
private Map<String, long[]> costModels; //18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class ProtocolParamsEntity {

private BigInteger minPoolCost; //16
private BigInteger adaPerUtxoByte; //17
//private String nonce;

//Alonzo changes
private Map<String, long[]> costModels; //18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.lang.reflect.Type;
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
Expand All @@ -13,13 +14,12 @@
import org.cardanofoundation.rosetta.common.services.LoggingService;

@ControllerAdvice
@RequiredArgsConstructor
public class CustomRequestBodyAdviceAdapter extends RequestBodyAdviceAdapter {

@Autowired
LoggingService loggingService;
final LoggingService loggingService;

@Autowired
HttpServletRequest httpServletRequest;
final HttpServletRequest httpServletRequest;

@Override
public boolean supports(MethodParameter methodParameter, Type type, Class<? extends HttpMessageConverter<?>> aClass) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cardanofoundation.rosetta.common.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
Expand All @@ -14,10 +15,10 @@
import org.cardanofoundation.rosetta.common.services.LoggingService;

@ControllerAdvice
@RequiredArgsConstructor
public class CustomResponseBodyAdviceAdapter implements ResponseBodyAdvice<Object> {

@Autowired
LoggingService loggingService;
final LoggingService loggingService;

@Override
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
Expand All @@ -13,10 +14,10 @@
import org.cardanofoundation.rosetta.common.services.LoggingService;

@Component
@RequiredArgsConstructor
public class LogInterceptor implements HandlerInterceptor {

@Autowired
LoggingService loggingService;
final LoggingService loggingService;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
package org.cardanofoundation.rosetta.common.model.cardano.transaction;

import java.util.Arrays;
import java.util.Objects;

import org.openapitools.client.model.TransactionIdentifier;

public record MemPoolTransaction(TransactionIdentifier identifier, byte[] txBytes) {}
public record MemPoolTransaction(TransactionIdentifier identifier, byte[] txBytes) {

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
MemPoolTransaction that = (MemPoolTransaction) object;
return Objects.equals(identifier, that.identifier) && Arrays.equals(txBytes,
that.txBytes);
}

@Override
public int hashCode() {
int result = Objects.hash(identifier);
result = 31 * result + Arrays.hashCode(txBytes);
return result;
}

@Override
public String toString() {
return "MemPoolTransaction{" +
"identifier=" + identifier +
", txBytes=" + Arrays.toString(txBytes) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
Expand All @@ -17,9 +18,10 @@


@Configuration
@RequiredArgsConstructor
public class SpringWebConfig implements WebMvcConfigurer {
@Autowired
LogInterceptor logInterceptor;

final LogInterceptor logInterceptor;

@Override
public void addFormatters(final FormatterRegistry registry) {
Expand Down

0 comments on commit f0a1a52

Please sign in to comment.