Skip to content

Commit

Permalink
MODLD-646: Update the response structure of authorityAssignmentCheck API
Browse files Browse the repository at this point in the history
  • Loading branch information
pkjacob committed Jan 28, 2025
1 parent 8cf7016 commit 5fdbd75
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
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().validAssignment(isValidAssignment));
}
}
3 changes: 1 addition & 2 deletions src/main/resources/swagger.api/mod-linked-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ paths:
content:
text/plain:
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"
},
"reason": {
"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."
}
},
"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))));
}
}

0 comments on commit 5fdbd75

Please sign in to comment.