Skip to content

Commit

Permalink
new API call to link-interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
w-hayes committed Nov 23, 2023
1 parent 55eedcc commit d5ae5a5
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,19 @@ private Route createJeMPIRoutes(
http)),
path(GlobalConstants.SEGMENT_POST_FILTER_GIDS,
() -> Routes.postFilterGids(actorSystem, backEnd)),
path(GlobalConstants.SEGMENT_PROXY_CR_REGISTER,
path(GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION,
() -> Routes.postLinkInteraction(AppConfig.LINKER_IP,
AppConfig.LINKER_HTTP_PORT,
http)),
path(GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION_TO_GID,
() -> Routes.postLinkInteractionToGid(AppConfig.LINKER_IP,
AppConfig.LINKER_HTTP_PORT,
http)),
path(GlobalConstants.SEGMENT_PROXY_POST_CR_REGISTER,
() -> Routes.postCrRegister(AppConfig.LINKER_IP, AppConfig.LINKER_HTTP_PORT, http)),
path(GlobalConstants.SEGMENT_PROXY_CR_FIND,
path(GlobalConstants.SEGMENT_PROXY_POST_CR_FIND,
() -> Routes.postCrFind(AppConfig.LINKER_IP, AppConfig.LINKER_HTTP_PORT, http)),
path(GlobalConstants.SEGMENT_PROXY_CR_CANDIDATES,
path(GlobalConstants.SEGMENT_PROXY_POST_CR_CANDIDATES,
() -> Routes.postCrCandidates(AppConfig.LINKER_IP, AppConfig.LINKER_HTTP_PORT, http)),
path(GlobalConstants.SEGMENT_POST_FILTER_GIDS_WITH_INTERACTION_COUNT,
() -> Routes.postFilterGidsWithInteractionCount(actorSystem, backEnd)))),
Expand All @@ -98,8 +106,10 @@ private Route createJeMPIRoutes(
() -> Routes.patchIidNewGidLink(actorSystem, backEnd)),
path(GlobalConstants.SEGMENT_PATCH_IID_GID_LINK,
() -> Routes.patchIidGidLink(actorSystem, backEnd)),
path(GlobalConstants.SEGMENT_PROXY_CR_UPDATE_FIELDS,
() -> Routes.patchCrUpdateFields(AppConfig.LINKER_IP, AppConfig.LINKER_HTTP_PORT, http)))),
path(GlobalConstants.SEGMENT_PROXY_PATCH_CR_UPDATE_FIELDS,
() -> Routes.patchCrUpdateFields(AppConfig.LINKER_IP,
AppConfig.LINKER_HTTP_PORT,
http)))),
get(() -> concat(path(GlobalConstants.SEGMENT_COUNT_GOLDEN_RECORDS,
() -> Routes.countGoldenRecords(actorSystem, backEnd)),
path(GlobalConstants.SEGMENT_COUNT_INTERACTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jembi.jempi.AppConfig;
import org.jembi.jempi.shared.models.ApiModels;
import org.jembi.jempi.shared.models.GlobalConstants;
import org.jembi.jempi.shared.models.LinkInteractionSyncBody;
import org.jembi.jempi.shared.models.LinkInteractionToGidSyncBody;
import org.jembi.jempi.shared.utils.AppUtils;

import java.util.Locale;
import java.util.concurrent.CompletionStage;

import static org.jembi.jempi.shared.utils.AppUtils.OBJECT_MAPPER;

public final class HttpServer extends AllDirectives {

private static final Logger LOGGER = LogManager.getLogger(HttpServer.class);
Expand All @@ -42,7 +42,7 @@ void open(
LOGGER.info("Server online at http://{}:{}", "0.0.0.0", AppConfig.CONTROLLER_HTTP_PORT);
}

private CompletionStage<HttpResponse> postLinkInteraction(final LinkInteractionSyncBody body) throws JsonProcessingException {
private CompletionStage<HttpResponse> postLinkInteraction(final ApiModels.LinkInteractionSyncBody body) throws JsonProcessingException {
final HttpRequest request;
request = HttpRequest
.create(String.format(Locale.ROOT,
Expand All @@ -51,20 +51,20 @@ private CompletionStage<HttpResponse> postLinkInteraction(final LinkInteractionS
AppConfig.LINKER_HTTP_PORT,
GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION))
.withMethod(HttpMethods.POST)
.withEntity(ContentTypes.APPLICATION_JSON, AppUtils.OBJECT_MAPPER.writeValueAsBytes(body));
.withEntity(ContentTypes.APPLICATION_JSON, OBJECT_MAPPER.writeValueAsBytes(body));
final var stage = http.singleRequest(request);
return stage.thenApply(response -> response);
}

private CompletionStage<HttpResponse> postLinkInteractionToGid(final LinkInteractionToGidSyncBody body) throws JsonProcessingException {
private CompletionStage<HttpResponse> postLinkInteractionToGid(final ApiModels.LinkInteractionToGidSyncBody body) throws JsonProcessingException {
final var request = HttpRequest
.create(String.format(Locale.ROOT,
"http://%s:%d/JeMPI/%s",
AppConfig.LINKER_IP,
AppConfig.LINKER_HTTP_PORT,
GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION_TO_GID))
.withMethod(HttpMethods.POST)
.withEntity(ContentTypes.APPLICATION_JSON, AppUtils.OBJECT_MAPPER.writeValueAsBytes(body));
.withEntity(ContentTypes.APPLICATION_JSON, OBJECT_MAPPER.writeValueAsBytes(body));
final var stage = http.singleRequest(request);
return stage.thenApply(response -> response);
}
Expand All @@ -78,7 +78,7 @@ private CompletionStage<HttpResponse> getMU() {
}

private Route routeLinkInteraction() {
return entity(Jackson.unmarshaller(LinkInteractionSyncBody.class),
return entity(Jackson.unmarshaller(ApiModels.LinkInteractionSyncBody.class),
obj -> {
try {
LOGGER.debug("{}", obj);
Expand All @@ -94,17 +94,17 @@ private Route routeLinkInteraction() {
}

private Route routeLinkInteractionToGid() {
return entity(Jackson.unmarshaller(LinkInteractionToGidSyncBody.class),
return entity(Jackson.unmarshaller(ApiModels.LinkInteractionToGidSyncBody.class),
obj -> {
try {
return onComplete(postLinkInteractionToGid(obj),
response -> response.isSuccess()
? complete(response.get())
: complete(StatusCodes.IM_A_TEAPOT));
: complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT)));
} catch (JsonProcessingException e) {
LOGGER.error(e.getLocalizedMessage(), e);
return complete(StatusCodes.IM_A_TEAPOT);
}
return complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT));
});
}

Expand Down
4 changes: 2 additions & 2 deletions JeMPI_Apps/JeMPI_LibAPI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
Expand Down
Loading

0 comments on commit d5ae5a5

Please sign in to comment.