Skip to content

Commit

Permalink
MODCON-91. Add consortiumId to user tenant table (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNosko authored Sep 6, 2023
1 parent f81fc66 commit 308e623
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void createPrimaryUserAffiliations(UUID consortiumId, String centralTena
if (ObjectUtils.notEqual(centralTenantId, tenantEntity.getId())) {
userTenantService.save(consortiumId, createUserTenant(centralTenantId, user), true);
}
sendCreatePrimaryAffiliationEvent(tenantEntity, user, centralTenantId);
sendCreatePrimaryAffiliationEvent(tenantEntity, user, centralTenantId, consortiumId);
}
affiliatedUsersCount++;
} catch (Exception e) {
Expand All @@ -130,8 +130,8 @@ private void createPrimaryUserAffiliations(UUID consortiumId, String centralTena
}

@SneakyThrows
private void sendCreatePrimaryAffiliationEvent(TenantEntity consortiaTenant, SyncUser user, String centralTenantId) {
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(user, consortiaTenant.getId(), centralTenantId);
private void sendCreatePrimaryAffiliationEvent(TenantEntity consortiaTenant, SyncUser user, String centralTenantId, UUID consortiumId) {
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(user, consortiaTenant.getId(), centralTenantId, consortiumId);
String data = objectMapper.writeValueAsString(affiliationEvent);
kafkaService.send(KafkaService.Topic.CONSORTIUM_PRIMARY_AFFILIATION_CREATED, user.getId(), data);
}
Expand All @@ -144,7 +144,10 @@ private UserTenant createUserTenant(String tenantId, SyncUser user) {
return userTenant;
}

private PrimaryAffiliationEvent createPrimaryAffiliationEvent(SyncUser user, String tenantId, String centralTenantId) {
private PrimaryAffiliationEvent createPrimaryAffiliationEvent(SyncUser user,
String tenantId,
String centralTenantId,
UUID consortiumId) {
PrimaryAffiliationEvent event = new PrimaryAffiliationEvent();
event.setId(UUID.randomUUID());
event.setUserId(UUID.fromString(user.getId()));
Expand All @@ -156,6 +159,7 @@ private PrimaryAffiliationEvent createPrimaryAffiliationEvent(SyncUser user, Str
event.setBarcode(user.getBarcode());
event.setExternalSystemId(user.getExternalSystemId());
event.setCentralTenantId(centralTenantId);
event.setConsortiumId(consortiumId);
return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Tenant save(UUID consortiumId, UUID adminUserId, Tenant tenantDto) {
try (var context = new FolioExecutionContextSetter(contextHelper.getSystemUserFolioExecutionContext(tenantDto.getId(), systemUserHeaders))) {
configurationClient.saveConfiguration(createConsortiaConfigurationBody(centralTenantId));
if (!tenantDto.getIsCentral()) {
createUserTenantWithDummyUser(tenantDto.getId(), centralTenantId);
createUserTenantWithDummyUser(tenantDto.getId(), centralTenantId, consortiumId);
createShadowUserWithPermissions(shadowAdminUser, SHADOW_ADMIN_PERMISSION_FILE_PATH); //NOSONAR
log.info("save:: shadow admin user '{}' with permissions was created in tenant '{}'", shadowAdminUser.getId(), tenantDto.getId());
createShadowUserWithPermissions(shadowSystemUser, SHADOW_SYSTEM_USER_PERMISSION_FILE_PATH);
Expand Down Expand Up @@ -227,14 +227,16 @@ private Tenant updateTenant(UUID consortiumId, Tenant tenantDto) {
@param tenantId tenant id
@param centralTenantId central tenant id
@param consortiumId consortium id
*/
private void createUserTenantWithDummyUser(String tenantId, String centralTenantId) {
private void createUserTenantWithDummyUser(String tenantId, String centralTenantId, UUID consortiumId) {
UserTenant userTenant = new UserTenant();
userTenant.setId(UUID.randomUUID());
userTenant.setTenantId(tenantId);
userTenant.setUserId(UUID.randomUUID());
userTenant.setUsername(DUMMY_USERNAME);
userTenant.setCentralTenantId(centralTenantId);
userTenant.setConsortiumId(consortiumId);

log.info("Creating userTenant with dummy user with id {}.", userTenant.getId());
userTenantsClient.postUserTenant(userTenant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void createPrimaryUserAffiliation(String eventPayload) {
userTenantService.save(tenant.getConsortiumId(), createUserTenant(centralTenantId, userEvent), false);
}

PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId);
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId, tenant.getConsortiumId());
String data = objectMapper.writeValueAsString(affiliationEvent);

kafkaService.send(KafkaService.Topic.CONSORTIUM_PRIMARY_AFFILIATION_CREATED, userEvent.getUserDto().getId(), data);
Expand Down Expand Up @@ -97,7 +97,7 @@ public void updatePrimaryUserAffiliation(String eventPayload) {
if (Boolean.TRUE.equals(userEvent.getIsPersonalDataChanged())) {
userTenantService.updateShadowUsersFirstAndLastNames(getUserId(userEvent));
}
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId);
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId, null);
String data = objectMapper.writeValueAsString(affiliationEvent);

kafkaService.send(KafkaService.Topic.CONSORTIUM_PRIMARY_AFFILIATION_UPDATED, userEvent.getUserDto().getId(), data);
Expand Down Expand Up @@ -126,7 +126,7 @@ public void deletePrimaryUserAffiliation(String eventPayload) {

userTenantService.deleteShadowUsers(getUserId(userEvent));

PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId);
PrimaryAffiliationEvent affiliationEvent = createPrimaryAffiliationEvent(userEvent, centralTenantId, null);
String data = objectMapper.writeValueAsString(affiliationEvent);

kafkaService.send(KafkaService.Topic.CONSORTIUM_PRIMARY_AFFILIATION_DELETED, userEvent.getUserDto().getId(), data);
Expand Down Expand Up @@ -164,7 +164,7 @@ private UserTenant createUserTenant(String tenantId, UserEvent userEvent) {
return userTenant;
}

private PrimaryAffiliationEvent createPrimaryAffiliationEvent(UserEvent userEvent, String centralTenantId) {
private PrimaryAffiliationEvent createPrimaryAffiliationEvent(UserEvent userEvent, String centralTenantId, UUID consortiumId) {
PrimaryAffiliationEvent event = new PrimaryAffiliationEvent();
event.setId(userEvent.getId());
event.setUserId(UUID.fromString(userEvent.getUserDto().getId()));
Expand All @@ -185,6 +185,7 @@ private PrimaryAffiliationEvent createPrimaryAffiliationEvent(UserEvent userEven
}
event.setTenantId(userEvent.getTenantId());
event.setCentralTenantId(centralTenantId);
event.setConsortiumId(consortiumId);
return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ properties:
centralTenantId:
description: "The name of the user's central tenant"
type: string
consortiumId:
description: "The consortium uuid that user belongs to"
$ref: "uuid.yaml"
email:
description: "The user's email"
type: string
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/swagger.api/schemas/userTenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ UserTenant:
type: boolean
centralTenantId:
type: string
consortiumId:
type: string
format: uuid
email:
type: string
mobilePhoneNumber:
Expand Down

0 comments on commit 308e623

Please sign in to comment.