Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release to SIT #1152

Merged
merged 12 commits into from
Apr 26, 2023
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
@@ -0,0 +1,10 @@
package uk.gov.crowncommercial.dts.scale.cat.exception;

public class SSOObjectMissingException extends RuntimeException {

private static final long serialVersionUID = 1L;

public SSOObjectMissingException(final String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.crowncommercial.dts.scale.cat.config.UserRegistrationNotificationConfig;
import uk.gov.crowncommercial.dts.scale.cat.exception.LoginDirectorEdgeCaseException;
import uk.gov.crowncommercial.dts.scale.cat.exception.ResourceNotFoundException;
import uk.gov.crowncommercial.dts.scale.cat.exception.SSOObjectMissingException;
import uk.gov.crowncommercial.dts.scale.cat.exception.UserRolesConflictException;
import uk.gov.crowncommercial.dts.scale.cat.model.SchemeType;
import uk.gov.crowncommercial.dts.scale.cat.model.SupplierLink;
Expand Down Expand Up @@ -200,7 +201,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 +222,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 +244,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 +258,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 +293,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 +306,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 @@ -333,17 +334,21 @@ private void updateBuyer(final UserProfileResponseInfo conclaveUser,
final UserContactInfoList conclaveUserContacts,
final CreateUpdateCompanyRequestBuilder createUpdateCompanyDataBuilder,
final Optional<SubUser> jaggaerBuyer, final RegisterUserResponse registerUserResponse) {
if(jaggaerBuyer.isPresent() && !ssoCodeDataExists(jaggaerBuyer.get().getSsoCodeData()))
{
throw new SSOObjectMissingException("SSO Object is not present for the User"+ jaggaerBuyer.get().getEmail());
}else {
createUpdateSubUserHelper(createUpdateCompanyDataBuilder, conclaveUser, conclaveUserOrg,
conclaveUserContacts, jaggaerBuyer, jaggaerAPIConfig.getSelfServiceId(),
jaggaerAPIConfig.getDefaultBuyerRightsProfile());

createUpdateSubUserHelper(createUpdateCompanyDataBuilder, conclaveUser, conclaveUserOrg,
conclaveUserContacts, jaggaerBuyer, jaggaerAPIConfig.getSelfServiceId(),
jaggaerAPIConfig.getDefaultBuyerRightsProfile());

log.debug("Updating buyer user: [{}]", conclaveUser.getUserName());
jaggaerService.createUpdateCompany(createUpdateCompanyDataBuilder.build());
userProfileService.refreshBuyerCache(conclaveUser.getUserName());
log.debug("Updating buyer user: [{}]", conclaveUser.getUserName());
jaggaerService.createUpdateCompany(createUpdateCompanyDataBuilder.build());
userProfileService.refreshBuyerCache(conclaveUser.getUserName());

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

private void updateSupplier(final UserProfileResponseInfo conclaveUser,
Expand All @@ -370,21 +375,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 +411,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 +488,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 +587,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