Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public record UserProfile(
UUID securityAnalysisParameterId,
UUID sensitivityAnalysisParameterId,
UUID shortcircuitParameterId,
UUID pccMinParameterId,
UUID voltageInitParameterId,
Boolean allLinksValid,
Integer maxAllowedCases,
Expand All @@ -35,6 +36,7 @@ public static UserProfile createDefaultProfile(Integer maxAllowedCases, Integer
null,
null,
null,
null,
maxAllowedCases,
maxAllowedBuilds,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class UserProfileEntity {
@Column(name = "shortcircuitParameterId")
private UUID shortcircuitParameterId;

@Column(name = "pccMinParameterId")
private UUID pccminParameterId;

@Column(name = "voltageInitParameterId")
private UUID voltageInitParameterId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<UserProfile> getProfiles(String userId, boolean checkLinksValidity)
e.getSecurityAnalysisParameterId(),
e.getSensitivityAnalysisParameterId(),
e.getShortcircuitParameterId(),
e.getPccminParameterId(),
e.getVoltageInitParameterId(),
e.getSpreadsheetConfigCollectionId(),
e.getNetworkVisualizationParameterId(),
Expand All @@ -88,6 +89,9 @@ public List<UserProfile> getProfiles(String userId, boolean checkLinksValidity)
if (BooleanUtils.toBooleanDefaultIfNull(allLinksValid, true) && p.getShortcircuitParameterId() != null) {
allLinksValid = !missingUuids.contains(p.getShortcircuitParameterId());
}
if (BooleanUtils.toBooleanDefaultIfNull(allLinksValid, true) && p.getPccminParameterId() != null) {
allLinksValid = !missingUuids.contains(p.getPccminParameterId());
}
if (BooleanUtils.toBooleanDefaultIfNull(allLinksValid, true) && p.getVoltageInitParameterId() != null) {
allLinksValid = !missingUuids.contains(p.getVoltageInitParameterId());
}
Expand Down Expand Up @@ -121,6 +125,7 @@ public void updateProfile(UUID profileUuid, UserProfile userProfile) {
profile.setSecurityAnalysisParameterId(userProfile.securityAnalysisParameterId());
profile.setSensitivityAnalysisParameterId(userProfile.sensitivityAnalysisParameterId());
profile.setShortcircuitParameterId(userProfile.shortcircuitParameterId());
profile.setPccminParameterId(userProfile.pccMinParameterId());
profile.setVoltageInitParameterId(userProfile.voltageInitParameterId());
profile.setMaxAllowedCases(userProfile.maxAllowedCases());
profile.setMaxAllowedBuilds(userProfile.maxAllowedBuilds());
Expand Down Expand Up @@ -159,7 +164,7 @@ private UserProfile toDto(final UserProfileEntity entity, Boolean allLinksValid)
}
return new UserProfile(entity.getId(), entity.getName(), entity.getLoadFlowParameterId(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those constructors using more than 10 parameters are cumbersome and a bit dangerous. I am surprised that sonar didn't complain about it. Wouldn't it be nicer to add @Builder to UserProfile and use a builder ?

entity.getSecurityAnalysisParameterId(), entity.getSensitivityAnalysisParameterId(),
entity.getShortcircuitParameterId(), entity.getVoltageInitParameterId(),
entity.getShortcircuitParameterId(), entity.getPccminParameterId(), entity.getVoltageInitParameterId(),
allLinksValid, entity.getMaxAllowedCases(), entity.getMaxAllowedBuilds(), entity.getSpreadsheetConfigCollectionId(),
entity.getNetworkVisualizationParameterId(), entity.getWorkspaceId());
}
Expand All @@ -173,6 +178,7 @@ private UserProfileEntity toEntity(final UserProfile userProfile) {
userProfile.securityAnalysisParameterId(),
userProfile.sensitivityAnalysisParameterId(),
userProfile.shortcircuitParameterId(),
userProfile.pccMinParameterId(),
userProfile.voltageInitParameterId(),
Optional.ofNullable(userProfile.maxAllowedCases()).orElse(applicationProps.getDefaultMaxAllowedCases()),
Optional.ofNullable(userProfile.maxAllowedBuilds()).orElse(applicationProps.getDefaultMaxAllowedBuilds()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="souissimai (generated)" id="1769092083222-7">
<addColumn tableName="user_profile">
<column name="pcc_min_parameter_id" type="uuid"/>
</addColumn>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ databaseChangeLog:
- include:
file: changesets/changelog_20251031T110224Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20260122T142750Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20260122T160112Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void testConversionToDtoOfUserInfos() {
.isEqualTo(new UserInfos("sub_user", null, null, null, null, null, null, null));

// with profile but without group
UserProfileEntity profile = new UserProfileEntity(UUID.randomUUID(), "a profile", null, null, null, null, null, 5, 6, null, null, null);
UserProfileEntity profile = new UserProfileEntity(UUID.randomUUID(), "a profile", null, null, null, null, null, null, 5, 6, null, null, null);
// Test mapping without quota
assertThat(UserInfosEntity.toDto(new UserInfosEntity(uuid, "sub_user", profile, null)))
.as("dto result")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void testUserCreationWithProfile() throws Exception {
}

private void createProfile(String profileName, Integer maxAllowedCases, Integer maxAllowedBuilds) throws Exception {
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, false, maxAllowedCases, maxAllowedBuilds, null, null, null);
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, null, false, maxAllowedCases, maxAllowedBuilds, null, null, null);
performPost(API_BASE_PATH + "/profiles", profileInfo);

Optional<UserProfileEntity> createdProfile = userProfileRepository.findByName(profileName);
Expand All @@ -119,6 +119,7 @@ private void createProfile(String profileName, Integer maxAllowedCases, Integer
assertNull(createdProfile.get().getSecurityAnalysisParameterId());
assertNull(createdProfile.get().getSensitivityAnalysisParameterId());
assertNull(createdProfile.get().getShortcircuitParameterId());
assertNull(createdProfile.get().getPccminParameterId());
assertNull(createdProfile.get().getVoltageInitParameterId());
assertEquals(maxAllowedCases, createdProfile.get().getMaxAllowedCases());
assertEquals(maxAllowedBuilds, createdProfile.get().getMaxAllowedBuilds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ void testGetUserProfileNotFound() throws Exception {
assertNull(profile.securityAnalysisParameterId());
assertNull(profile.sensitivityAnalysisParameterId());
assertNull(profile.shortcircuitParameterId());
assertNull(profile.pccMinParameterId());
assertNull(profile.voltageInitParameterId());
assertNull(profile.allLinksValid());
assertNull(profile.spreadsheetConfigCollectionId());
Expand Down Expand Up @@ -367,7 +368,7 @@ private void createUser(String userName) throws Exception {

private void createProfile(String profileName) throws Exception {
ObjectWriter objectWriter = objectMapper.writer().withDefaultPrettyPrinter();
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, false, null, null, null, null, null);
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, null, false, null, null, null, null, null);
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/profiles")
.content(objectWriter.writeValueAsString(profileInfo))
.contentType(MediaType.APPLICATION_JSON)
Expand Down
28 changes: 17 additions & 11 deletions src/test/java/org/gridsuite/useradmin/server/UserProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void testCreateProfile() throws Exception {
assertNull(userProfiles.get(0).securityAnalysisParameterId());
assertNull(userProfiles.get(0).sensitivityAnalysisParameterId());
assertNull(userProfiles.get(0).shortcircuitParameterId());
assertNull(userProfiles.getFirst().pccMinParameterId());
assertNull(userProfiles.get(0).voltageInitParameterId());
assertNull(userProfiles.get(0).allLinksValid());
assertEquals(10, userProfiles.get(0).maxAllowedCases());
Expand Down Expand Up @@ -154,15 +155,15 @@ void testDeleteProfileNotFound() throws Exception {

@Test
void testProfileUpdateNotFound() throws Exception {
updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null, null, null, null, null, null, null, null),
updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null, null, null, null, null, null, null, null, null),
ADMIN_USER,
USER_ADMIN_ROLE,
HttpStatus.NOT_FOUND);
}

@Test
void testProfileUpdateForbidden() throws Exception {
updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null, null, null, null, null, null, null, null),
updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null, null, null, null, null, null, null, null, null),
NOT_ADMIN,
"USER",
HttpStatus.FORBIDDEN);
Expand All @@ -180,7 +181,7 @@ void testProfileUpdateValidityKo() throws Exception {

@Test
void testGetProfileMaxAllowedCases() throws Exception {
UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, null, null, null, null, 15, null, null, null, null);
UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, null, null, null, null, null, 15, null, null, null, null);
UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, userProfileEntity, null);
userProfileRepository.save(userProfileEntity);
userInfosRepository.save(userInfosEntity);
Expand All @@ -196,7 +197,7 @@ void testGetProfileMaxAllowedCases() throws Exception {

@Test
void testGetProfileMaxAllowedBuilds() throws Exception {
UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, null, null, null, null, null, 15, null, null, null);
UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, null, null, null, null, null, null, 15, null, null, null);
UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, userProfileEntity, null);
userProfileRepository.save(userProfileEntity);
userInfosRepository.save(userInfosEntity);
Expand Down Expand Up @@ -245,12 +246,13 @@ private void updateProfile(boolean validParameters) throws Exception {
UUID securityAnalysisParametersUuid = UUID.fromString("22222222-9594-4e55-8ec7-07ea965d24eb");
UUID sensitivityAnalysisParametersUuid = UUID.fromString("33333333-9594-4e55-8ec7-07ea965d24eb");
UUID shortcircuitParametersUuid = UUID.fromString("44444444-9594-4e55-8ec7-07ea965d24eb");
UUID voltageInitParametersUuid = UUID.fromString("55555555-9594-4e55-8ec7-07ea965d24eb");
UUID spreadsheetConfigCollectionUuid = UUID.fromString("66666666-9594-4e55-8ec7-07ea965d24eb");
UUID networkVisualizationParametersUuid = UUID.fromString("77777777-9594-4e55-8ec7-07ea965d24eb");
UUID diagramConfigUuid = UUID.fromString("88888888-9594-4e55-8ec7-07ea965d24eb");
UUID pccminParametersUuid = UUID.fromString("55555555-9594-4e55-8ec7-07ea965d24eb");
UUID voltageInitParametersUuid = UUID.fromString("66666666-9594-4e55-8ec7-07ea965d24eb");
UUID spreadsheetConfigCollectionUuid = UUID.fromString("77777777-9594-4e55-8ec7-07ea965d24eb");
UUID networkVisualizationParametersUuid = UUID.fromString("88888888-9594-4e55-8ec7-07ea965d24eb");
UUID diagramConfigUuid = UUID.fromString("9999999-9594-4e55-8ec7-07ea965d24eb");
List<UUID> elementsUuids = List.of(loadFlowParametersUuid, securityAnalysisParametersUuid,
sensitivityAnalysisParametersUuid, shortcircuitParametersUuid, voltageInitParametersUuid, spreadsheetConfigCollectionUuid, networkVisualizationParametersUuid, diagramConfigUuid);
sensitivityAnalysisParametersUuid, shortcircuitParametersUuid, pccminParametersUuid, voltageInitParametersUuid, spreadsheetConfigCollectionUuid, networkVisualizationParametersUuid, diagramConfigUuid);

// stub for parameters and spreadsheet config collection elements existence check
final String urlPath = "/v1/elements";
Expand All @@ -259,6 +261,7 @@ private void updateProfile(boolean validParameters) throws Exception {
new ElementAttributes(securityAnalysisParametersUuid, "securityAnalysisParams", "SECURITY_ANALYSIS_PARAMETERS"),
new ElementAttributes(sensitivityAnalysisParametersUuid, "sensitivityAnalysisParams", "SENSITIVITY_PARAMETERS"),
new ElementAttributes(shortcircuitParametersUuid, "shortcircuitParams", "SHORT_CIRCUIT_PARAMETERS"),
new ElementAttributes(pccminParametersUuid, "pccminParams", "PCC_MIN_PARAMETERS"),
new ElementAttributes(voltageInitParametersUuid, "voltageInitParams", "VOLTAGE_INIT_PARAMETERS"),
new ElementAttributes(spreadsheetConfigCollectionUuid, "spreadsheetConfigCollection", "SPREADSHEET_CONFIG_COLLECTION"),
new ElementAttributes(networkVisualizationParametersUuid, "networkVisualizationParams", "NETWORK_VISUALIZATION_PARAMETERS"),
Expand All @@ -273,7 +276,7 @@ private void updateProfile(boolean validParameters) throws Exception {

// udpate the profile: change name and set its parameters, maxAllowedCases, maxAllowedBuilds and spreadsheet config collection
UserProfile userProfile = new UserProfile(profileUuid, PROFILE_2, loadFlowParametersUuid, securityAnalysisParametersUuid,
sensitivityAnalysisParametersUuid, shortcircuitParametersUuid, voltageInitParametersUuid, null, 10, 11, spreadsheetConfigCollectionUuid, networkVisualizationParametersUuid, diagramConfigUuid);
sensitivityAnalysisParametersUuid, shortcircuitParametersUuid, pccminParametersUuid, voltageInitParametersUuid, null, 10, 11, spreadsheetConfigCollectionUuid, networkVisualizationParametersUuid, diagramConfigUuid);
updateProfile(userProfile, ADMIN_USER, USER_ADMIN_ROLE, HttpStatus.OK);

// profiles list (with validity flag)
Expand All @@ -284,6 +287,7 @@ private void updateProfile(boolean validParameters) throws Exception {
assertEquals(securityAnalysisParametersUuid, userProfiles.get(0).securityAnalysisParameterId());
assertEquals(sensitivityAnalysisParametersUuid, userProfiles.get(0).sensitivityAnalysisParameterId());
assertEquals(shortcircuitParametersUuid, userProfiles.get(0).shortcircuitParameterId());
assertEquals(pccminParametersUuid, userProfiles.get(0).pccMinParameterId());
assertEquals(voltageInitParametersUuid, userProfiles.get(0).voltageInitParameterId());
assertEquals(validParameters, userProfiles.get(0).allLinksValid());
assertEquals(10, userProfiles.get(0).maxAllowedCases());
Expand All @@ -302,7 +306,7 @@ private static Map<String, StringValuePattern> handleQueryParams(List<UUID> para
}

private UUID createProfile(String profileName, String userName, String userRole, Integer maxAllowedCases, Integer maxAllowedBuilds, HttpStatusCode status) throws Exception {
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, false, maxAllowedCases, maxAllowedBuilds, null, null, null);
UserProfile profileInfo = new UserProfile(null, profileName, null, null, null, null, null, null, false, maxAllowedCases, maxAllowedBuilds, null, null, null);
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/profiles")
.content(objectWriter.writeValueAsString(profileInfo))
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -327,6 +331,7 @@ private UUID createProfile(String profileName, String userName, String userRole,
assertNull(profile1.get().getSecurityAnalysisParameterId()); // no security analysis params by dft
assertNull(profile1.get().getSensitivityAnalysisParameterId()); // no sensitivity analysis params by dft
assertNull(profile1.get().getShortcircuitParameterId()); // no shortcircuit params by dft
assertNull(profile1.get().getPccminParameterId()); // no pccmin params by dft
assertNull(profile1.get().getVoltageInitParameterId()); // no voltage init params by dft
assertNull(profile1.get().getSpreadsheetConfigCollectionId()); // no spreadsheet config collection by dft
assertNull(profile1.get().getNetworkVisualizationParameterId()); // no network visualization params by dft
Expand Down Expand Up @@ -381,6 +386,7 @@ private void updateProfile(UserProfile newData, String userName, String userRole
assertEquals(newData.securityAnalysisParameterId(), updatedProfile.securityAnalysisParameterId());
assertEquals(newData.sensitivityAnalysisParameterId(), updatedProfile.sensitivityAnalysisParameterId());
assertEquals(newData.shortcircuitParameterId(), updatedProfile.shortcircuitParameterId());
assertEquals(newData.pccMinParameterId(), updatedProfile.pccMinParameterId());
assertEquals(newData.voltageInitParameterId(), updatedProfile.voltageInitParameterId());
assertEquals(newData.maxAllowedCases(), updatedProfile.maxAllowedCases());
assertNull(updatedProfile.allLinksValid()); // validity not set in this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void cleanDB() {
@Test
void getUserDetail() throws Exception {
// Create a profile
UserProfileEntity profileEntity = new UserProfileEntity(UUID.randomUUID(), PROFILE_A, null, null, null, null, null, 10, 20, null, null, null);
UserProfileEntity profileEntity = new UserProfileEntity(UUID.randomUUID(), PROFILE_A, null, null, null, null, null, null, 10, 20, null, null, null);
userProfileRepository.save(profileEntity);
// Create a user
UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), USER_A, profileEntity, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void toDtoUserInfoTest() {
// get number of cases used mock
when(directoryServiceMock.getCasesCount("user_A")).thenReturn(3);
// create user and profile
UserProfileEntity profile = new UserProfileEntity(UUID.randomUUID(), "profile_A", null, null, null, null, null, 5, 6, null, null, null);
UserProfileEntity profile = new UserProfileEntity(UUID.randomUUID(), "profile_A", null, null, null, null, null, null, 5, 6, null, null, null);
UserInfosEntity user = new UserInfosEntity(UUID.randomUUID(), "user_A", profile, null);

when(userInfosRepositoryMock.findBySub("user_A")).thenReturn(Optional.of(user));
Expand Down