Skip to content

Commit

Permalink
Releases/1.1.2 (#95)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Rafeli <[email protected]>
Co-authored-by: Kevin Silva <[email protected]>
Co-authored-by: renovate-pagopa[bot] <164534245+renovate-pagopa[bot]@users.noreply.github.com>
Co-authored-by: empassaro <[email protected]>
  • Loading branch information
5 people authored Jun 6, 2024
1 parent d6f0e83 commit f956d78
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 1,669 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/pr_ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ on:
workflow_dispatch:

pull_request:
branches:
- main
- releases/**
types:
- opened
- edited
- synchronize
- reopened
- ready_for_review
paths:
- '.github/workflows/pr_ms.yml'
- '.github/workflows/release_ms.yml'
- '.github/workflows/release_ms_pnpg.yml'
- '!.devops/**'
- '!helm/**'
- '!**.md'
- '!**ignore'
- '!infra/**'
- '!.terraform-version'
- '!CODEOWNERS'

jobs:

Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/release_ms.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
name: Release ms-external-interceptor

on:
push:
branches:
- main
- releases/*
paths:
- 'app/**'
- 'connector/**'
- 'connector-api/**'
- 'core/**'
- 'infra/**'
- 'web/**'
- 'pom.xml'

workflow_dispatch:
inputs:
env:
Expand All @@ -11,19 +24,6 @@ on:
- uat
- prod

push:
branches:
- main
- releases/*
paths:
- '!.devops/**'
- '!helm/**'
- '!**.md'
- '!**ignore'
- '!infra/repository/**'
- '!.terraform-version'
- '!CODEOWNERS'

jobs:

release_dev:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.new
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM maven:3-eclipse-temurin-17 AS builder
FROM maven:3-eclipse-temurin-17@sha256:0d328fa6843bb26b60cf44d69833f241ffe96218fb29fa19df7a6603863eaae7 AS builder

COPY . .

RUN mvn clean package -DskipTests=true

FROM openjdk:17-jdk AS runtime
FROM openjdk:17-jdk@sha256:528707081fdb9562eb819128a9f85ae7fe000e2fbaeaf9f87662e7b3f38cb7d8 AS runtime

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import it.pagopa.selfcare.external_interceptor.core.InterceptorService;
import it.pagopa.selfcare.external_interceptor.core.SchedulerService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -42,9 +41,6 @@ class SwaggerConfigTest {
@MockBean
private InterceptorService interceptorService;

@MockBean
private SchedulerService schedulerService;

@Autowired
WebApplicationContext context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public class Billing {
private String vatNumber;
private String recipientCode;
private String taxCodeInvoicing;
private boolean publicService;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.pagopa.selfcare.external_interceptor.connector.model.institution;

import lombok.Data;

@Data
public class BillingToSend {
private String vatNumber;
private String recipientCode;
private boolean publicService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NotificationToSend {
private InstitutionToSend institution;
private String fileName;
private String contentType;
private Billing billing;
private BillingToSend billing;
private UserToSend user;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import java.util.UUID;


@Mapper(componentModel = "spring", imports = {UUID.class, RelationshipState.class})
@Mapper(componentModel = "spring", imports = {UUID.class, RelationshipState.class })
public interface NotificationMapper {

@Mapping(target = "id", expression = "java(UUID.randomUUID().toString())")
@Mapping(target = "user", source = "inbound.user", qualifiedByName = "toUserToSend")
@Mapping(target = "product", source = "productId")
@Mapping(target = "createdAt", expression = "java(inbound.getCreatedAt().atOffset(java.time.ZoneOffset.UTC))")
@Mapping(target = "updatedAt", expression = "java(inbound.getUpdatedAt().atOffset(java.time.ZoneOffset.UTC))")
NotificationToSend createUserNotification(UserNotification inbound);


Expand All @@ -34,6 +36,7 @@ public interface NotificationMapper {
NotificationToSend createInstitutionNotification(Notification inbound);



@Named("toUserToSend")
@Mapping(target = "roles", expression = "java(toUserRole(user.getProductRole()))")
UserToSend toUserToSend(UserNotify user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import it.pagopa.selfcare.external_interceptor.connector.model.interceptor.QueueEvent;
import lombok.Data;

import java.time.OffsetDateTime;
import java.time.LocalDateTime;

@Data
public class UserNotification {
private String id;
private String institutionId;
private String productId;
private String onboardingTokenId;
private OffsetDateTime createdAt;
private OffsetDateTime updatedAt;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private QueueEvent eventType;
private UserNotify user;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
public class UserProductDetails {
private String id;
private String institutionId;
private OnboardedUserProduct onboardedUserProductDetails;
private OnboardedUserProduct onboardedProductDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import it.pagopa.selfcare.commons.base.logging.LogUtils;
import it.pagopa.selfcare.external_interceptor.connector.kafka_manager.factory.KafkaSendService;
import it.pagopa.selfcare.external_interceptor.connector.kafka_manager.factory.KafkaSendStrategyFactory;
import it.pagopa.selfcare.external_interceptor.connector.kafka_manager.factory.SendSapNotification;
import it.pagopa.selfcare.external_interceptor.connector.model.constant.ProductId;
import it.pagopa.selfcare.external_interceptor.connector.model.institution.Notification;
import it.pagopa.selfcare.external_interceptor.connector.model.user.UserNotification;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;
Expand All @@ -24,42 +21,11 @@ public class KafkaInterceptor {
public static final String NOTIFICATION_CONVERSION_EXCEPTION = "Something went wrong while trying to convert the record";
private final ObjectMapper mapper;
private final KafkaSendStrategyFactory sendStrategyFactory;
private final SendSapNotification sapSendService;

public KafkaInterceptor(ObjectMapper mapper, KafkaSendStrategyFactory sendStrategyFactory, @Qualifier("sapNotificator") SendSapNotification sapSendService) {
public KafkaInterceptor(ObjectMapper mapper, KafkaSendStrategyFactory sendStrategyFactory) {
this.mapper = mapper;
this.mapper.registerModule(new JavaTimeModule());
this.sendStrategyFactory = sendStrategyFactory;
this.sapSendService = sapSendService;
}

@KafkaListener(topics = "${kafka-manager.external-interceptor.sc-contracts-read-topic}", containerFactory = "kafkaContractsListenerContainerFactoryGeneral")
public void interceptInstitutionGeneral(ConsumerRecord<String, String> inboundRecord, Acknowledgment acknowledgment) {
log.trace("KafkaInterceptor GENERAL intercept start");
log.debug(LogUtils.CONFIDENTIAL_MARKER, "KafKaInterceptor GENERAL incoming message = {}", inboundRecord);
try {
Notification notification = mapper.readValue(inboundRecord.value(), Notification.class);
KafkaSendService sendService = sendStrategyFactory.create(notification.getProduct());
if(sendService!= null)
sendService.sendInstitutionNotification(notification, acknowledgment);
} catch (JsonProcessingException e) {
log.warn(NOTIFICATION_CONVERSION_EXCEPTION, e);
}

log.trace("KafkaInterceptor GENERAL intercept end");
}

@KafkaListener(topics = "${kafka-manager.external-interceptor.sc-contracts-read-topic}", containerFactory = "kafkaContractsListenerContainerFactorySap")
public void interceptInstitutionSap(ConsumerRecord<String, String> inboundRecord, Acknowledgment acknowledgment) {
log.trace("KafkaInterceptor SAP intercept start");
log.debug(LogUtils.CONFIDENTIAL_MARKER, "KafKaInterceptor SAP incoming message = {}", inboundRecord);
try {
Notification notification = mapper.readValue(inboundRecord.value(), Notification.class);
sapSendService.sendInstitutionNotification(notification, acknowledgment);
} catch (JsonProcessingException e) {
log.warn(NOTIFICATION_CONVERSION_EXCEPTION, e);
}
log.trace("KafkaInterceptor SAP intercept end");
}

@KafkaListener(topics = "${kafka-manager.external-interceptor.sc-users-read-topic}", containerFactory = "kafkaUserListenerContainerFactory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
import org.springframework.kafka.support.Acknowledgment;

public interface KafkaSendService {

void sendInstitutionNotification(Notification notification, Acknowledgment acknowledgment) throws JsonProcessingException;
void sendUserNotification(UserNotification userNotification, Acknowledgment acknowledgment) throws JsonProcessingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ public SendFdNotification(@Value("#{${external-interceptor.producer-topics}}") M
}


@Override
public void sendInstitutionNotification(Notification notification, Acknowledgment acknowledgment) throws JsonProcessingException {
log.trace("sendInstitutionNotification start");
log.debug(LogUtils.CONFIDENTIAL_MARKER, "send institution notification = {}", notification);
if (validateProductTopic(notification.getProduct())) {
NotificationToSend notificationToSend = notificationMapper.createInstitutionNotification(notification);
notificationToSend.setType(NotificationType.ADD_INSTITUTE);
String institutionNotification = mapper.writeValueAsString(notificationToSend);
String topic = producerAllowedTopics.get().get(notification.getProduct());
String logSuccess = String.format("sent notification for token : %s, to FD", notification.getOnboardingTokenId());
String logFailure = String.format("error during notification sending for token: %s, on FD ", notification.getOnboardingTokenId());
sendNotification(institutionNotification, topic, logSuccess, logFailure, Optional.of(acknowledgment));
}
log.trace("sendInstitutionNotification end");
}

@Override
public void sendUserNotification(UserNotification userNotification, Acknowledgment acknowledgment) throws JsonProcessingException {
log.trace("sendUserNotification start");
Expand All @@ -70,7 +54,7 @@ public void sendUserNotification(UserNotification userNotification, Acknowledgme
&& (userNotification.getProductId().equals(PROD_FD.getValue())
|| userNotification.getProductId().equals(PROD_FD_GARANTITO.getValue()))) {
UserProductDetails userProduct = externalApiConnector.getUserOnboardedProductDetails(userNotification.getUser().getUserId(), userNotification.getInstitutionId(), userNotification.getProductId());
if(userProduct.getOnboardedUserProductDetails() != null) {
if(userProduct.getOnboardedProductDetails() != null) {
sendUpdateUserEvents(notificationToSend, userProduct);
acknowledgment.acknowledge();
}
Expand All @@ -92,9 +76,9 @@ private void sendUpdateUserEvents(NotificationToSend notification, UserProductDe
List<NotificationType> eventTypes = List.of(NotificationType.DELETE_USER, NotificationType.ACTIVE_USER);
UserToSend userToSend = new UserToSend();
userToSend.setUserId(userProductDetails.getId());
userToSend.setRole(userProductDetails.getOnboardedUserProductDetails().getRole());
userToSend.setRoles(userProductDetails.getOnboardedUserProductDetails().getRoles());
notification.setCreatedAt(userProductDetails.getOnboardedUserProductDetails().getCreatedAt());
userToSend.setRole(userProductDetails.getOnboardedProductDetails().getRole());
userToSend.setRoles(userProductDetails.getOnboardedProductDetails().getRoles());
notification.setCreatedAt(userProductDetails.getOnboardedProductDetails().getCreatedAt());
eventTypes.forEach(type -> {
notification.setType(type);
notification.setUser(userToSend);
Expand Down
Loading

0 comments on commit f956d78

Please sign in to comment.