Skip to content

Commit

Permalink
Implement sharing of role capability sets
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Aug 22, 2024
1 parent e47387c commit 9eef669
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 189 deletions.
55 changes: 55 additions & 0 deletions docs/sharing-role-cabalities-capablity-set.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@startuml
title sd book room

actor Guest
participant Catalog
participant System
participant Booking
participant Room
participant Payment

activate Guest
Guest -> Catalog : searchRoom(price, style)
activate Catalog
Catalog --> Guest : return roomList
deactivate Catalog

Guest -> System : selectRoom()
activate System

alt roomStatus = available
System --> Guest : ready to book
Guest -> System : createBooking(room)
System -> Booking : create
activate Booking
Booking -> Room : getBookingPrice()
activate Room
Room --> Booking : return bookingPrice
deactivate Room
Booking --> Guest : ready for payment
deactivate Booking
Guest -> Payment : initiatePayment(bookingPrice)
activate Payment
Payment -> Payment : process payment

alt payment successful
Payment --> Guest : payment succeeded
Payment -> System : payment fulfilled
deactivate Payment
System -> Room : setRoomStatus(reserved)
activate Room
Room --> System : roomStatus updated
deactivate Room
else payment unsuccessful
Payment --> Guest : payment failed
deactivate Payment
end

else roomStatus = unavailable
System --> Guest : room unavailable
end

deactivate System
deactivate Guest

@enduml
13 changes: 13 additions & 0 deletions src/main/java/org/folio/consortia/client/CapabilitySetsClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.folio.consortia.client;

import org.folio.consortia.domain.dto.CapabilitySets;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "capability-sets")
public interface CapabilitySetsClient {

@GetMapping
CapabilitySets queryCapabilitySets(@RequestParam String query, @RequestParam Integer limit, @RequestParam Integer offset);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.folio.consortia.controller;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;

import java.util.UUID;

import lombok.RequiredArgsConstructor;
import org.folio.consortia.domain.dto.SharingRoleCapabilitySetDeleteResponse;
import org.folio.consortia.domain.dto.SharingRoleCapabilitySetRequest;
import org.folio.consortia.domain.dto.SharingRoleCapabilitySetResponse;
import org.folio.consortia.rest.resource.RolesApi;
import org.folio.consortia.service.impl.SharingRoleCapabilitySetService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/consortia/{consortiumId}/sharing")
@RequiredArgsConstructor
public class SharingRoleCapabilitySetController implements RolesApi {

private final SharingRoleCapabilitySetService sharingRoleCapabilitySetService;

@Override
public ResponseEntity<SharingRoleCapabilitySetResponse> startSharingRoleCapabilitySet(UUID consortiumId,
SharingRoleCapabilitySetRequest sharingRoleCapabilitySetRequest) {
return ResponseEntity
.status(CREATED)
.body(sharingRoleCapabilitySetService.start(consortiumId, sharingRoleCapabilitySetRequest));
}

@Override
public ResponseEntity<SharingRoleCapabilitySetDeleteResponse> deleteSharingRoleCapabilitySet(UUID consortiumId, UUID roleId,
SharingRoleCapabilitySetRequest sharingRoleCapabilitySetRequest) {
return ResponseEntity
.status(OK)
.body(sharingRoleCapabilitySetService.delete(consortiumId, roleId, sharingRoleCapabilitySetRequest));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.folio.consortia.domain.entity;

import java.util.List;
import java.util.UUID;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.folio.consortia.domain.entity.base.AuditableEntity;

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "sharing_role")
public class SharingRoleCapabilitySetEntity extends AuditableEntity {

@Id
private UUID id;
private UUID roleId;
private List<UUID> capabilitySetIds;
private String tenantId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.folio.consortia.repository;

import java.util.Set;
import java.util.UUID;

import org.folio.consortia.domain.entity.SharingRoleCapabilitySetEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface SharingRoleCapabilitySetRepository extends JpaRepository<SharingRoleCapabilitySetEntity, UUID> {

@Query("SELECT sr.tenantId FROM SharingRoleCapabilitySetEntity sr WHERE sr.roleId = ?1")
Set<String> findTenantsByRoleId(UUID roleId);

boolean existsByRoleId(UUID roleId);

@Modifying
@Query("DELETE FROM SharingRoleEntity sr WHERE sr.roleId = ?1")
void deleteByRoleId(UUID roleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class BaseSharingService<TRequest, TResponse, TDeleteResponse, T
private final ConsortiumService consortiumService;
private final SystemUserScopedExecutionService systemUserScopedExecutionService;
private final PublicationService publicationService;
private final FolioExecutionContext folioExecutionContext;
protected final FolioExecutionContext folioExecutionContext;
protected final ObjectMapper objectMapper;
private final TaskExecutor asyncTaskExecutor;

Expand Down Expand Up @@ -149,11 +149,11 @@ private void checkEqualsOfPayloadIdWithConfigId(TRequest sharingConfigRequest) {
* @param publicationPostRequest publication post request
* @return List of SharingConfigEntity objects
*/
private List<TEntity> linkTenantsToPublicationPutPostRequestAndEntity(TenantCollection allTenants,
TRequest sharingConfigRequest,
Set<String> sharingConfigTenants,
PublicationRequest publicationPutRequest,
PublicationRequest publicationPostRequest) {
protected List<TEntity> linkTenantsToPublicationPutPostRequestAndEntity(TenantCollection allTenants,
TRequest sharingConfigRequest,
Set<String> sharingConfigTenants,
PublicationRequest publicationPutRequest,
PublicationRequest publicationPostRequest) {
List<TEntity> sharingConfigEntityList = new ArrayList<>();
for (Tenant tenant : allTenants.getTenants()) {
if (sharingConfigTenants.contains(tenant.getId())) {
Expand All @@ -180,7 +180,7 @@ private List<TEntity> linkTenantsToPublicationPutPostRequestAndEntity(TenantColl
* @param sharingConfigTenants existing tenants in configs
* @param publicationDeleteRequest publication delete request
*/
private void linkTenantsToPublicationDeleteRequest(TenantCollection allTenants,
protected void linkTenantsToPublicationDeleteRequest(TenantCollection allTenants,
TRequest sharingConfigRequest,
Set<String> sharingConfigTenants,
PublicationRequest publicationDeleteRequest) {
Expand All @@ -195,7 +195,7 @@ private void linkTenantsToPublicationDeleteRequest(TenantCollection allTenants,
}


private UUID publishRequest(UUID consortiumId, PublicationRequest publicationRequest) {
protected UUID publishRequest(UUID consortiumId, PublicationRequest publicationRequest) {
if (CollectionUtils.isNotEmpty(publicationRequest.getTenants())) {
return publicationService.publishRequest(consortiumId, publicationRequest).getId();
}
Expand Down
Loading

0 comments on commit 9eef669

Please sign in to comment.