-
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.
Loading status checks…
feat(specification-storage): implement endpoints to fetch specificati…
…on rules and enable/disable it Closes: MRSPECS-4
Showing
44 changed files
with
2,074 additions
and
39 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
34 changes: 34 additions & 0 deletions
34
api/paths/specification-storage/get-specification-rules-by-id-path.yaml
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,34 @@ | ||
patch: | ||
summary: Toggle Specification Rule | ||
description: Enable or disable specification rule. | ||
operationId: toggleSpecificationRule | ||
tags: | ||
- specification-storage | ||
parameters: | ||
- in: path | ||
name: id | ||
description: Specification ID | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
- in: path | ||
name: ruleId | ||
description: Specification Rule ID | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../schemas/toggleSpecificationRuleDto.yaml' | ||
responses: | ||
'204': | ||
description: 'Operation was successful' | ||
'400': | ||
$ref: '../../responses/badRequestResponse.yaml' | ||
'500': | ||
$ref: '../../responses/internalServerErrorResponse.yaml' |
25 changes: 25 additions & 0 deletions
25
api/paths/specification-storage/get-specification-rules-path.yaml
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,25 @@ | ||
get: | ||
summary: Get Specification Rules | ||
description: Get a collection of specification rules enabled and disabled. | ||
operationId: getSpecificationRules | ||
tags: | ||
- specification-storage | ||
parameters: | ||
- in: path | ||
name: id | ||
description: Specification ID | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
responses: | ||
'200': | ||
description: Collection of specifications | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../schemas/specificationRuleDtoCollection.yaml' | ||
'400': | ||
$ref: '../../responses/badRequestResponse.yaml' | ||
'500': | ||
$ref: '../../responses/internalServerErrorResponse.yaml' |
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,18 @@ | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
format: uuid | ||
specificationId: | ||
type: string | ||
format: uuid | ||
name: | ||
type: string | ||
description: | ||
type: string | ||
code: | ||
type: string | ||
enabled: | ||
type: boolean | ||
metadata: | ||
$ref: 'common/metadataDto.yaml' |
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,8 @@ | ||
type: object | ||
properties: | ||
rules: | ||
type: array | ||
items: | ||
$ref: specificationRuleDto.yaml | ||
totalRecords: | ||
type: integer |
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,6 @@ | ||
type: object | ||
properties: | ||
enabled: | ||
type: boolean | ||
required: | ||
- enabled |
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
34 changes: 34 additions & 0 deletions
34
.../main/java/org/folio/rspec/controller/handler/MethodArgumentNotValidExceptionHandler.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,34 @@ | ||
package org.folio.rspec.controller.handler; | ||
|
||
import static org.folio.rspec.controller.handler.ServiceExceptionHandler.fromErrorCode; | ||
import static org.folio.rspec.domain.dto.ErrorCode.INVALID_REQUEST_PARAMETER; | ||
|
||
import org.folio.rspec.domain.dto.ErrorCollection; | ||
import org.folio.rspec.domain.dto.Parameter; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
|
||
@Component | ||
public class MethodArgumentNotValidExceptionHandler implements ServiceExceptionHandler { | ||
|
||
@Override | ||
public ResponseEntity<ErrorCollection> handleException(Exception e) { | ||
var exception = (MethodArgumentNotValidException) e; | ||
var errorCollection = new ErrorCollection(); | ||
for (FieldError fieldError : exception.getBindingResult().getFieldErrors()) { | ||
var error = fromErrorCode(INVALID_REQUEST_PARAMETER); | ||
error.setMessage(fieldError.getDefaultMessage()); | ||
var parameter = new Parameter().key(fieldError.getField()).value(String.valueOf(fieldError.getRejectedValue())); | ||
error.addParametersItem(parameter); | ||
errorCollection.addErrorsItem(error); | ||
} | ||
return ResponseEntity.badRequest().body(errorCollection); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(Exception e) { | ||
return e instanceof MethodArgumentNotValidException; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...er/src/main/java/org/folio/rspec/controller/handler/ResourceNotFoundExceptionHandler.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,26 @@ | ||
package org.folio.rspec.controller.handler; | ||
|
||
import static org.folio.rspec.controller.handler.ServiceExceptionHandler.errorCollection; | ||
import static org.folio.rspec.controller.handler.ServiceExceptionHandler.fromErrorCode; | ||
import static org.folio.rspec.domain.dto.ErrorCode.RESOURCE_NOT_FOUND; | ||
|
||
import org.folio.rspec.domain.dto.ErrorCollection; | ||
import org.folio.rspec.exception.ResourceNotFoundException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ResourceNotFoundExceptionHandler implements ServiceExceptionHandler { | ||
|
||
@Override | ||
public ResponseEntity<ErrorCollection> handleException(Exception e) { | ||
var error = fromErrorCode(RESOURCE_NOT_FOUND).message(e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorCollection(error)); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(Exception e) { | ||
return e instanceof ResourceNotFoundException; | ||
} | ||
} |
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
mod-record-specifications-server/src/main/java/org/folio/rspec/domain/entity/Rule.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.rspec.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.folio.rspec.domain.entity.support.Metadata; | ||
import org.folio.rspec.domain.entity.support.UuidPersistable; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "rule") | ||
public class Rule extends UuidPersistable { | ||
|
||
public static final String NAME_COLUMN = "name"; | ||
public static final String DESCRIPTION_COLUMN = "description"; | ||
public static final String CODE_COLUMN = "code"; | ||
|
||
@Column(name = NAME_COLUMN, nullable = false) | ||
private String name; | ||
@Column(name = DESCRIPTION_COLUMN) | ||
private String description; | ||
@Column(name = CODE_COLUMN, nullable = false) | ||
private String code; | ||
|
||
@Embedded | ||
private Metadata metadata; | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return super.equals(obj); | ||
} | ||
} |
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
Oops, something went wrong.