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

CIRC-2198 Implement the code for the feature UXPROD-5001 #1521

Merged
merged 13 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 4 additions & 0 deletions ramls/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
"itemLocationCode": {
"description": "Allow specifying item location when creating title-level requests",
"type": "string"
},
"isDcbReRequestCancellation": {
"description": "Indicates whether the request was cancelled during a DCB transaction update",
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/folio/circulation/domain/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.folio.circulation.domain.representations.RequestProperties.REQUEST_LEVEL;
import static org.folio.circulation.domain.representations.RequestProperties.REQUEST_TYPE;
import static org.folio.circulation.domain.representations.RequestProperties.STATUS;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getBooleanProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getDateTimeProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getIntegerProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;
Expand Down Expand Up @@ -427,6 +428,10 @@ public boolean hasLoan() {
return loan != null;
}

public boolean getDcbReRequestCancellationValue() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public boolean getDcbReRequestCancellationValue() {
public boolean isDcbReRequestCancellation() {

return getBooleanProperty(requestRepresentation, "isDcbReRequestCancellation");
}

public enum Operation {
CREATE, REPLACE, MOVE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ public Result<RequestAndRelatedRecords> sendNoticeOnRequestCancelled(
log.debug("sendNoticeOnRequestCancelled:: parameters records: {}", () -> records);
Request request = records.getRequest();

if (request.hasItemId()) {
sendCancellationNoticeForRequestWithItemId(request);
} else {
sendCancellationNoticeForRequestWithoutItemId(request);
// Send the cancellation notice only if the isDcbReRequestCancellation flag is false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this comment? I think code below speaks for itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!request.getDcbReRequestCancellationValue()) {
if (request.hasItemId()) {
sendCancellationNoticeForRequestWithItemId(request);
} else {
sendCancellationNoticeForRequestWithoutItemId(request);
}
}

return succeeded(records);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.folio.circulation.resources;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;

import org.folio.circulation.domain.Request;
import org.folio.circulation.domain.RequestAndRelatedRecords;
import org.folio.circulation.domain.notice.ImmediatePatronNoticeService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import api.support.builders.RequestBuilder;
import io.vertx.core.json.JsonObject;

@ExtendWith(MockitoExtension.class)
class RequestNoticeSenderTest {

@Mock
private ImmediatePatronNoticeService immediatePatronNoticeService;
@InjectMocks
private RequestNoticeSender requestNoticeSender;

@Test
void shouldNotSendNotificationWhenIsDcbCancellationTrue() {
JsonObject representation = new RequestBuilder().create();
representation.put("isDcbReRequestCancellation", true);
requestNoticeSender.sendNoticeOnRequestCancelled(
new RequestAndRelatedRecords(Request.from(representation)));
Mockito.verify(immediatePatronNoticeService, times(0)).acceptNoticeEvent(any());
Mockito.verify(immediatePatronNoticeService, times(0)).sendNotice(any(), any());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Mockito.verify(immediatePatronNoticeService, times(0)).acceptNoticeEvent(any());
Mockito.verify(immediatePatronNoticeService, times(0)).sendNotice(any(), any());
Mockito.verify(immediatePatronNoticeService, times(0)).acceptNoticeEvent(any());
Mockito.verify(immediatePatronNoticeService, times(0)).sendNotice(any(), any());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}
Loading