Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Release production (#452)
Browse files Browse the repository at this point in the history
* chore: fix pnpg suffix private_dns_name

* fix: Adding api for count users for each product

* fix: [SELC-4536] fix deleteDelegations query findByToAndStatus (#449)

* chore: deployment k8s replica 0 uat

* fix: Adding api for count users for each product

* fix: Adding return value api

* fix: Adding return value api

* chore: create release pipeline and promote release

* chore: fix STORAGE_CREDENTIAL_ID value

---------

Co-authored-by: manuraf <[email protected]>
Co-authored-by: Giulia Tremolada <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent ceaae9a commit cc5a7d1
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 36 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/create_release_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Create Release branch

on:
workflow_dispatch:
inputs:
version-bump:
required: false
type: choice
options:
- major
- minor
- patch
default: patch
description: 'Major, Minor, or Patch version bump'

jobs:
create_branch:
name: 'Create Release Branch'
runs-on: ubuntu-20.04
permissions:
contents: write
actions: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:

- name: Create Release Branch
id: create_branch
uses: pagopa/selfcare-commons/github-actions-template/create-release@main
with:
version_bump: ${{ inputs.version-bump }}
github_path_token: ${{ secrets.GH_PAT_VARIABLES }}

- name: Trigger release ms UAT Release
run: |
gh workflow run release_ms.yml \
--ref ${{ steps.create_branch.outputs.new_branch_name }}
- name: Trigger PNPG release ms UAT Release
run: |
gh workflow run release_ms_pnpg.yml \
--ref ${{ steps.create_branch.outputs.new_branch_name }}
12 changes: 11 additions & 1 deletion .github/workflows/release_ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ jobs:
with:
environment: prod
tf_environment: prod
dir: 'infra/container_apps'
dir: 'infra/container_apps'

promote_release:
name: 'Promote prerelase release'
runs-on: ubuntu-20.04
needs: [release_prod]
steps:
- uses: pagopa/selfcare-commons/github-actions-template/promote-release@main
with:
github_path_token: ${{ secrets.GH_PAT_VARIABLES }}
release_version: ${{ vars.CURRENT_UAT_VERSION }}
68 changes: 68 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,49 @@
} ]
}
},
"/notification-event/users/count" : {
"get" : {
"tags" : [ "kafka" ],
"summary" : "countUsers",
"description" : "Users' Count for single product",
"operationId" : "countUsersUsingGET",
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"$ref" : "#/components/schemas/ProductCountResponse"
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/tokens" : {
"get" : {
"tags" : [ "Token" ],
Expand Down Expand Up @@ -7164,6 +7207,31 @@
}
}
},
"ProductCount" : {
"title" : "ProductCount",
"type" : "object",
"properties" : {
"count" : {
"type" : "integer",
"format" : "int32"
},
"productId" : {
"type" : "string"
}
}
},
"ProductCountResponse" : {
"title" : "ProductCountResponse",
"type" : "object",
"properties" : {
"products" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ProductCount"
}
}
}
},
"ProductInfo" : {
"title" : "ProductInfo",
"type" : "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.mscore.constant.RelationshipState;
import it.pagopa.selfcare.mscore.model.aggregation.QueryCount;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter;
import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct;
Expand Down Expand Up @@ -63,6 +64,7 @@ public interface UserConnector {

List<UserInfo> findByInstitutionId(String institutionId);

List<UserInstitutionAggregation> getUserInfo(String userId, String institutionId, String[] states);
List<UserInstitutionAggregation> getUserInfo(String userId, String institutionId, String[] states);

List<QueryCount> countUsers();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.pagopa.selfcare.mscore.model.aggregation;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

@Data
@FieldNameConstants(asEnum = true)
@AllArgsConstructor
@NoArgsConstructor
public class QueryCount {
private String _id;
private Integer count;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.pagopa.selfcare.mscore.connector.dao;

import com.mongodb.client.model.Facet;
import it.pagopa.selfcare.mscore.api.DelegationConnector;
import it.pagopa.selfcare.mscore.connector.dao.model.DelegationEntity;
import it.pagopa.selfcare.mscore.connector.dao.model.mapper.DelegationEntityMapper;
Expand All @@ -21,10 +20,7 @@
import org.springframework.stereotype.Component;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -122,7 +118,7 @@ public Delegation findByIdAndModifyStatus(String delegationId, DelegationState s

@Override
public boolean checkIfDelegationsAreActive(String institutionId) {
Optional<DelegationEntity> opt = repository.findByToAndStatus(institutionId, DelegationState.ACTIVE);
return opt.isPresent();
List<DelegationEntity> opt = repository.findByToAndStatus(institutionId, DelegationState.ACTIVE).orElse(Collections.emptyList());
return !opt.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface DelegationRepository extends MongoRepository<DelegationEntity, String>, MongoCustomConnector {

Optional<DelegationEntity> findByFromAndToAndProductIdAndType(String from, String to, String productId, DelegationType type);

Optional<DelegationEntity> findByToAndStatus(String to, DelegationState status);
Optional<List<DelegationEntity>> findByToAndStatus(String to, DelegationState status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import it.pagopa.selfcare.mscore.constant.RelationshipState;
import it.pagopa.selfcare.mscore.exception.InvalidRequestException;
import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException;
import it.pagopa.selfcare.mscore.model.aggregation.QueryCount;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter;
import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct;
Expand All @@ -28,10 +29,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.GraphLookupOperation;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.UnwindOperation;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
Expand All @@ -45,6 +43,7 @@
import java.util.stream.Collectors;

import static it.pagopa.selfcare.mscore.constant.CustomError.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.group;

@Slf4j
@Component
Expand Down Expand Up @@ -436,4 +435,14 @@ private String constructQuery(String... variables) {
Arrays.stream(variables).forEach(s -> builder.append(".").append(s));
return builder.toString();
}

@Override
public List<QueryCount> countUsers() {
UnwindOperation unwindBindings = Aggregation.unwind("$bindings", "binding", true);
UnwindOperation unwindProducts = Aggregation.unwind("$bindings.products", "products", true);
MatchOperation matchStatusId = Aggregation.match(Criteria.where("bindings.products.status").in(VALID_USER_RELATIONSHIPS));
GroupOperation productCount = group("bindings.products.productId").count().as("count");
Aggregation aggregation = Aggregation.newAggregation(unwindBindings, unwindProducts, matchStatusId, productCount);
return mongoOperations.aggregate(aggregation, "User", QueryCount.class).getMappedResults();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.test.context.ContextConfiguration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -218,12 +218,19 @@ void findByIdAndModifyStatus() {
}

@Test
void checkIfDelegationsAreActive() {
when(delegationRepository.findByToAndStatus(anyString(), any())).thenReturn(Optional.of(new DelegationEntity()));
void checkIfDelegationsAreActive_true() {
when(delegationRepository.findByToAndStatus(anyString(), any())).thenReturn(Optional.of(List.of(new DelegationEntity())));
boolean response = delegationConnectorImpl.checkIfDelegationsAreActive("id");
assertTrue(response);
}

@Test
void checkIfDelegationsAreActive_false() {
when(delegationRepository.findByToAndStatus(anyString(), any())).thenReturn(Optional.of(Collections.emptyList()));
boolean response = delegationConnectorImpl.checkIfDelegationsAreActive("id");
assertFalse(response);
}


@Test
void find_shouldGetDataPaginated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import it.pagopa.selfcare.mscore.constant.Env;
import it.pagopa.selfcare.mscore.constant.RelationshipState;
import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException;
import it.pagopa.selfcare.mscore.model.aggregation.QueryCount;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionBinding;
import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter;
Expand Down Expand Up @@ -1159,4 +1160,30 @@ void findUsersByInstitutionIdAndProductId(){
List<String> userIds = userConnectorImpl.findUsersByInstitutionIdAndProductId("institutionId", "productId");
assertEquals(1, userIds.size());
}


@Test
void countUser() {
//Given
AggregationResults<Object> results = mock(AggregationResults.class);

when(results.getMappedResults()).thenReturn(List.of(
new QueryCount("prod1", 1),
new QueryCount("prod2", 2),
new QueryCount("prod3", 3)));

//When
when(mongoTemplate.aggregate(any(Aggregation.class), anyString(), any())).
thenReturn(results);

List<QueryCount> response = userConnectorImpl.countUsers();

//Then
assertNotNull(response);
assertFalse(response.isEmpty());
QueryCount actual = response.get(0);

assertEquals(actual.getCount(), 1);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.mscore.core;

import it.pagopa.selfcare.mscore.model.aggregation.QueryCount;
import org.springframework.scheduling.annotation.Async;

import java.util.List;
Expand All @@ -13,4 +14,6 @@ public interface QueueNotificationService {
void sendContracts(Optional<Integer> size, List<String> productsFilter);

void sendUsers(Optional<Integer> size, Optional<Integer> page, List<String> productsFilter, Optional<String> userId);

List<QueryCount> countUsers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.pagopa.selfcare.mscore.constant.RelationshipState;
import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException;
import it.pagopa.selfcare.mscore.model.QueueEvent;
import it.pagopa.selfcare.mscore.model.aggregation.QueryCount;
import it.pagopa.selfcare.mscore.model.institution.Institution;
import it.pagopa.selfcare.mscore.model.institution.Onboarding;
import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser;
Expand All @@ -19,7 +20,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@Slf4j
Expand Down Expand Up @@ -184,4 +184,9 @@ public void sendUsers(Optional<Integer> size, Optional<Integer> page, List<Strin
this.page=page;
regenerateUserNotifications(userId);
}

@Override
public List<QueryCount> countUsers() {
return userConnector.countUsers();
}
}
Loading

0 comments on commit cc5a7d1

Please sign in to comment.