-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
362 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
search-cli/src/main/java/ca/gc/aafc/dina/search/cli/http/DinaApiAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ca.gc.aafc.dina.search.cli.http; | ||
|
||
import ca.gc.aafc.dina.search.cli.config.EndpointDescriptor; | ||
import ca.gc.aafc.dina.search.cli.exceptions.SearchApiException; | ||
|
||
public interface DinaApiAccess { | ||
|
||
String getFromApi(EndpointDescriptor endpointDescriptor, String objectId) throws SearchApiException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
search-cli/src/main/java/ca/gc/aafc/dina/search/cli/indexing/JsonNodeTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ca.gc.aafc.dina.search.cli.indexing; | ||
|
||
import com.fasterxml.jackson.core.JsonPointer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Gets a node from a JONS:API document and transforms its value. | ||
*/ | ||
@Log4j2 | ||
public final class JsonNodeTransformer { | ||
|
||
private static final JsonPointer COORDINATES_PTR = JsonPointer.valueOf("/coordinates"); | ||
|
||
private JsonNodeTransformer() { | ||
// utility class | ||
} | ||
|
||
/** | ||
* Extracts the JsonNode under the property "coordinates". | ||
* @param eventGeomNode | ||
* @return | ||
*/ | ||
public static JsonNode extractCoordinates(JsonNode eventGeomNode) { | ||
return eventGeomNode.at(COORDINATES_PTR); | ||
} | ||
|
||
/** | ||
* From a node, get the JsonNode from an attribute and apply the transformer to it. | ||
* Replace its value with the result of the transformation. | ||
* | ||
* @param nodeToTransform | ||
* @param attribute | ||
* @param transformer | ||
*/ | ||
public static void transformNode(JsonNode nodeToTransform, String attribute, Function<JsonNode, JsonNode> transformer) { | ||
JsonNode node = nodeToTransform.get(attribute); | ||
if (node != null && !node.isMissingNode()) { | ||
if (nodeToTransform instanceof ObjectNode objectNode) { | ||
objectNode.replace(attribute, transformer.apply(node)); | ||
} else { | ||
log.debug("Not and instance of ObjectNode"); | ||
} | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
search-cli/src/test/java/ca/gc/aafc/dina/search/cli/indexing/IndexableDocumentHandlerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package ca.gc.aafc.dina.search.cli.indexing; | ||
|
||
import ca.gc.aafc.dina.search.cli.TestConstants; | ||
import ca.gc.aafc.dina.search.cli.config.ServiceEndpointProperties; | ||
import ca.gc.aafc.dina.search.cli.containers.DinaElasticSearchContainer; | ||
import ca.gc.aafc.dina.search.cli.exceptions.SearchApiException; | ||
import ca.gc.aafc.dina.search.cli.utils.JsonTestUtils; | ||
import ca.gc.aafc.dina.testsupport.TestResourceHelper; | ||
import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
import co.elastic.clients.elasticsearch.core.SearchResponse; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.testcontainers.elasticsearch.ElasticsearchContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(properties = { | ||
"spring.shell.interactive.enabled=false", | ||
"dina.messaging.isProducer=false", | ||
"dina.messaging.isConsumer=false" | ||
}) | ||
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) | ||
public class IndexableDocumentHandlerIT { | ||
|
||
private final String DOC_ID = "01930c2a-f299-7464-ad27-ce3828421e6e"; | ||
|
||
@Container | ||
private static final ElasticsearchContainer ELASTICSEARCH_CONTAINER = new DinaElasticSearchContainer(); | ||
|
||
@Autowired | ||
private ElasticsearchClient elasticSearchClient; | ||
|
||
@Autowired | ||
private ServiceEndpointProperties svcEndpointProps; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
// Start elastic search container. | ||
ELASTICSEARCH_CONTAINER.start(); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
ELASTICSEARCH_CONTAINER.stop(); | ||
} | ||
|
||
@Test | ||
@SneakyThrows({ IOException.class }) | ||
public void indexGeoPointDocuments() throws SearchApiException { | ||
|
||
ca.gc.aafc.dina.testsupport.elasticsearch.ElasticSearchTestUtils.createIndex(elasticSearchClient, | ||
TestConstants.MATERIAL_SAMPLE_INDEX, TestConstants.MATERIAL_SAMPLE_INDEX_MAPPING_FILE); | ||
|
||
// Create a specific instance to ignore api calls since we don't have external relationships to resolve | ||
IndexableDocumentHandler idh = new IndexableDocumentHandler( | ||
(endpointDescriptor, objectId) -> "", | ||
svcEndpointProps | ||
); | ||
|
||
// assemble the document which includes a geo point | ||
ObjectNode result = idh.assembleDocument(TestResourceHelper.readContentAsString("material_sample_document.json")); | ||
|
||
|
||
ca.gc.aafc.dina.testsupport.elasticsearch.ElasticSearchTestUtils.indexDocument(elasticSearchClient, TestConstants.MATERIAL_SAMPLE_INDEX, DOC_ID, | ||
JsonTestUtils.OBJECT_MAPPER.writeValueAsString(result)); | ||
|
||
SearchResponse<JsonNode> searchResponse = ca.gc.aafc.dina.search.cli.utils.ElasticSearchTestUtils.search(elasticSearchClient, TestConstants.MATERIAL_SAMPLE_INDEX, | ||
"data.id", DOC_ID); | ||
|
||
assertEquals(1, searchResponse.hits().hits().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.