Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Oct 3, 2024
1 parent 405c461 commit 0eebf20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
<module name="JavadocMethod">
<property name="allowedAnnotations" value="Override"/>
<property name="validateThrows" value="true"/>
<property name="scope" value="anoninner"/>
<property name="allowMissingParamTags" value="false"/>
<property name="allowMissingReturnTag" value="false"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<version>3.4.0</version>
<dependencies>
<!-- override default checkstyle version -->
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.30</version>
<version>10.18.1</version>
</dependency>
</dependencies>
<configuration>
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/org/qubitpi/wilhelm/web/endpoints/DataServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.QueryConfig;
import org.neo4j.driver.Value;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.types.InternalTypeSystem;
import org.qubitpi.wilhelm.config.ApplicationConfig;

Expand All @@ -42,13 +41,9 @@
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -136,17 +131,14 @@ public Response getVocabularyByLanguagePaged(
LANGUAGES.get(language), (Integer.parseInt(page) - 1) * Integer.parseInt(perPage), perPage
);

EagerResult result = executeNativeQuery(query);
final EagerResult result = executeNativeQuery(query);

Object responseBody = result.records()
final Object responseBody = result.records()
.stream()
.map(
record -> record.keys()
.stream()
.map(key -> new AbstractMap.SimpleImmutableEntry<>(
key,
expand(record.get(key))
))
.map(key -> new AbstractMap.SimpleImmutableEntry<>(key, expand(record.get(key))))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)
.collect(Collectors.toList());
Expand All @@ -167,6 +159,7 @@ record -> record.keys()
@GET
@Path("/expand/{word}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("MultipleStringLiterals")
public Response expand(@NotNull @PathParam("word") final String word) {
final String query = String.format(
"""
Expand All @@ -181,9 +174,10 @@ RETURN path, length(path) AS hops

final EagerResult result = executeNativeQuery(query);

final Map<String, List<Map<String, Object>>> responseBody = new HashMap<>();
responseBody.put("nodes", new ArrayList<>());
responseBody.put("links", new ArrayList<>());
final Map<String, List<Map<String, Object>>> responseBody = Map.of(
"nodes", new ArrayList<>(),
"links", new ArrayList<>()
);

result.records().stream()
.map(record -> record.get("path").asPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.qubitpi.wilhelm.web.endpoints

import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.Matchers.hasKey
import static org.hamcrest.Matchers.matchesPattern

import org.hamcrest.Description
import org.hamcrest.Matcher
Expand Down Expand Up @@ -89,7 +91,7 @@ class DataServletITSpec extends Specification {
.statusCode(200)
}

def "Get vocabulary by language and retrieve the very first word"() {
def "Get vocabulary by language returns a list of map, with each entry containing 'term' and 'definition' keys"() {
expect:
RestAssured
.given()
Expand All @@ -100,10 +102,11 @@ class DataServletITSpec extends Specification {
.get("/data/languages/german")
.then()
.statusCode(200)
.body("[0]", equalTo([term: "dieser", definition: "this"]))
.body("[0]", hasKey("term"))
.body("[0]", hasKey("definition"))
}

def "Expand"() {
def "Expand a word returns a map of two keys - 'nodes' & 'links'"() {
expect:
RestAssured
.given()
Expand All @@ -113,6 +116,10 @@ class DataServletITSpec extends Specification {
.get("/data/expand/nämlich")
.then()
.statusCode(200)
.body("[0]", equalTo([term: "dieser", definition: "this"]))
.body("", hasKey("nodes"))
.body("", hasKey("links"))
.body("nodes[0]", hasKey("id"))
.body("links[0]", hasKey("sourceNodeId"))
.body("links[0]", hasKey("targetNodeId"))
}
}

0 comments on commit 0eebf20

Please sign in to comment.