Skip to content

Commit

Permalink
renamed files
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Jan 8, 2025
1 parent bc39c66 commit 32d911a
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import com.amazonaws.services.lambda.runtime.Context;
import com.google.common.net.MediaType;

import java.net.HttpURLConnection;
import java.util.List;
import no.unit.nva.search.common.ContentTypeUtils;
import no.unit.nva.search.common.records.JsonNodeMutator;
import no.unit.nva.search.resource.LegacyMutator;
import no.unit.nva.search.resource.ResourceClient;
import no.unit.nva.search.resource.ResourceSearchQuery;
import no.unit.nva.search.resource.SimplifiedMutator;

import nva.commons.apigateway.AccessRight;
import nva.commons.apigateway.ApiGatewayHandler;
import nva.commons.apigateway.RequestInfo;
Expand All @@ -31,9 +31,6 @@
import nva.commons.core.Environment;
import nva.commons.core.JacocoGenerated;

import java.net.HttpURLConnection;
import java.util.List;

/**
* Handler for searching resources.
*
Expand All @@ -58,15 +55,15 @@ protected List<MediaType> listSupportedMediaTypes() {
return DEFAULT_RESPONSE_MEDIA_TYPES;
}

@Override
protected void validateRequest(Void unused, RequestInfo requestInfo, Context context)
throws ApiGatewayException {
@Override
protected void validateRequest(Void unused, RequestInfo requestInfo, Context context)
throws ApiGatewayException {
validateAccessRight(requestInfo.getAccessRights());
}

@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException, UnauthorizedException {
@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException, UnauthorizedException {
var version = ContentTypeUtils.extractVersionFromRequestInfo(requestInfo);

return ResourceSearchQuery.builder()
Expand All @@ -90,11 +87,8 @@ protected Integer getSuccessStatusCode(Void input, String output) {
}

private void validateAccessRight(List<AccessRight> accessRights) throws UnauthorizedException {
if (accessRights.contains(AccessRight.MANAGE_RESOURCES_ALL)
|| accessRights.contains(AccessRight.MANAGE_CUSTOMERS)
// || accessRights.contains(AccessRight.MANAGE_OWN_AFFILIATION)
// || accessRights.contains(AccessRight.MANAGE_RESOURCES_STANDARD)
) {
if (accessRights.contains(AccessRight.MANAGE_RESOURCES_ALL)
|| accessRights.contains(AccessRight.MANAGE_CUSTOMERS)) {
return;
}
throw new UnauthorizedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,55 @@

import com.amazonaws.services.lambda.runtime.Context;
import com.google.common.net.MediaType;

import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import no.unit.nva.search.common.ContentTypeUtils;
import no.unit.nva.search.common.records.JsonNodeMutator;
import no.unit.nva.search.resource.LegacyMutator;
import no.unit.nva.search.resource.ResourceClient;
import no.unit.nva.search.resource.ResourceSearchQuery;
import no.unit.nva.search.resource.SimplifiedMutator;

import nva.commons.apigateway.ApiGatewayHandler;
import nva.commons.apigateway.RequestInfo;
import nva.commons.apigateway.exceptions.BadRequestException;
import nva.commons.core.Environment;
import nva.commons.core.JacocoGenerated;

import org.apache.http.HttpHeaders;

import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
* Handler for searching resources.
*
* <p>Searches for resources in the OpenSearch index.
*/
public class SearchResourceHandler extends ApiGatewayHandler<Void, String> {

private final ResourceClient opensearchClient;
private final ResourceClient opensearchClient;

@JacocoGenerated
public SearchResourceHandler() {
this(new Environment(), defaultClient());
}
@JacocoGenerated
public SearchResourceHandler() {
this(new Environment(), defaultClient());
}

public SearchResourceHandler(Environment environment, ResourceClient resourceClient) {
super(Void.class, environment);
this.opensearchClient = resourceClient;
}
public SearchResourceHandler(Environment environment, ResourceClient resourceClient) {
super(Void.class, environment);
this.opensearchClient = resourceClient;
}

@Override
protected List<MediaType> listSupportedMediaTypes() {
return DEFAULT_RESPONSE_MEDIA_TYPES;
}
@Override
protected List<MediaType> listSupportedMediaTypes() {
return DEFAULT_RESPONSE_MEDIA_TYPES;
}

@Override
protected void validateRequest(Void unused, RequestInfo requestInfo, Context context) {
// Do nothing
}
@Override
protected void validateRequest(Void unused, RequestInfo requestInfo, Context context) {
// Do nothing
}

@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException {
@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException {
var version = ContentTypeUtils.extractVersionFromRequestInfo(requestInfo);

return ResourceSearchQuery.builder()
Expand All @@ -79,12 +75,12 @@ protected String processInput(Void input, RequestInfo requestInfo, Context conte
.doSearch(opensearchClient)
.withMutator(getMutator(version))
.toString();
}
}

@Override
protected void addAdditionalHeaders(Supplier<Map<String, String>> additionalHeaders) {
super.addAdditionalHeaders(() -> Map.of(HttpHeaders.VARY, HttpHeaders.ACCEPT));
}
@Override
protected void addAdditionalHeaders(Supplier<Map<String, String>> additionalHeaders) {
super.addAdditionalHeaders(() -> Map.of(HttpHeaders.VARY, HttpHeaders.ACCEPT));
}

private List<String> getIncludedFields(String version) {
return V_2024_12_01_SIMPLER_MODEL.equals(version)
Expand All @@ -98,8 +94,8 @@ private JsonNodeMutator getMutator(String version) {
: new LegacyMutator();
}

@Override
protected Integer getSuccessStatusCode(Void input, String output) {
return HttpURLConnection.HTTP_OK;
}
@Override
protected Integer getSuccessStatusCode(Void input, String output) {
return HttpURLConnection.HTTP_OK;
}
}
Loading

0 comments on commit 32d911a

Please sign in to comment.