Skip to content

Commit

Permalink
Merge pull request #1136 from Crown-Commercial-Service/bugfix/CAS-107…
Browse files Browse the repository at this point in the history
…3_Issue_with_user_update

Added the fix Back
  • Loading branch information
ravi-sankar-uppala committed Apr 19, 2023
2 parents a6aa9f5 + bd87389 commit 19afb75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ResponseEntity<RegisterUserResponse> registerUser(
}
var registerUserResponse = profileManagementService.registerUser(userId);
if (registerUserResponse.getUserAction() == UserActionEnum.EXISTED) {
throw new JaggaerUserExistException("Jaggaer sub or super user already exists");
return ResponseEntity.status(HttpStatus.OK).body(registerUserResponse);
} else {
return ResponseEntity.status(HttpStatus.CREATED).body(registerUserResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public RegisterUserResponse registerUser(final String userId) {
} else if (conclaveRoles.contains(SUPPLIER) && jaggaerRoles.isEmpty()) {

var primaryOrgId = conclaveService.getOrganisationIdentifer(conclaveUserOrg);

// Validate DUNS-Number
if (!conclaveUserOrg.getIdentifier().getScheme().equalsIgnoreCase("US-DUN")) {
var validDunsNumber = conclaveUserOrg.getAdditionalIdentifiers().stream()
Expand All @@ -221,7 +221,7 @@ public RegisterUserResponse registerUser(final String userId) {
orgMapping =
retryableTendersDBDelegate.findOrganisationMappingByCasOrganisationId(primaryOrgId);
}

// Now searched by Supplier mapping table CAS-665
if (orgMapping.isEmpty()) {
try {
Expand All @@ -243,7 +243,7 @@ public RegisterUserResponse registerUser(final String userId) {

if (orgMapping.isPresent()) {
var jaggaerSupplierOrgId = orgMapping.get().getExternalOrganisationId();

// CON-1682-AC10: Create Jaggaer Supplier sub-user
createUpdateSupplierSubUser(String.valueOf(jaggaerSupplierOrgId), createUpdateCompanyDataBuilder,
conclaveUser, conclaveUserOrg, conclaveUserContacts, userId, registerUserResponse);
Expand All @@ -257,13 +257,13 @@ public RegisterUserResponse registerUser(final String userId) {
createUpdateSupplierSubUser(superUser.get().getReturnCompanyInfo().getBravoId(),
createUpdateCompanyDataBuilder, conclaveUser, conclaveUserOrg, conclaveUserContacts,
userId, registerUserResponse);

retryableTendersDBDelegate.save(OrganisationMapping.builder()
.organisationId(primaryOrgId)
.externalOrganisationId(
Integer.parseInt(superUser.get().getReturnCompanyInfo().getBravoId()))
.createdAt(Instant.now()).createdBy(conclaveUser.getUserName()).build());

} else {
// CON-1682-AC9: Supplier is first user in company - create as super-user
createUpdateSuperUserHelper(createUpdateCompanyDataBuilder, conclaveUser, conclaveUserOrg,
Expand Down Expand Up @@ -292,7 +292,7 @@ public RegisterUserResponse registerUser(final String userId) {
registerUserResponse.roles(returnRoles);
return registerUserResponse;
}

private void createUpdateSupplierSubUser(final String jaggaerSupplierOrgId,
final CreateUpdateCompanyRequestBuilder createUpdateCompanyDataBuilder,
final UserProfileResponseInfo conclaveUser, OrganisationProfileResponseInfo conclaveUserOrg,
Expand All @@ -305,7 +305,7 @@ private void createUpdateSupplierSubUser(final String jaggaerSupplierOrgId,
jaggaerAPIConfig.getDefaultSupplierRightsProfile());
log.debug("Creating supplier sub-user: [{}]", userId);
jaggaerService.createUpdateCompany(createUpdateCompanyDataBuilder.build());

registerUserResponse.userAction(UserActionEnum.CREATED);
registerUserResponse.organisationAction(OrganisationActionEnum.EXISTED);
}
Expand Down Expand Up @@ -370,21 +370,18 @@ private void updateSupplier(final UserProfileResponseInfo conclaveUser,
&& Objects.equals(conclaveUser.getUserName(), subUser.getSsoCodeData().getSsoCode()
.stream().findFirst().orElseThrow().getSsoUserLogin()))
.findFirst();

// CON-1682-AC16: Update supplier sub-user
createUpdateSubUserHelper(createUpdateCompanyDataBuilder, conclaveUser, conclaveUserOrg,
conclaveUserContacts, jaggaerSupplierSubUser,
jaggaerSupplierData.getReturnCompanyInfo().getBravoId(),
jaggaerAPIConfig.getDefaultSupplierRightsProfile());

log.debug("Updating supplier sub-user: [{}]", conclaveUser.getUserName());
jaggaerService.createUpdateCompany(createUpdateCompanyDataBuilder.build());

}
registerUserResponse.userAction(UserActionEnum.EXISTED);
registerUserResponse.organisationAction(OrganisationActionEnum.EXISTED);
}

private void createUpdateSubUserHelper(
final CreateUpdateCompanyRequestBuilder createUpdateCompanyRequestBuilder,
final UserProfileResponseInfo conclaveUser,
Expand All @@ -409,7 +406,7 @@ private void createUpdateSubUserHelper(
subUserBuilder.division("Division");
subUserBuilder.ssoCodeData(buildSSOCodeData(conclaveUser.getUserName()));
}

var conclaveRoles = new HashSet<RolesEnum>();
populateConclaveRoles(conclaveRoles, conclaveUser);
var isBuyer = conclaveRoles.contains(RolesEnum.BUYER);
Expand Down Expand Up @@ -486,7 +483,7 @@ private void populateConclaveRoles(final Set<RolesEnum> conclaveRoles,
conclaveUser.getDetail().getRolePermissionInfo().stream().map(RolePermissionInfo::getRoleKey)
.filter(conclaveBuyerSupplierRoleKeys::containsKey)
.forEach(rk -> conclaveRoles.add(conclaveBuyerSupplierRoleKeys.get(rk)));

//CAS-1048
if (Objects.nonNull(conclaveUser.getDetail().getUserGroups()))
conclaveUser.getDetail().getUserGroups().stream().map(GroupAccessRole::getAccessRole)
Expand Down Expand Up @@ -585,7 +582,7 @@ private void sendUserRegistrationNotification(final UserProfileResponseInfo conc
notificationService.sendEmail(userRegistrationNotificationConfig.getTemplateId(),
userRegistrationNotificationConfig.getTargetEmail(), placeholders, "");
}

private void sendSupplierRegistrationInvalidDunsNotification(
final OrganisationProfileResponseInfo conclaveUserOrg) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ void putUser_500_InternalServerError() throws Exception {
mockMvc
.perform(put("/tenders/users/{user-id}", PRINCIPAL).with(validLDJwtReqPostProcessor)
.accept(APPLICATION_JSON))
.andDo(print()).andExpect(status().isInternalServerError())
.andDo(print()).andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(APPLICATION_JSON))
.andExpect(jsonPath("$.errors", hasSize(1)))
.andExpect(jsonPath("$.errors[0].status", is("500 INTERNAL_SERVER_ERROR")))
.andExpect(jsonPath("$.errors[0].title", is("Jaggaer User Exist Scenario")))
.andExpect(jsonPath("$.errors[0].detail", is("Jaggaer sub or super user already exists")));
.andExpect(jsonPath("$.roles", hasSize(1)))
.andExpect(jsonPath("$.userAction", is("existed")));
}

@Test
Expand Down

0 comments on commit 19afb75

Please sign in to comment.