Skip to content

Commit

Permalink
⬆️ Upgrade versions and format
Browse files Browse the repository at this point in the history
  • Loading branch information
dubdabasoduba committed Feb 12, 2025
1 parent 2924dd0 commit c00de45
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 65 deletions.
4 changes: 2 additions & 2 deletions exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.smartregister</groupId>
<artifactId>opensrp-gateway-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>exec</artifactId>
Expand Down Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>org.smartregister</groupId>
<artifactId>plugins</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.smartregister</groupId>
<artifactId>opensrp-gateway-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>plugins</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface ResourceType {
String LOCATION = "Location";
}

public interface HttpMethods{
public interface HttpMethods {
String POST = "POST";
String GET = "GET";
String PUT = "PUT";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
package org.smartregister.fhir.gateway.plugins;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
import com.google.common.annotations.VisibleForTesting;
import com.google.fhir.gateway.ExceptionUtil;
import com.google.fhir.gateway.ProxyConstants;
import com.google.fhir.gateway.interfaces.AccessDecision;
import com.google.fhir.gateway.interfaces.RequestDetailsReader;
import com.google.fhir.gateway.interfaces.RequestMutation;
import com.google.gson.Gson;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import lombok.Getter;
import static ca.uhn.fhir.rest.api.Constants.PARAM_SUMMARY;
import static org.smartregister.fhir.gateway.plugins.EnvUtil.getEnvironmentVar;

import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.TextUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartregister.helpers.LocationHelper;

import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import com.google.common.annotations.VisibleForTesting;
import com.google.fhir.gateway.ExceptionUtil;
import com.google.fhir.gateway.ProxyConstants;
import com.google.fhir.gateway.interfaces.AccessDecision;
import com.google.fhir.gateway.interfaces.RequestDetailsReader;
import com.google.fhir.gateway.interfaces.RequestMutation;
import com.google.gson.Gson;

import static ca.uhn.fhir.rest.api.Constants.PARAM_SUMMARY;
import static org.smartregister.fhir.gateway.plugins.EnvUtil.getEnvironmentVar;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import lombok.Getter;

public class SyncAccessDecision implements AccessDecision {
public static final String SYNC_FILTER_IGNORE_RESOURCES_FILE_ENV =
Expand Down Expand Up @@ -100,7 +99,7 @@ public RequestMutation getRequestMutation(RequestDetailsReader requestDetailsRea
if (syncStrategyIdsMap.isEmpty()
|| StringUtils.isBlank(syncStrategy)
|| (syncStrategyIdsMap.containsKey(syncStrategy)
&& syncStrategyIdsMap.get(syncStrategy).isEmpty())) {
&& syncStrategyIdsMap.get(syncStrategy).isEmpty())) {

ForbiddenOperationException forbiddenOperationException =
new ForbiddenOperationException(
Expand Down Expand Up @@ -197,9 +196,7 @@ private List<String> addSyncFilters(Map<String, String[]> syncTags) {
return paramValues;
}

/**
* NOTE: Always return a null whenever you want to skip post-processing
*/
/** NOTE: Always return a null whenever you want to skip post-processing */
@Override
public String postProcess(RequestDetailsReader request, HttpResponse response)
throws IOException {
Expand Down Expand Up @@ -233,9 +230,9 @@ public String postProcess(RequestDetailsReader request, HttpResponse response)

resultContent = this.fhirR4JsonParser.encodeResourceToString(resultContentBundle);

} else if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy) &&
(Constants.HttpMethods.GET.equals(request.getRequestType().name())
|| Constants.HttpMethods.PATCH.equals(request.getRequestType().name()))) {
} else if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)
&& (Constants.HttpMethods.GET.equals(request.getRequestType().name())
|| Constants.HttpMethods.PATCH.equals(request.getRequestType().name()))) {

IBaseResource responseResource =
processRelatedEntityLocationSyncStrategy(request, response);
Expand All @@ -251,7 +248,7 @@ public String postProcess(RequestDetailsReader request, HttpResponse response)

if (Constants.ResourceType.LOCATION.equals(request.getResourceName())
&& (Constants.HttpMethods.POST.equals(request.getRequestType().name())
|| Constants.HttpMethods.PUT.equals(request.getRequestType().name()))) {
|| Constants.HttpMethods.PUT.equals(request.getRequestType().name()))) {

resultContent = new BasicResponseHandler().handleResponse(response);
String requestPath = request.getRequestPath();
Expand Down Expand Up @@ -294,11 +291,11 @@ private IBaseResource processRelatedEntityLocationSyncStrategy(
+ getRequestParametersString(request.getParameters());

for (int startIndex = SyncAccessDecisionConstants.REL_LOCATION_INITIAL_CHUNK_SIZE;
startIndex
< syncStrategyIdsMap
.get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION)
.size();
startIndex += SyncAccessDecisionConstants.REL_LOCATION_CHUNK_SIZE) {
startIndex
< syncStrategyIdsMap
.get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION)
.size();
startIndex += SyncAccessDecisionConstants.REL_LOCATION_CHUNK_SIZE) {

int endIndex =
Math.min(
Expand Down Expand Up @@ -428,20 +425,20 @@ private Bundle processListEntriesGatewayModeByBundle(
List<Bundle.BundleEntryComponent> bundleEntryComponentList =
((Bundle) responseResource)
.getEntry().stream()
.filter(it -> it.getResource() instanceof ListResource)
.flatMap(
bundleEntryComponent ->
((ListResource) bundleEntryComponent.getResource())
.getEntry().stream())
.skip(start)
.limit(count)
.map(
listEntryComponent ->
createBundleEntryComponent(
Bundle.HTTPVerb.GET,
listEntryComponent.getItem().getReference(),
null))
.collect(Collectors.toList());
.filter(it -> it.getResource() instanceof ListResource)
.flatMap(
bundleEntryComponent ->
((ListResource) bundleEntryComponent.getResource())
.getEntry().stream())
.skip(start)
.limit(count)
.map(
listEntryComponent ->
createBundleEntryComponent(
Bundle.HTTPVerb.GET,
listEntryComponent.getItem().getReference(),
null))
.collect(Collectors.toList());

return requestBundle.setEntry(bundleEntryComponentList);
}
Expand Down Expand Up @@ -653,7 +650,7 @@ private boolean shouldSkipDataFiltering(RequestDetailsReader requestDetailsReade

if (entry.getMethodType() != null
&& !entry.getMethodType()
.equals(requestDetailsReader.getRequestType().name())) {
.equals(requestDetailsReader.getRequestType().name())) {
continue;
}

Expand Down Expand Up @@ -703,14 +700,10 @@ public void setFhirR4Client(IGenericClient fhirR4Client) {
}

class IgnoredResourcesConfig {
@Getter
List<IgnoredResourcesConfig> entries;
@Getter
private String path;
@Getter
private String methodType;
@Getter
private Map<String, Object> queryParams;
@Getter List<IgnoredResourcesConfig> entries;
@Getter private String path;
@Getter private String methodType;
@Getter private Map<String, Object> queryParams;

@Override
public String toString() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.smartregister</groupId>
<artifactId>opensrp-gateway-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<packaging>pom</packaging>

<modules>
Expand Down

0 comments on commit c00de45

Please sign in to comment.