Skip to content

Commit

Permalink
[MODCONSKC-18] - Implement sharing of authorization policies (#74)
Browse files Browse the repository at this point in the history
* [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
azizbekxm authored Aug 6, 2024
1 parent bf4a2b7 commit 797e81d
Show file tree
Hide file tree
Showing 26 changed files with 1,364 additions and 325 deletions.
34 changes: 33 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@
"consortia.sharing-settings.item.delete"
],
"modulePermissions": []
},
{
"methods": [
"POST"
],
"pathPattern": "/consortia/{consortiumId}/sharing/policies",
"permissionsRequired": [
"consortia.sharing-policies.item.post"
],
"modulePermissions": []
},
{
"methods": [
"DELETE"
],
"pathPattern": "/consortia/{consortiumId}/sharing/policies/{policyId}",
"permissionsRequired": [
"consortia.sharing-policies.item.delete"
],
"modulePermissions": []
}
]
},
Expand Down Expand Up @@ -411,7 +431,9 @@
"consortia.publications.item.delete",
"consortia.publications-results.item.get",
"consortia.sharing-settings.item.post",
"consortia.sharing-settings.item.delete"
"consortia.sharing-settings.item.delete",
"consortia.sharing-policies.item.post",
"consortia.sharing-policies.item.delete"
]
},
{
Expand Down Expand Up @@ -540,6 +562,16 @@
"permissionName": "consortia.sharing-settings.item.delete",
"displayName": "delete sharing setting",
"description": "Delete sharing setting"
},
{
"permissionName": "consortia.sharing-policies.item.post",
"displayName": "post sharing policy",
"description": "Create sharing policy"
},
{
"permissionName": "consortia.sharing-policies.item.delete",
"displayName": "delete sharing policy",
"description": "Delete sharing policy"
}
],
"metadata": {
Expand Down
42 changes: 32 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@
<self.yaml.file>${project.basedir}/src/main/resources/swagger.api/self.yaml</self.yaml.file>
<tenants.yaml.file>${project.basedir}/src/main/resources/swagger.api/tenants.yaml</tenants.yaml.file>
<user_tenants.yaml.file>${project.basedir}/src/main/resources/swagger.api/user_tenants.yaml</user_tenants.yaml.file>
<user_events.yaml.file>${project.basedir}/src/main/resources/swagger.api/kafka_message_schemas.yaml
</user_events.yaml.file>
<consortia_configuration.yaml.file>${project.basedir}/src/main/resources/swagger.api/consortia_configuration.yaml
</consortia_configuration.yaml.file>
<publish_coordinator.yaml.file>${project.basedir}/src/main/resources/swagger.api/publications.yaml
</publish_coordinator.yaml.file>
<sharing_instances.yaml.file>${project.basedir}/src/main/resources/swagger.api/sharing_instances.yaml
</sharing_instances.yaml.file>
<sharing_settings.yaml.file>${project.basedir}/src/main/resources/swagger.api/sharing_settings.yaml
</sharing_settings.yaml.file>
<user_events.yaml.file>${project.basedir}/src/main/resources/swagger.api/kafka_message_schemas.yaml</user_events.yaml.file>
<consortia_configuration.yaml.file>${project.basedir}/src/main/resources/swagger.api/consortia_configuration.yaml</consortia_configuration.yaml.file>
<publish_coordinator.yaml.file>${project.basedir}/src/main/resources/swagger.api/publications.yaml</publish_coordinator.yaml.file>
<sharing_instances.yaml.file>${project.basedir}/src/main/resources/swagger.api/sharing_instances.yaml</sharing_instances.yaml.file>
<sharing_settings.yaml.file>${project.basedir}/src/main/resources/swagger.api/sharing_settings.yaml</sharing_settings.yaml.file>
<sharing_policies.yaml.file>${project.basedir}/src/main/resources/swagger.api/sharing_policies.yaml</sharing_policies.yaml.file>

<!-- runtime dependencies -->
<folio-spring-base.version>8.1.2</folio-spring-base.version>
Expand Down Expand Up @@ -537,6 +533,32 @@
</configOptions>
</configuration>
</execution>
<execution>
<id>sharing policies</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${sharing_policies.yaml.file}</inputSpec>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<modelPackage>${project.groupId}.consortia.domain.dto</modelPackage>
<apiPackage>${project.groupId}.consortia.rest.resource</apiPackage>
<generateApis>true</generateApis>
<generateApiTests>true</generateApiTests>
<generateApiDocumentation>true</generateApiDocumentation>
<generateModels>true</generateModels>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<generateModelDocumentation>true</generateModelDocumentation>
<configOptions>
<dateLibrary>java</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
<execution>
<id>publish_coordinator</id>
<goals>
Expand Down
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));
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.folio.consortia.controller;

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

import org.folio.consortia.service.SharingSettingService;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.folio.consortia.domain.dto.SharingSettingDeleteResponse;
import org.folio.consortia.domain.dto.SharingSettingRequest;
import org.folio.consortia.domain.dto.SharingSettingResponse;
import org.folio.consortia.rest.resource.SettingsApi;
import org.folio.consortia.service.impl.SharingSettingService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -22,12 +23,16 @@ public class SharingSettingController implements SettingsApi {

@Override
public ResponseEntity<SharingSettingResponse> startSharingSetting(UUID consortiumId, SharingSettingRequest sharingSettingRequest) {
return ResponseEntity.status(CREATED).body(sharingSettingService.start(consortiumId, sharingSettingRequest));
return ResponseEntity
.status(CREATED)
.body(sharingSettingService.start(consortiumId, sharingSettingRequest));
}

@Override
public ResponseEntity<SharingSettingDeleteResponse> deleteSharingSetting(UUID consortiumId, UUID settingId,
SharingSettingRequest sharingSettingRequest) {
return ResponseEntity.ok(sharingSettingService.delete(consortiumId, settingId, sharingSettingRequest));
return ResponseEntity
.status(OK)
.body(sharingSettingService.delete(consortiumId, settingId, sharingSettingRequest));
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/folio/consortia/domain/dto/SourceValues.java
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;
}
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);
}
}
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);
}
Loading

0 comments on commit 797e81d

Please sign in to comment.