-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODCONSKC-18] - Implement sharing of authorization policies (#74)
* [MODCONSKC-18] - Implement sharing of authorization policies * Fix tests * Fix tests * Added test for SharingPolicyService * Minor improvements * minor improvements * improved test cases * Used RetryMethod of build-in spring feature * fixed unit test * Minor code cleaning improvements
- Loading branch information
Showing
26 changed files
with
1,364 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/folio/consortia/controller/SharingPolicyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.folio.consortia.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.folio.consortia.domain.dto.SharingPolicyDeleteResponse; | ||
import org.folio.consortia.domain.dto.SharingPolicyRequest; | ||
import org.folio.consortia.domain.dto.SharingPolicyResponse; | ||
import org.folio.consortia.rest.resource.PoliciesApi; | ||
import org.folio.consortia.service.impl.SharingPolicyService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.springframework.http.HttpStatus.CREATED; | ||
import static org.springframework.http.HttpStatus.OK; | ||
|
||
@RestController | ||
@RequestMapping("/consortia/{consortiumId}/sharing") | ||
@RequiredArgsConstructor | ||
public class SharingPolicyController implements PoliciesApi { | ||
|
||
private final SharingPolicyService sharingPolicyService; | ||
|
||
@Override | ||
public ResponseEntity<SharingPolicyResponse> startSharingPolicy(UUID consortiumId, | ||
SharingPolicyRequest sharingPolicyRequest) { | ||
return ResponseEntity | ||
.status(CREATED) | ||
.body(sharingPolicyService.start(consortiumId, sharingPolicyRequest)); | ||
} | ||
|
||
@Override | ||
public ResponseEntity<SharingPolicyDeleteResponse> deleteSharingPolicy(UUID consortiumId, UUID policyId, | ||
SharingPolicyRequest sharingPolicyRequest) { | ||
return ResponseEntity | ||
.status(OK) | ||
.body(sharingPolicyService.delete(consortiumId, policyId, sharingPolicyRequest)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/folio/consortia/domain/dto/SourceValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.folio.consortia.domain.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SourceValues { | ||
CONSORTIUM_FOLIO_INSTANCE("CONSORTIUM-FOLIO"), | ||
CONSORTIUM_MARC_INSTANCE("CONSORTIUM-MARC"), | ||
CONSORTIUM("consortium"), | ||
USER("user"); | ||
|
||
private final String value; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/folio/consortia/domain/entity/SharingPolicyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.folio.consortia.domain.entity; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.folio.consortia.domain.entity.base.AuditableEntity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@RequiredArgsConstructor | ||
@Entity | ||
@Table(name = "sharing_policy") | ||
public class SharingPolicyEntity extends AuditableEntity { | ||
@Id | ||
private UUID id; | ||
private UUID policyId; | ||
private String tenantId; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (!(o instanceof SharingPolicyEntity that)) | ||
return false; | ||
return Objects.equals(id, that.id) | ||
&& Objects.equals(policyId, that.policyId) | ||
&& Objects.equals(tenantId, that.tenantId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, policyId, tenantId); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/folio/consortia/repository/SharingPolicyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.folio.consortia.repository; | ||
|
||
import org.folio.consortia.domain.entity.SharingPolicyEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface SharingPolicyRepository extends JpaRepository<SharingPolicyEntity, UUID> { | ||
|
||
@Query("SELECT sp.tenantId FROM SharingPolicyEntity sp WHERE sp.policyId = ?1") | ||
Set<String> findTenantsByPolicyId(UUID policyId); | ||
|
||
boolean existsByPolicyId(UUID policyId); | ||
|
||
@Modifying | ||
@Query("DELETE FROM SharingPolicyEntity sp WHERE sp.policyId = ?1") | ||
void deleteByPolicyId(UUID policyId); | ||
} |
Oops, something went wrong.