Skip to content

Commit

Permalink
fix maxSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
noemil12 committed Nov 23, 2023
1 parent 5f6d361 commit 110452a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ public class PDNDExceptionHelper {
public Problem handle(Throwable ex){
ProblemBuilder builder = ProblemBuilder.builder();

if (ex instanceof PDNDGenericException casted) {
return builder.addExceptionType(casted.getExceptionType())
.addStatusCode(casted.getHttpStatus())
.setMessage(casted.getMessage())
if (ex instanceof PDNDGenericException casted ) {
return builder.addStatusCode(casted.getHttpStatus())
.addProblemError(casted.getExceptionType().getTitle(), casted.getExceptionType().getMessage())
.build();
}

return builder.addExceptionType(GENERIC_ERROR)
.addStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)
if (ex instanceof JWTException casted) {
return builder.addStatusCode(casted.getHttpStatus())
.addProblemError(casted.getExceptionType().getTitle(), casted.getExceptionType().getMessage())
.build();
}

return builder.addStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)
.addProblemError(GENERIC_ERROR.getTitle(), GENERIC_ERROR.getMessage())
.build();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package it.pagopa.interop.signalhub.pull.service.exception;


import it.pagopa.interop.signalhub.pull.service.rest.v1.dto.Problem;
import it.pagopa.interop.signalhub.pull.service.rest.v1.dto.ProblemError;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


public class ProblemBuilder {
private final Problem problem;
private ExceptionTypeEnum typeEnum;
private HttpStatus status;
private List<ProblemError> errors;
private String customMessage;

private ProblemBuilder(){
this.problem = new Problem();
}


public ProblemBuilder addExceptionType(ExceptionTypeEnum typeEnum){
this.typeEnum = typeEnum;
return this;
}

public ProblemBuilder addStatusCode(HttpStatus status) {
this.status = status;
return this;
Expand All @@ -33,13 +32,21 @@ public ProblemBuilder setMessage(String message){
return this;
}

public ProblemBuilder addProblemError(String code, String detail){
if(errors==null) errors= new ArrayList<>();
ProblemError problemError= new ProblemError(code,detail);
errors.add(problemError);
return this;
}

public Problem build(){
if (typeEnum == null || status == null) {
if (status == null) {
throw new IllegalArgumentException("Required arguments not founded");
}
this.problem.setStatus(this.status.value());
this.problem.setTitle(this.typeEnum.getTitle());
this.problem.setDetail(this.typeEnum.getMessage());
this.problem.setTitle(this.status.name());
this.problem.setDetail(this.status.getReasonPhrase());
if(errors!=null) this.problem.setErrors(errors);
if (StringUtils.isNotBlank(this.customMessage)) {
this.problem.setDetail(this.customMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public interface SignalRepository extends ReactiveCrudRepository<SignalEntity, L
"order by s.signal_id")
Flux<SignalEntity> findSignal(String eserviceId, Long signalIdStart, Long signalIdEnd);

@Query("select count (*) from signal s where s.eservice_id= :eserviceId")
Mono<Integer> countAllSignal(String eserviceId);
@Query("select max (s.signal_id) from signal s where s.eservice_id= :eserviceId" +
"group by s.eservice_id")
Mono<Integer> maxSignal(String eserviceId);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.pagopa.interop.signalhub.pull.service.service.impl;

import com.nimbusds.jose.util.Pair;
import it.pagopa.interop.signalhub.pull.service.exception.ExceptionTypeEnum;
import it.pagopa.interop.signalhub.pull.service.exception.PDNDGenericException;
import it.pagopa.interop.signalhub.pull.service.mapper.SignalMapper;
Expand All @@ -11,7 +10,6 @@
import it.pagopa.interop.signalhub.pull.service.service.SignalService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.zset.Tuple;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -42,7 +40,7 @@ public Flux<Signal> pullSignal(String consumerId, String eServiceId, Long signal
}

public Mono<Integer> counter(String eServiceId){
return signalRepository.countAllSignal(eServiceId);
return signalRepository.maxSignal(eServiceId);

}

Expand Down

0 comments on commit 110452a

Please sign in to comment.