Skip to content

Commit

Permalink
renamed files (#624)
Browse files Browse the repository at this point in the history
no code changes
  • Loading branch information
StigNorland authored Jan 8, 2025
1 parent bcdb19a commit ad04a9f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import no.unit.nva.search.common.records.JsonNodeMutator;

public class ContributorCopyMutator implements JsonNodeMutator {
public class LegacyMutator implements JsonNodeMutator {

public static final String CONTRIBUTORS_PREVIEW = "contributorsPreview";
public static final String ENTITY_DESCRIPTION = "entityDescription";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SimplifiedResourceModelMutator implements JsonNodeMutator {
public class SimplifiedMutator implements JsonNodeMutator {

public static final String ID = "id";
public static final String IDENTIFIER = "identifier";
Expand Down Expand Up @@ -82,7 +82,7 @@ public class SimplifiedResourceModelMutator implements JsonNodeMutator {
public static final String SERIES = "series";
public static final String PUBLISHER = "publisher";

public SimplifiedResourceModelMutator() {
public SimplifiedMutator() {
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@

import java.nio.file.Path;

class SimplifiedResourceModelMutatorTest {
class SimplifiedMutatorTest {

@Test
void shouldNotThrowOnEmptyBody() {
assertDoesNotThrow(
() ->
new SimplifiedResourceModelMutator()
.transform(new ObjectMapper().createObjectNode()));
assertDoesNotThrow(
() -> new SimplifiedMutator().transform(new ObjectMapper().createObjectNode()));
}

@Test
void shouldOutputIdAndNoEmptyStringsIdIfOnlyIdIsProvidedAsInput() {
var id = randomString();
var input = new ObjectMapper().createObjectNode();
input.set("id", new TextNode(id));
var result = new SimplifiedResourceModelMutator().transform(input);
var result = new SimplifiedMutator().transform(input);
assertTrue(result.isObject());
ObjectNode resultAsObject = (ObjectNode) result;
resultAsObject
Expand All @@ -63,7 +61,7 @@ void shouldKeepAllContributorsOMutating() throws JsonProcessingException {

var contributorsInSampleJson = 1;

var mutated = new SimplifiedResourceModelMutator().transform(json);
var mutated = new SimplifiedMutator().transform(json);
var asDto = objectMapper.treeToValue(mutated, ResourceSearchResponse.class);
assertThat(asDto.contributorsPreview().size(), is(equalTo(contributorsInSampleJson)));
assertThat(asDto.contributorsCount(), is(equalTo(contributorsInSampleJson)));
Expand All @@ -80,7 +78,7 @@ void shouldMapAlternativeTitles() throws JsonProcessingException {
entityDescription.set("alternativeTitles", alternativeTitles);
input.set("entityDescription", entityDescription);

var mutated = new SimplifiedResourceModelMutator().transform(input);
var mutated = new SimplifiedMutator().transform(input);
var asDto = objectMapper.treeToValue(mutated, ResourceSearchResponse.class);
assertThat(asDto.alternativeTitles().size(), is(equalTo(1)));
assertThat(asDto.alternativeTitles().get(language), is(equalTo(expectedAlternativeTitle)));
Expand All @@ -106,7 +104,7 @@ void shouldMapIsbnsForArtistics() throws JsonProcessingException {
entityDescription.set("reference", reference);
input.set("entityDescription", entityDescription);

var mutated = new SimplifiedResourceModelMutator().transform(input);
var mutated = new SimplifiedMutator().transform(input);
var asDto = objectMapper.treeToValue(mutated, ResourceSearchResponse.class);

assertThat(asDto.otherIdentifiers().isbn(), hasItem(isbn1));
Expand All @@ -119,7 +117,7 @@ void shouldParseSampleFileWithNoExceptions() throws JsonProcessingException {
new ObjectMapper()
.readTree(stringFromResources(Path.of("resource_datasource.json")))
.get(0);
var result = new SimplifiedResourceModelMutator().transform(json);
var result = new SimplifiedMutator().transform(json);
assertNotNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import no.unit.nva.search.resource.ResourceClient;
import no.unit.nva.search.resource.ResourceSearchQuery;
import no.unit.nva.search.resource.SimplifiedResourceModelMutator;
import no.unit.nva.search.resource.SimplifiedMutator;

import nva.commons.apigateway.ApiGatewayHandler;
import nva.commons.apigateway.RequestInfo;
Expand Down Expand Up @@ -57,18 +57,18 @@ protected void validateRequest(Void unused, RequestInfo requestInfo, Context con
@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException {
return ResourceSearchQuery.builder()
.fromRequestInfo(requestInfo)
.withRequiredParameters(FROM, SIZE, AGGREGATION, SORT)
.withAlwaysIncludedFields(SimplifiedResourceModelMutator.getIncludedFields())
.validate()
.build()
.withFilter()
.requiredStatus(PUBLISHED, PUBLISHED_METADATA)
.apply()
.doSearch(opensearchClient)
.withMutators(new SimplifiedResourceModelMutator())
.toString();
return ResourceSearchQuery.builder()
.fromRequestInfo(requestInfo)
.withRequiredParameters(FROM, SIZE, AGGREGATION, SORT)
.withAlwaysIncludedFields(SimplifiedMutator.getIncludedFields())
.validate()
.build()
.withFilter()
.requiredStatus(PUBLISHED, PUBLISHED_METADATA)
.apply()
.doSearch(opensearchClient)
.withMutators(new SimplifiedMutator())
.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.amazonaws.services.lambda.runtime.Context;
import com.google.common.net.MediaType;

import no.unit.nva.search.resource.ContributorCopyMutator;
import no.unit.nva.search.resource.LegacyMutator;
import no.unit.nva.search.resource.ResourceClient;
import no.unit.nva.search.resource.ResourceSearchQuery;

Expand Down Expand Up @@ -61,18 +61,18 @@ protected void validateRequest(Void unused, RequestInfo requestInfo, Context con
@Override
protected String processInput(Void input, RequestInfo requestInfo, Context context)
throws BadRequestException {
return ResourceSearchQuery.builder()
.fromRequestInfo(requestInfo)
.withRequiredParameters(FROM, SIZE, AGGREGATION, SORT)
.withAlwaysExcludedFields(getExcludedFields())
.validate()
.build()
.withFilter()
.requiredStatus(PUBLISHED, PUBLISHED_METADATA)
.apply()
.doSearch(opensearchClient)
.withMutators(new ContributorCopyMutator())
.toString();
return ResourceSearchQuery.builder()
.fromRequestInfo(requestInfo)
.withRequiredParameters(FROM, SIZE, AGGREGATION, SORT)
.withAlwaysExcludedFields(getExcludedFields())
.validate()
.build()
.withFilter()
.requiredStatus(PUBLISHED, PUBLISHED_METADATA)
.apply()
.doSearch(opensearchClient)
.withMutators(new LegacyMutator())
.toString();
}

private List<String> getExcludedFields() {
Expand Down

0 comments on commit ad04a9f

Please sign in to comment.