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

refactor Route.java & fix dn-app script #215

Merged
merged 1 commit into from
Apr 3, 2024
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 @@ -9,7 +9,6 @@
import akka.http.javadsl.server.Route;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jembi.jempi.libmpi.MpiGeneralError;
import org.jembi.jempi.libmpi.MpiServiceError;
import org.jembi.jempi.shared.models.*;

Expand All @@ -25,6 +24,7 @@

import static akka.http.javadsl.server.Directives.*;
import static akka.http.javadsl.server.PathMatchers.segment;
import static org.jembi.jempi.libapi.MapError.mapError;
import static org.jembi.jempi.shared.utils.AppUtils.OBJECT_MAPPER;

public final class Routes {
Expand All @@ -36,28 +36,6 @@ public final class Routes {
private Routes() {
}

static Route mapError(final MpiGeneralError obj) {
return switch (obj) {
case MpiServiceError.InteractionIdDoesNotExistError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.GoldenIdDoesNotExistError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.GoldenIdInteractionConflictError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.DeletePredicateError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.InvalidFunctionError e -> complete(StatusCodes.UNPROCESSABLE_ENTITY, e, JSON_MARSHALLER);
case MpiServiceError.InvalidOperatorError e -> complete(StatusCodes.UNPROCESSABLE_ENTITY, e, JSON_MARSHALLER);
case MpiServiceError.NoScoreGivenError e -> complete(StatusCodes.PARTIAL_CONTENT, e, JSON_MARSHALLER);
case MpiServiceError.NotImplementedError e -> complete(StatusCodes.NOT_IMPLEMENTED, e, JSON_MARSHALLER);
case MpiServiceError.CRClientExistsError e -> complete(StatusCodes.CONFLICT, e, JSON_MARSHALLER);
case MpiServiceError.CRUpdateFieldError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.CRGidDoesNotExistError e -> complete(StatusCodes.NOT_FOUND, e, JSON_MARSHALLER);
case MpiServiceError.CRLinkUpdateError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.CRMissingFieldError e -> complete(StatusCodes.BAD_REQUEST, e, JSON_MARSHALLER);
case MpiServiceError.GeneralError e -> complete(StatusCodes.INTERNAL_SERVER_ERROR, e, JSON_MARSHALLER);
case MpiServiceError.InternalError e -> complete(StatusCodes.INTERNAL_SERVER_ERROR, e, JSON_MARSHALLER);
default -> complete(StatusCodes.INTERNAL_SERVER_ERROR);
};
}


private static Route postIidNewGidLink(
final ActorSystem<Void> actorSystem,
final ActorRef<BackEnd.Event> backEnd,
Expand All @@ -76,7 +54,7 @@ private static Route postIidNewGidLink(
}
return result.get()
.linkInfo()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
linkInfo -> onComplete(
processOnNotificationResolution(
Expand Down Expand Up @@ -107,7 +85,7 @@ private static Route postIidGidLink(
}
return result.get()
.linkInfo()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
linkInfo -> onComplete(
processOnNotificationResolution(
Expand Down Expand Up @@ -209,7 +187,7 @@ private static Route countGoldenRecords(
}
return result.get()
.count()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
count -> complete(StatusCodes.OK,
new ApiModels.ApiGoldenRecordCount(count),
Expand All @@ -229,7 +207,7 @@ private static Route countInteractions(
}
return result.get()
.count()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
count -> complete(StatusCodes.OK,
new ApiModels.ApiInteractionCount(count),
Expand Down Expand Up @@ -314,7 +292,7 @@ private static Route getExpandedGoldenRecordsUsingParameterList(
}
return result.get()
.expandedGoldenRecords()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
expandedGoldenRecords -> complete(StatusCodes.OK,
expandedGoldenRecords.stream()
Expand All @@ -339,7 +317,7 @@ private static Route getExpandedGoldenRecordsFromUsingCSV(
}
return result.get()
.expandedGoldenRecords()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
expandedGoldenRecords -> complete(StatusCodes.OK,
expandedGoldenRecords.stream()
Expand All @@ -364,7 +342,7 @@ private static Route getExpandedInteractionsUsingCSV(
}
return result.get()
.expandedPatientRecords()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
expandedPatientRecords -> complete(StatusCodes.OK,
expandedPatientRecords.stream()
Expand All @@ -388,7 +366,7 @@ private static Route getExpandedGoldenRecord(
}
return result.get()
.goldenRecord()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
goldenRecord -> complete(StatusCodes.OK,
ApiModels.ApiExpandedGoldenRecord
Expand All @@ -410,7 +388,7 @@ private static Route getInteraction(
}
return result.get()
.patient()
.mapLeft(Routes::mapError)
.mapLeft(MapError::mapError)
.fold(error -> error,
patientRecord -> complete(StatusCodes.OK,
ApiModels.ApiInteraction.fromInteraction(patientRecord),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pushd .
em-scala
linker
api
api_kc
api-kc
ui
)

Expand Down