Skip to content

Commit

Permalink
[SELC-6441] feat: getUserCount
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetano-miglionico committed Feb 7, 2025
1 parent 4aa2c2e commit f48534e
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 12 deletions.
135 changes: 135 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,108 @@
} ]
}
},
"/v2/institutions/{institutionId}/products/{productId}/users/count" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getUserCount",
"description" : "Service to get the number of users related to a specific pair of institution-product optionally filtered by role and status",
"operationId" : "v2GetUserCount",
"parameters" : [ {
"name" : "institutionId",
"in" : "path",
"description" : "Institution's unique internal identifier",
"required" : true,
"style" : "simple",
"schema" : {
"type" : "string"
}
}, {
"name" : "productId",
"in" : "path",
"description" : "Product's unique identifier",
"required" : true,
"style" : "simple",
"schema" : {
"type" : "string"
}
}, {
"name" : "roles",
"in" : "query",
"description" : "List of party roles (ex: roles=MANAGER,DELEGATE)",
"required" : false,
"style" : "form",
"explode" : true,
"schema" : {
"type" : "string"
}
}, {
"name" : "status",
"in" : "query",
"description" : "User's status list (ex: status=ACTIVE,SUSPENDED)",
"required" : false,
"style" : "form",
"explode" : true,
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/UserCountResource"
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/v2/institutions/{institutionId}/products/{productId}/users/{userId}" : {
"put" : {
"tags" : [ "institutions" ],
Expand Down Expand Up @@ -4321,6 +4423,39 @@
}
}
},
"UserCountResource" : {
"title" : "UserCountResource",
"type" : "object",
"properties" : {
"count" : {
"type" : "integer",
"description" : "Number of users",
"format" : "int64"
},
"institutionId" : {
"type" : "string",
"description" : "Institution's unique internal identifier"
},
"productId" : {
"type" : "string",
"description" : "Product's unique identifier"
},
"roles" : {
"type" : "array",
"description" : "Party role, available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA",
"items" : {
"type" : "string"
}
},
"status" : {
"type" : "array",
"description" : "User's status",
"items" : {
"type" : "string"
}
}
}
},
"UserGroupIdResource" : {
"title" : "UserGroupIdResource",
"required" : [ "id" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public interface UserApiConnector {

UserInstitutionWithActionsDto getUserInstitutionWithActions(String userId, String institutionId, String productId);

UserCount getUserCount(String institutionId, String productId, List<String> roles, List<String> status);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.selfcare.dashboard.connector.model.user;

import lombok.Data;

import java.util.List;

@Data
public class UserCount {

private String institutionId;
private String productId;
private List<String> roles;
private List<String> status;
private Long count;

}
93 changes: 93 additions & 0 deletions connector/rest/docs/openapi/selfcare-user-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,68 @@
} ]
}
},
"/institutions/{institutionId}/products/{productId}/users/count" : {
"get" : {
"tags" : [ "Institution" ],
"summary" : "Get the number of users for a certain product of an institution with a certain role and status",
"description" : "Count the number of users associated with a specific product of an institution, with an optional filter by roles and status. If no filter is specified count users with any role in status ACTIVE",
"operationId" : "getUsersCount",
"parameters" : [ {
"name" : "institutionId",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"name" : "productId",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"name" : "roles",
"in" : "query",
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}, {
"name" : "status",
"in" : "query",
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/UsersCountResponse"
}
}
}
},
"401" : {
"description" : "Not Authorized"
},
"403" : {
"description" : "Not Allowed"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
},
"/institutions/{institutionId}/user-institutions" : {
"get" : {
"tags" : [ "Institution" ],
Expand Down Expand Up @@ -1517,6 +1579,10 @@
}
}
},
"PartyRole" : {
"enum" : [ "MANAGER", "DELEGATE", "SUB_DELEGATE", "OPERATOR", "ADMIN_EA" ],
"type" : "string"
},
"PermissionTypeEnum" : {
"enum" : [ "ADMIN", "ANY" ],
"type" : "string"
Expand Down Expand Up @@ -1942,6 +2008,33 @@
}
}
},
"UsersCountResponse" : {
"type" : "object",
"properties" : {
"institutionId" : {
"type" : "string"
},
"productId" : {
"type" : "string"
},
"roles" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PartyRole"
}
},
"status" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/OnboardedProductState"
}
},
"count" : {
"format" : "int64",
"type" : "integer"
}
}
},
"UsersNotificationResponse" : {
"type" : "object",
"properties" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public UserInstitutionWithActionsDto getUserInstitutionWithActions(String userId
return userMapper.toUserInstitutionWithActionsDto(userInstitutionWithActions);
}

@Override
@Retry(name = "retryTimeout")
public UserCount getUserCount(String institutionId, String productId, List<String> roles, List<String> status) {
log.trace("getUserCount start");
UsersCountResponse usersCountResponse = userInstitutionApiRestClient._getUsersCount(institutionId, productId, roles, status)
.getBody();
return userMapper.toUserCount(usersCountResponse);
}

@Override
@Retry(name = "retryTimeout")
public UserInstitution getProducts(String institutionId, String userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ default CertifiedField<String> toCertifiedField(CertifiableFieldResponseString f
@Mapping(target = "products", expression = "java(toProductInfoMap(userDashboardResponse.getProducts()))")
UserInfo toUserInfo(UserDataResponse userDashboardResponse);

UserCount toUserCount(UsersCountResponse usersCountResponse);

UserInstitutionWithActionsDto toUserInstitutionWithActionsDto(UserInstitutionWithActions userInstitutionWithActions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,38 @@ void getUserByUserIdInstitutionIdAndProductAndStates_throwsResourceNotFoundExcep
statusFilter);
}

@Test
void getUserCount() {
final String institutionId = "institutionId";
final String productId = "productId";
final List<String> roles = List.of("MANAGER", "DELEGATE");
final List<String> status = List.of("ACTIVE", "SUSPENDED");

final UsersCountResponse userCountResponse = new UsersCountResponse();
userCountResponse.setInstitutionId(institutionId);
userCountResponse.setProductId(productId);
userCountResponse.setRoles(List.of(
it.pagopa.selfcare.user.generated.openapi.v1.dto.PartyRole.MANAGER,
it.pagopa.selfcare.user.generated.openapi.v1.dto.PartyRole.DELEGATE
));
userCountResponse.setStatus(List.of(
OnboardedProductState.ACTIVE,
OnboardedProductState.SUSPENDED)
);
userCountResponse.setCount(2L);
when(userInstitutionApiRestClient._getUsersCount(institutionId, productId, roles, status))
.thenReturn(ResponseEntity.ok(userCountResponse));

final UserCount userCount = userConnector.getUserCount(institutionId, productId, roles, status);
assertEquals(institutionId, userCount.getInstitutionId());
assertEquals(productId, userCount.getProductId());
assertIterableEquals(roles, userCount.getRoles());
assertIterableEquals(status, userCount.getStatus());
assertEquals(2L, userCount.getCount());

verify(userInstitutionApiRestClient, times(1))
._getUsersCount(institutionId, productId, roles, status);
verifyNoMoreInteractions(userInstitutionApiRestClient);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package it.pagopa.selfcare.dashboard.core;

import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionBase;
import it.pagopa.selfcare.dashboard.connector.model.user.UpdateUserRequestDto;
import it.pagopa.selfcare.dashboard.connector.model.user.User;
import it.pagopa.selfcare.dashboard.connector.model.user.UserInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.UserToCreate;
import it.pagopa.selfcare.dashboard.connector.model.user.*;

import java.util.Collection;
import java.util.List;
Expand All @@ -31,4 +28,7 @@ public interface UserV2Service {
String createUsers(String institutionId, String productId, UserToCreate userToCreate);

void addUserProductRoles(String institutionId, String productId, String userId, Set<String> productRoles, String role);

UserCount getUserCount(String institutionId, String productId, List<String> roles, List<String> status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ public void addUserProductRoles(String institutionId, String productId, String u
log.trace("createOrUpdateUserByUserId end");
}

@Override
public UserCount getUserCount(String institutionId, String productId, List<String> roles, List<String> status) {
log.trace("getUserCount start");
UserCount userCount = userApiConnector.getUserCount(institutionId, productId, roles, status);
log.trace("getUserCount end");
return userCount;
}

private Institution verifyOnboardingStatus(String institutionId, String productId) {
Institution institution = msCoreConnector.getInstitution(institutionId);
if (institution.getOnboarding() == null || institution.getOnboarding().stream()
Expand Down
Loading

0 comments on commit f48534e

Please sign in to comment.