Skip to content

Commit

Permalink
MODEUS-184 Remove /counter-reports/upload/provider/{id} endpoint (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
alb3rtino authored Oct 14, 2024
1 parent d477d3f commit b941151
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 929 deletions.
11 changes: 1 addition & 10 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
},
{
"id": "counter-reports",
"version": "3.3",
"version": "4.0",
"handlers": [
{
"methods": [
Expand Down Expand Up @@ -208,15 +208,6 @@
"counterreports.item.get"
]
},
{
"methods": [
"POST"
],
"pathPattern": "/counter-reports/upload/provider/{id}",
"permissionsRequired": [
"counterreports.item.post"
]
},
{
"methods": [
"POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
Expand All @@ -22,7 +21,6 @@
import io.vertx.sqlclient.Tuple;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
Expand All @@ -38,7 +36,6 @@
import org.folio.cql2pgjson.exception.FieldException;
import org.folio.rest.annotations.Validate;
import org.folio.rest.jaxrs.model.CounterReport;
import org.folio.rest.jaxrs.model.CounterReportDocument;
import org.folio.rest.jaxrs.model.CounterReports;
import org.folio.rest.jaxrs.model.CounterReportsGetOrder;
import org.folio.rest.jaxrs.model.CounterReportsPerYear;
Expand Down Expand Up @@ -295,61 +292,6 @@ private CounterReportsSorted sortByYearAndType(List<CounterReport> reports) {
return result;
}

@Override
@Validate
public void postCounterReportsUploadProviderById(
String id,
boolean overwrite,
CounterReportDocument entity,
Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) {

Boolean isEditedManually = entity.getReportMetadata().getReportEditedManually();
String editReason = entity.getReportMetadata().getEditReason();
decodeBase64Report(entity.getContents().getData(), vertxContext)
.onSuccess(
counterReports ->
PgHelper.getUDPfromDbById(vertxContext, okapiHeaders, id)
.compose(
udp -> {
counterReports.forEach(
cr -> {
cr.setEditReason(editReason);
cr.setReportEditedManually(isEditedManually);
cr.withProviderId(udp.getId())
.withDownloadTime(Date.from(Instant.now()));
});
return succeededFuture(counterReports);
})
.compose(
crs ->
PgHelper.saveCounterReportsToDb(
vertxContext, okapiHeaders, crs, overwrite))
.onSuccess(
reportIds ->
asyncResultHandler.handle(
succeededFuture(
PostCounterReportsUploadProviderByIdResponse
.respond200WithTextPlain(
String.format(
"Saved report with ids: %s",
String.join(",", reportIds))))))
.onFailure(
throwable ->
asyncResultHandler.handle(
succeededFuture(
PostCounterReportsUploadProviderByIdResponse
.respond500WithTextPlain(
String.format(ERR_MSG_SAVE_REPORT, throwable))))))
.onFailure(
throwable ->
asyncResultHandler.handle(
succeededFuture(
PostCounterReportsUploadProviderByIdResponse.respond400WithTextPlain(
String.format(ERR_MSG_SAVE_REPORT, throwable)))));
}

private void processUpload(
String id,
boolean overwrite,
Expand Down Expand Up @@ -393,9 +335,10 @@ private void processUpload(
reportIds ->
asyncResultHandler.handle(
succeededFuture(
PostCounterReportsUploadProviderByIdResponse.respond200WithTextPlain(
String.format(
"Saved report with ids: %s", String.join(",", reportIds))))))
PostCounterReportsMultipartuploadProviderByIdResponse
.respond200WithTextPlain(
String.format(
"Saved report with ids: %s", String.join(",", reportIds))))))
.onFailure(
throwable -> {
Response.ResponseBuilder response =
Expand Down Expand Up @@ -642,27 +585,6 @@ public void getCounterReportsExportById(
.onComplete(asyncResultHandler);
}

private Future<List<CounterReport>> decodeBase64Report(String encodedData, Context vertxContext) {
Promise<List<CounterReport>> result = Promise.promise();
executeBlocking(
vertxContext,
() -> {
try {
String[] base64Splitted = encodedData.split(",");
if (base64Splitted.length < 2) {
throw new ReportUploadException(new Throwable("Report is empty."));
}
byte[] reportAsBytes = Base64.getDecoder().decode(base64Splitted[1]);
return UploadHelper.getCounterReportsFromString(new String(reportAsBytes));
} catch (Exception e) {
throw new ReportUploadException(e);
}
})
.onSuccess(result::complete)
.onFailure(result::fail);
return result.future();
}

private static class ReportUploadException extends RuntimeException {

public ReportUploadException(Throwable cause) {
Expand Down
Loading

0 comments on commit b941151

Please sign in to comment.