-
Notifications
You must be signed in to change notification settings - Fork 5
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 #46 from folio-org/MODDCB-49
MODDCB-49
- Loading branch information
Showing
41 changed files
with
537 additions
and
30 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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/folio/dcb/client/feign/CancellationReasonClient.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.dcb.client.feign; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.folio.spring.config.FeignClientConfiguration; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "cancellation-reason-storage", configuration = FeignClientConfiguration.class) | ||
public interface CancellationReasonClient { | ||
|
||
@GetMapping("/cancellation-reasons/{cancellationReasonId}") | ||
CancellationReason findCancellationReason(@PathVariable("cancellationReasonId") String cancellationReasonId); | ||
|
||
@PostMapping("/cancellation-reasons") | ||
void createCancellationReason(@RequestBody CancellationReason cancellationReason); | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
class CancellationReason { | ||
private String id; | ||
private String name; | ||
private String description; | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/org/folio/dcb/client/feign/CirculationRequestClient.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,14 @@ | ||
package org.folio.dcb.client.feign; | ||
|
||
import org.folio.dcb.domain.dto.CirculationRequest; | ||
import org.folio.spring.config.FeignClientConfiguration; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
@FeignClient(name = "request-storage", configuration = FeignClientConfiguration.class) | ||
public interface CirculationRequestClient { | ||
@GetMapping("/requests/{circulationItemId}") | ||
CirculationRequest fetchRequestById(@PathVariable("circulationItemId") String circulationItemId); | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/folio/dcb/exception/CirculationRequestException.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.dcb.exception; | ||
|
||
public class CirculationRequestException extends RuntimeException { | ||
|
||
public CirculationRequestException(String errorMsg) { | ||
super(errorMsg); | ||
} | ||
|
||
} |
Empty file removed
0
src/main/java/org/folio/dcb/listener/kafka/CirculationCheckInEventListener.java
Empty file.
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
7 changes: 7 additions & 0 deletions
7
src/main/java/org/folio/dcb/service/CirculationRequestService.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,7 @@ | ||
package org.folio.dcb.service; | ||
|
||
import org.folio.dcb.domain.dto.CirculationRequest; | ||
|
||
public interface CirculationRequestService { | ||
CirculationRequest getCancellationRequestIfOpenOrNull(String requestId); | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/folio/dcb/service/impl/CirculationRequestServiceImpl.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,48 @@ | ||
package org.folio.dcb.service.impl; | ||
|
||
import feign.FeignException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.dcb.client.feign.CirculationRequestClient; | ||
import org.folio.dcb.domain.dto.CirculationRequest; | ||
import org.folio.dcb.service.CirculationRequestService; | ||
import org.folio.dcb.utils.DCBConstants; | ||
import org.folio.dcb.utils.RequestStatus; | ||
import org.folio.spring.FolioExecutionContext; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@Log4j2 | ||
@RequiredArgsConstructor | ||
public class CirculationRequestServiceImpl implements CirculationRequestService { | ||
|
||
private final CirculationRequestClient circulationRequestClient; | ||
private final FolioExecutionContext folioExecutionContext; | ||
|
||
private CirculationRequest fetchRequestById(String requestId) { | ||
log.info("fetchRequestById:: fetching request for id {} ", requestId); | ||
try { | ||
return circulationRequestClient.fetchRequestById(requestId); | ||
} catch (FeignException.NotFound e) { | ||
log.warn("Circulation request not found by id={}", requestId); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public CirculationRequest getCancellationRequestIfOpenOrNull(String requestId){ | ||
CirculationRequest request = fetchRequestById(requestId); | ||
if(request != null && RequestStatus.isRequestOpen(RequestStatus.from(request.getStatus()))){ | ||
request.setStatus(RequestStatus.CLOSED_CANCELLED.getValue()); | ||
request.setCancelledDate(OffsetDateTime.now().toString()); | ||
request.setCancellationAdditionalInformation("Request cancelled by DCB"); | ||
request.setCancelledByUserId(folioExecutionContext.getUserId()); | ||
request.setCancellationReasonId(UUID.fromString(DCBConstants.CANCELLATION_REASON_ID)); | ||
return request; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.