Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODLD-646: Update the response structure of authorityAssignmentCheck API #104

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import lombok.RequiredArgsConstructor;
import org.folio.linked.data.domain.dto.AssignmentCheckDto;
import org.folio.linked.data.domain.dto.AssignmentCheckResponseDto;
import org.folio.linked.data.rest.resource.AuthorityApi;
import org.folio.linked.data.service.resource.marc.AssignAuthorityTarget;
import org.folio.linked.data.service.resource.marc.ResourceMarcAuthorityService;
Expand All @@ -17,11 +18,10 @@ public class AuthorityAssignmentController implements AuthorityApi {
private final ResourceMarcAuthorityService resourceMarcAuthorityService;

@Override
public ResponseEntity<String> authorityAssignmentCheck(AssignmentCheckDto dto) {
return ok(String.valueOf(
resourceMarcAuthorityService.isMarcAuthorityCompatibleWithTarget(
dto.getRawMarc(),
AssignAuthorityTarget.valueOf(dto.getTarget().name()))
));
public ResponseEntity<AssignmentCheckResponseDto> authorityAssignmentCheck(AssignmentCheckDto dto) {
var isValidAssignment = resourceMarcAuthorityService.isMarcAuthorityCompatibleWithTarget(
dto.getRawMarc(),
AssignAuthorityTarget.valueOf(dto.getTarget().name()));
return ok(new AssignmentCheckResponseDto(isValidAssignment));
}
}
7 changes: 3 additions & 4 deletions src/main/resources/swagger.api/mod-linked-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,11 @@ paths:
$ref: schema/assignmentCheckDto.json
responses:
'200':
description: Returns plain text boolean as response
description: Returns the result of the assignment check, including whether the assignment is valid and, if not, the reason for invalidity
content:
text/plain:
application/json:
schema:
type: string
example: true|false
$ref: schema/assignmentCheckResponseDto.json
'400':
$ref: '#/components/responses/badRequestResponse'
'500':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "MARC authority assignment check response",
"type": "object",
"properties": {
"validAssignment": {
"type": "boolean",
"description": "Indicates if the assignment is valid"
},
"invalidAssignmentReason": {
"type": "string",
"enum": ["UNSUPPORTED_MARC", "NO_LCCN", "NOT_VALID_FOR_TARGET"],
"description": "Indicates the reason why the assignment is not valid. Only present if 'validAssignment' is false."
PBobylev marked this conversation as resolved.
Show resolved Hide resolved
}
},
"required": [
"validAssignment"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import static org.folio.linked.data.test.TestUtil.defaultHeaders;
import static org.folio.linked.data.test.TestUtil.loadResourceAsString;
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -42,6 +43,7 @@ class AuthorityAssignmentControllerIT {
void authorityAssignmentCheck(String marcFile, String expectedResponse) throws Exception {
// given
var requestBuilder = post(ASSIGNMENT_CHECK_ENDPOINT)
.accept(APPLICATION_JSON)
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env))
.content(
Expand All @@ -57,6 +59,6 @@ void authorityAssignmentCheck(String marcFile, String expectedResponse) throws E
// then
resultActions
.andExpect(status().isOk())
.andExpect(content().string(expectedResponse));
.andExpect(jsonPath("$.validAssignment", equalTo(Boolean.valueOf(expectedResponse))));
}
}