Skip to content

Commit

Permalink
fix: Tpp Model Update (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: stefanodel <[email protected]>
  • Loading branch information
Vitolo-Andrea and stedelia authored Nov 14, 2024
1 parent a958fa7 commit c42d539
Show file tree
Hide file tree
Showing 22 changed files with 1,513 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
-Dsonar.java.binaries=target/classes \
-Dsonar.junit.reportPaths=target/surefire-reports \
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml \
-Dsonar.exclusions=**/configuration/**,**/enums/**,**/model/**,**/stub/**,**/dto/**,**/*Constant*,**/*Config.java,**/*Scheduler.java,**/*Application.java,**/src/test/**,**/Dummy*.java
-Dsonar.exclusions=**/configuration/**,**/enums/**,**/model/**,**/dto/**,**/*Constant*,**/*Config.java,**/*Application.java,**/src/test/**,**/Dummy*.java
- name: Fetch all branches
run: git fetch --all
14 changes: 14 additions & 0 deletions .spectral.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends:
- "spectral:oas"
- "spectral:asyncapi"
- "https://unpkg.com/@stoplight/spectral-owasp-ruleset/dist/ruleset.mjs"
overrides:
- files:
- "src/main/resources/META-INF/openapi.yaml#/paths/~1token/post/security"
rules:
owasp:api2:2023-write-restricted: "off"
- files:
- "src/main/resources/META-INF/openapi.yaml#/paths/~1.well-known~1jwks.json/get/security"
- "src/main/resources/META-INF/openapi.yaml#/paths/~1.well-known~1openid-configuration/get/security"
rules:
owasp:api2:2023-read-restricted: "off"
10 changes: 9 additions & 1 deletion src/main/java/it/gov/pagopa/tpp/configuration/ExceptionMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ public ExceptionMap() {
message
)
);

exceptions.put(TppConstants.ExceptionName.TPP_ALREADY_ONBOARDED, message ->
new ClientExceptionWithBody(
HttpStatus.FORBIDDEN,
TppConstants.ExceptionCode.TPP_ALREADY_ONBOARDED,
message
)
);
}

public RuntimeException throwException(String exceptionKey, String message) {
if (exceptions.containsKey(exceptionKey)) {
return exceptions.get(exceptionKey).apply(message);
} else {
log.error("Exception Name Not Found: {}", exceptionKey);
log.error("[EMP-TPP][EXCEPTION-MAP] Exception Name Not Found: {}", exceptionKey);
return new RuntimeException();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/constants/TppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ public class TppConstants {
public static final class ExceptionCode {

public static final String TPP_NOT_ONBOARDED = "TPP_NOT_ONBOARDED";

public static final String TPP_ALREADY_ONBOARDED = "TPP_ALREADY_ONBOARDED";
public static final String GENERIC_ERROR = "GENERIC_ERROR";
private ExceptionCode() {}
}

public static final class ExceptionMessage {

public static final String TPP_NOT_ONBOARDED = "TPP_NOT_ONBOARDED";

public static final String TPP_ALREADY_ONBOARDED = "TPP_ALREADY_ONBOARDED";
public static final String GENERIC_ERROR = "GENERIC_ERROR";
private ExceptionMessage() {}
}

public static final class ExceptionName {

public static final String TPP_NOT_ONBOARDED = "TPP_NOT_ONBOARDED";

public static final String TPP_ALREADY_ONBOARDED = "TPP_ALREADY_ONBOARDED";
public static final String GENERIC_ERROR = "GENERIC_ERROR";
private ExceptionName() {}
}
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/it/gov/pagopa/tpp/controller/TppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppIdList;
import it.gov.pagopa.tpp.dto.TppUpdateState;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -13,10 +14,10 @@
public interface TppController {

/**
* Get list of tpps
* Get list of tpp
*
* @param tppIdList whose data is to be retrieved
* @return outcome of retrieving the tpps
* @return outcome of retrieving the tpp
*/
@PostMapping("/list")
Mono<ResponseEntity<List<TppDTO>>> getEnabledList(@Valid @RequestBody TppIdList tppIdList);
Expand All @@ -25,26 +26,30 @@ public interface TppController {
/**
* Update a tpp
*
* @param tppDTO to update
* @param tppUpdateState to update
* @return outcome of the update
*/
@PutMapping()
Mono<ResponseEntity<TppDTO>> updateState(@Valid @RequestBody TppDTO tppDTO);
Mono<ResponseEntity<TppDTO>> updateState(@Valid @RequestBody TppUpdateState tppUpdateState);

/**
* Save a tpp
*
* @param tppDTO to save
* @return outcome of saving the tpp
*/
@PostMapping()
Mono<ResponseEntity<TppDTO>> upsert(@Valid @RequestBody TppDTO tppDTO);
@PostMapping("/save")
Mono<ResponseEntity<TppDTO>> save(@Valid @RequestBody TppDTO tppDTO);

@PutMapping("/update")
Mono<ResponseEntity<TppDTO>> update(@Valid @RequestBody TppDTO tppDTO);


/**
* Save a tpp
* Get a tpp
*
* @param tppId to save
* @return outcome of saving the tpp
* @param tppId to get
* @return outcome of getting tpp
*/
@GetMapping("/{tppId}")
Mono<ResponseEntity<TppDTO>> get(@Valid @PathVariable String tppId);
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/it/gov/pagopa/tpp/controller/TppControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppIdList;
import it.gov.pagopa.tpp.dto.TppUpdateState;
import it.gov.pagopa.tpp.service.TppServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

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

@RestController
public class TppControllerImpl implements TppController {
Expand All @@ -27,15 +29,21 @@ public Mono<ResponseEntity<List<TppDTO>>> getEnabledList(TppIdList tppIdList) {


@Override
public Mono<ResponseEntity<TppDTO>> updateState(TppDTO tppDTO) {
return tppService.updateState(tppDTO.getTppId(),tppDTO.getState())
public Mono<ResponseEntity<TppDTO>> updateState(TppUpdateState tppUpdateState) {
return tppService.updateState(tppUpdateState.getTppId(),tppUpdateState.getState())
.map(ResponseEntity::ok);

}

@Override
public Mono<ResponseEntity<TppDTO>> upsert(TppDTO tppDTO) {
return tppService.upsert(tppDTO)
public Mono<ResponseEntity<TppDTO>> save(TppDTO tppDTO) {
return tppService.createNewTpp(tppDTO, String.format("%s_%d", UUID.randomUUID(), System.currentTimeMillis()))
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TppDTO>> update(TppDTO tppDTO) {
return tppService.updateExistingTpp(tppDTO)
.map(ResponseEntity::ok);
}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TppDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,49 @@

import it.gov.pagopa.tpp.enums.AuthenticationType;
import it.gov.pagopa.tpp.model.Contact;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.time.LocalDateTime;

@Data
@SuperBuilder
@NoArgsConstructor
public class TppDTO {

private String tppId;

@NotBlank(message = "Entity ID must not be blank")
@Pattern(regexp = "^(\\d{11}|[A-Za-z0-9]{16})$", message = "Entity ID must be 11 digits or up to 16 alphanumeric characters")
private String entityId;

@NotBlank(message = "ID PSP must not be blank")
private String idPsp;

@NotBlank(message = "Business name must not be blank")
private String businessName;

@NotBlank(message = "Legal address must not be blank")
private String legalAddress;

@Pattern(regexp = "^(https?|ftp)://[^ /$.?#].[^ ]*$", message = "Message URL must be a valid URL")
private String messageUrl;

@Pattern(regexp = "^(https?|ftp)://[^ /$.?#].[^ ]*$", message = "Authentication URL must be a valid URL")
private String authenticationUrl;

@NotNull(message = "Authentication type must not be null")
private AuthenticationType authenticationType;

@NotNull(message = "Contact must not be null")
private Contact contact;

private Boolean state;

private LocalDateTime creationDate;

private LocalDateTime lastUpdateDate;
}
4 changes: 4 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TppIdList.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package it.gov.pagopa.tpp.dto;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TppIdList {
@NotNull
List<String> ids;
}
16 changes: 16 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TppUpdateState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.gov.pagopa.tpp.dto;

import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@NoArgsConstructor
public class TppUpdateState {
@NotNull
private String tppId;
@NotNull
private Boolean state;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ public TppDTO map(Tpp tpp){
.authenticationUrl(tpp.getAuthenticationUrl())
.authenticationType(tpp.getAuthenticationType())
.tppId(tpp.getTppId())
.idPsp(tpp.getIdPsp())
.legalAddress(tpp.getLegalAddress())
.businessName(tpp.getBusinessName())
.contact(tpp.getContact())
.entityId(tpp.getEntityId())
.creationDate(tpp.getCreationDate())
.lastUpdateDate(tpp.getLastUpdateDate())
.build();
}
}
7 changes: 6 additions & 1 deletion src/main/java/it/gov/pagopa/tpp/model/Contact.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.gov.pagopa.tpp.model;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -8,8 +10,11 @@
@AllArgsConstructor
@NoArgsConstructor
public class Contact {

private String name;

@Pattern(regexp = "^\\d{9,10}$", message = "Number must be between 9 and 10 digits")
private String number;

@Email(message = "Email must be valid")
private String email;
}
8 changes: 7 additions & 1 deletion src/main/java/it/gov/pagopa/tpp/model/Tpp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.experimental.SuperBuilder;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

@Document(collection = "tpp")
@Data
@SuperBuilder
Expand All @@ -16,10 +18,14 @@ public class Tpp {
private String id;
private String tppId;
private String entityId;
private String idPsp;
private String businessName;
private String legalAddress;
private String messageUrl;
private String authenticationUrl;
private AuthenticationType authenticationType;
private Contact contact;
private Boolean state;
private Contact contact;
private LocalDateTime creationDate;
private LocalDateTime lastUpdateDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public Tpp map(TppDTO tppDTO){
return Tpp.builder()
.state(true)
.tppId(tppDTO.getTppId())
.idPsp(tppDTO.getIdPsp())
.messageUrl(tppDTO.getMessageUrl())
.legalAddress(tppDTO.getLegalAddress())
.authenticationUrl(tppDTO.getAuthenticationUrl())
.authenticationType(tppDTO.getAuthenticationType())
.businessName(tppDTO.getBusinessName())
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/repository/TppRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface TppRepository extends ReactiveMongoRepository<Tpp,String> {

Mono<Tpp> findByTppId(String tppId);

Mono<Tpp> findByEntityId(String entityId);

}
4 changes: 3 additions & 1 deletion src/main/java/it/gov/pagopa/tpp/service/TppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public interface TppService {

Mono<List<TppDTO>> getEnabledList(List<String> tppIdList);

Mono<TppDTO> upsert(TppDTO tppDTO);
Mono<TppDTO> createNewTpp(TppDTO tppDTO, String tppId);

Mono<TppDTO> updateExistingTpp(TppDTO tppDTO);

Mono<TppDTO> updateState(String tppId, Boolean state);

Expand Down
Loading

0 comments on commit c42d539

Please sign in to comment.