-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from folio-org/MODTLR-24
[MODTLR-24] Create a new endpoint tlr/settings (GET, PUT methods) to manage ECS TLR settings
- Loading branch information
Showing
18 changed files
with
522 additions
and
24 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
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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/folio/controller/TlrSettingsController.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,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
24
src/main/java/org/folio/domain/entity/TlrSettingsEntity.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,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
16
src/main/java/org/folio/domain/mapper/TlrSettingsMapper.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,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
9
src/main/java/org/folio/repository/TlrSettingsRepository.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,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> { | ||
} |
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,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); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/org/folio/service/impl/TlrSettingsServiceImpl.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,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()))))); | ||
} | ||
} |
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
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,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 |
Oops, something went wrong.