Skip to content

Commit

Permalink
Merge pull request #21 from folio-org/MODTLR-24
Browse files Browse the repository at this point in the history
[MODTLR-24] Create a new endpoint tlr/settings (GET, PUT methods) to manage ECS TLR settings
  • Loading branch information
roman-barannyk authored Mar 25, 2024
2 parents c42306a + 2bba05c commit 23ffb41
Show file tree
Hide file tree
Showing 18 changed files with 522 additions and 24 deletions.
58 changes: 58 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
}
]
},
{
"id": "tlr-settings",
"version": "1.0",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/tlr/settings",
"permissionsRequired": ["tlr.settings.get"],
"modulePermissions": []
},
{
"methods": ["PUT"],
"pathPattern": "/tlr/settings",
"permissionsRequired": ["tlr.settings.put"],
"modulePermissions": []
}
]
},
{
"id": "_tenant",
"version": "2.0",
Expand Down Expand Up @@ -95,6 +113,46 @@
"permissionName": "tlr.ecs-tlr.delete",
"displayName": "ecs-tlr - remove ECS TLR",
"description": "Remove ECS TLR"
},
{
"permissionName": "tlr.settings.get",
"displayName": "tlr-settings - get ECS TLR Settings",
"description": "Get ECS TLR Settings"
},
{
"permissionName": "tlr.settings.put",
"displayName": "tlr-settings - update ECS TLR Settings",
"description": "Update ECS TLR"
},
{
"permissionName": "tlr.consortium-tlr.view",
"displayName": "Settings (Circulation): Consortium title level requests view",
"description": "Entire set of permissions needed to use Consortium title level requests settings view",
"subPermissions": [
"tlr.settings.get",
"settings.circulation.enabled",
"mod-settings.global.read.circulation",
"mod-settings.entries.collection.get",
"mod-settings.entries.item.get"
],
"visible": false
},
{
"permissionName": "tlr.consortium-tlr.edit",
"displayName": "Settings (Circulation): Consortium title level requests edit",
"description": "Entire set of permissions needed to use Consortium title level requests settings edit",
"subPermissions": [
"tlr.settings.get",
"tlr.settings.put",
"settings.circulation.enabled",
"mod-settings.global.read.circulation",
"mod-settings.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.global.write.circulation",
"mod-settings.entries.item.put",
"mod-settings.entries.item.post"
],
"visible": true
}
],
"requires": [
Expand Down
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,34 @@
<dateLibrary>java</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
<execution>
<id>tlr-settings</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.api/tlr-settings.yaml</inputSpec>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<modelPackage>${project.groupId}.domain.dto</modelPackage>
<apiPackage>${project.groupId}.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>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/folio/controller/EcsTlrController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import java.util.UUID;

import org.folio.domain.dto.EcsTlr;
import org.folio.rest.resource.TlrApi;
import org.folio.rest.resource.EcsTlrApi;
import org.folio.service.EcsTlrService;
import org.folio.service.TlrSettingsService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -20,9 +21,10 @@
@RestController
@Log4j2
@AllArgsConstructor
public class EcsTlrController implements TlrApi {
public class EcsTlrController implements EcsTlrApi {

private final EcsTlrService ecsTlrService;
private final TlrSettingsService tlrSettingsService;

@Override
public ResponseEntity<EcsTlr> getEcsTlrById(UUID requestId) {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/folio/controller/TlrSettingsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.folio.controller;

import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;

import org.folio.domain.dto.TlrSettings;
import org.folio.rest.resource.TlrSettingsApi;
import org.folio.service.TlrSettingsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;

@RestController
@Log4j2
@AllArgsConstructor
public class TlrSettingsController implements TlrSettingsApi {

private final TlrSettingsService tlrSettingsService;

@Override
public ResponseEntity<TlrSettings> getTlrSettings() {
log.debug("getTlrSettings:: ");

return tlrSettingsService.getTlrSettings()
.map(ResponseEntity.status(OK)::body)
.orElseGet(() -> ResponseEntity.notFound().build());
}

@Override
public ResponseEntity<Void> putTlrSettings(TlrSettings tlrSettings) {
log.debug("putTlrSettings:: parameters: {}", () -> tlrSettings);

return ResponseEntity.status(
tlrSettingsService.updateTlrSettings(tlrSettings)
.map(entity -> NO_CONTENT)
.orElse(NOT_FOUND))
.build();
}
}
24 changes: 24 additions & 0 deletions src/main/java/org/folio/domain/entity/TlrSettingsEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.folio.domain.entity;

import java.util.UUID;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "tlr_settings")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TlrSettingsEntity {

@Id
private UUID id;
private boolean ecsTlrFeatureEnabled;
}
16 changes: 16 additions & 0 deletions src/main/java/org/folio/domain/mapper/TlrSettingsMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.folio.domain.mapper;

import org.folio.domain.dto.TlrSettings;
import org.folio.domain.entity.TlrSettingsEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;

@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface TlrSettingsMapper {

@Mapping(target = "id", ignore = true)
TlrSettings mapEntityToDto(TlrSettingsEntity tlrSettingsEntity);

TlrSettingsEntity mapDtoToEntity(TlrSettings tlrSettings);
}
9 changes: 9 additions & 0 deletions src/main/java/org/folio/repository/TlrSettingsRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.folio.repository;

import java.util.UUID;

import org.folio.domain.entity.TlrSettingsEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TlrSettingsRepository extends JpaRepository<TlrSettingsEntity, UUID> {
}
10 changes: 10 additions & 0 deletions src/main/java/org/folio/service/TlrSettingsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.folio.service;

import java.util.Optional;

import org.folio.domain.dto.TlrSettings;

public interface TlrSettingsService {
Optional<TlrSettings> getTlrSettings();
Optional<TlrSettings> updateTlrSettings(TlrSettings tlrSettings);
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,4 @@ private void handleSecondaryRequestUpdate(EcsTlrEntity ecsTlr, UUID itemId) {
ecsTlrRepository.save(ecsTlr);
log.info("handleSecondaryRequestUpdate: ECS TLR {} is updated", ecsTlrId);
}

}
44 changes: 44 additions & 0 deletions src/main/java/org/folio/service/impl/TlrSettingsServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.folio.service.impl;

import java.util.Optional;

import org.folio.domain.dto.TlrSettings;
import org.folio.domain.mapper.TlrSettingsMapper;
import org.folio.repository.TlrSettingsRepository;
import org.folio.service.TlrSettingsService;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class TlrSettingsServiceImpl implements TlrSettingsService {

private final TlrSettingsRepository tlrSettingsRepository;
private final TlrSettingsMapper tlrSettingsMapper;

@Override
public Optional<TlrSettings> getTlrSettings() {
log.debug("getTlrSettings:: ");

return tlrSettingsRepository.findAll(PageRequest.of(0, 1))
.stream()
.findFirst()
.map(tlrSettingsMapper::mapEntityToDto);
}

@Override
public Optional<TlrSettings> updateTlrSettings(TlrSettings tlrSettings) {
log.debug("updateTlrSettings:: parameters: {} ", () -> tlrSettings);

return tlrSettingsRepository.findAll(PageRequest.of(0, 1))
.stream()
.findFirst()
.map(entity -> tlrSettingsMapper.mapEntityToDto(
tlrSettingsRepository.save(tlrSettingsMapper.mapDtoToEntity(
tlrSettings.id(entity.getId().toString())))));
}
}
12 changes: 12 additions & 0 deletions src/main/resources/db/changelog/changes/initial_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@
<column name="updated_date" type="timestamp without time zone"/>
</createTable>
</changeSet>
<changeSet id="insertDefaultTlrSettings" author="RomanBarannyk">
<createTable tableName="tlr_settings">
<column name="id" type="uuid">
<constraints primaryKey="true"/>
</column>
<column name="ecs_tlr_feature_enabled" type="boolean"/>
</createTable>
<insert tableName="tlr_settings">
<column name="id" value="b937cf15-da8b-4480-aa87-4bc32f17219b"/>
<column name="ecs_tlr_feature_enabled" valueBoolean="true"/>
</insert>
</changeSet>
</databaseChangeLog>
10 changes: 10 additions & 0 deletions src/main/resources/swagger.api/ecs-tlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ openapi: 3.0.0
info:
title: ECS TLR API
version: v1
tags:
- name: ecsTlr
paths:
/tlr/ecs-tlr:
post:
description: Create ECS TLR
operationId: postEcsTlr
tags:
- ecsTlr
requestBody:
content:
application/json:
Expand All @@ -24,6 +28,8 @@ paths:
get:
description: Retrieve ECS TLR by ID
operationId: getEcsTlrById
tags:
- ecsTlr
parameters:
- $ref: '#/components/parameters/requestId'
responses:
Expand All @@ -38,6 +44,8 @@ paths:
put:
description: Update ECS TLR by ID
operationId: putEcsTlrById
tags:
- ecsTlr
requestBody:
content:
application/json:
Expand All @@ -58,6 +66,8 @@ paths:
delete:
description: Remove ECS TLR by ID
operationId: deleteEcsTlrById
tags:
- ecsTlr
parameters:
- $ref: '#/components/parameters/requestId'
responses:
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/swagger.api/schemas/TlrSettings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TlrSettings:
description: TLR Settings in a multi-tenant environment with Сonsortia support enabled
type: "object"
properties:
id:
description: "ID of the ECS TLR Settings"
$ref: "uuid.yaml"
ecsTlrFeatureEnabled:
description: "Indicates if TLR feature is enabled"
type: boolean
required:
- ecsTlrFeatureEnabled
Loading

0 comments on commit 23ffb41

Please sign in to comment.