summaryrefslogtreecommitdiffstats
path: root/aai-core
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-06-26 14:12:55 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-06-28 16:14:12 +0200
commit037c33e49b202218261b474439def75d508717f4 (patch)
treea394dc0d4c8ca7e72a11dbed09441225cc49ddf9 /aai-core
parentbdcbdc723dfb3cd4c29fa3cdbe76ceb0df2a8033 (diff)
Update Janusgraph to 0.5.0 in aai-common
- update tinkerpop to 3.4.13 - update janusgraph to 0.5.0 - restore the total-pages header that was accidentally removed in the last pagination commit - remove stateful pagination logic from HttpEntry Issue-ID: AAI-3900 Change-Id: I5fac397ece75136673b8dc3866e10ff15dfdcee3 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-core')
-rw-r--r--aai-core/pom.xml13
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java187
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java15
3 files changed, 20 insertions, 195 deletions
diff --git a/aai-core/pom.xml b/aai-core/pom.xml
index 30820d80..cd78bff2 100644
--- a/aai-core/pom.xml
+++ b/aai-core/pom.xml
@@ -198,6 +198,11 @@ limitations under the License.
</exclusions>
</dependency>
<dependency>
+ <groupId>org.janusgraph</groupId>
+ <artifactId>janusgraph-inmemory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
@@ -282,10 +287,6 @@ limitations under the License.
<version>1.4.01</version>
</dependency>
<dependency>
- <groupId>com.beust</groupId>
- <artifactId>jcommander</artifactId>
- </dependency>
- <dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
@@ -314,10 +315,6 @@ limitations under the License.
<artifactId>activemq-openwire-legacy</artifactId>
</dependency>
<dependency>
- <groupId>com.opencsv</groupId>
- <artifactId>opencsv</artifactId>
- </dependency>
- <dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
diff --git a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
index 7c652079..85c87667 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
@@ -95,11 +95,6 @@ public class HttpEntry {
private boolean processSingle = true;
- private int paginationBucket = -1;
- private int paginationIndex = -1;
- private int totalVertices = 0;
- private int totalPaginationBuckets = 0;
-
@Autowired
private NodeIngestor nodeIngestor;
@@ -178,132 +173,26 @@ public class HttpEntry {
return this;
}
- /**
- * Gets the introspector factory type.
- *
- * @return the introspector factory type
- */
public ModelType getIntrospectorFactoryType() {
return introspectorFactoryType;
}
- /**
- * Gets the query style.
- *
- * @return the query style
- */
public QueryStyle getQueryStyle() {
return queryStyle;
}
- /**
- * Gets the version.
- *
- * @return the version
- */
public SchemaVersion getVersion() {
return version;
}
- /**
- * Gets the loader.
- *
- * @return the loader
- */
public Loader getLoader() {
return loader;
}
- /**
- * Gets the db engine.
- *
- * @return the db engine
- */
public TransactionalGraphEngine getDbEngine() {
return dbEngine;
}
- /**
- * Checks the pagination bucket and pagination index variables to determine whether or not the user
- * requested paginated results
- *
- * @return a boolean true/false of whether the user requested paginated results
- */
- public boolean isPaginated() {
- return this.paginationBucket > -1 && this.paginationIndex > -1;
- }
-
- /**
- * Returns the pagination size
- *
- * @return integer of the size of results to be returned when paginated
- */
- public int getPaginationBucket() {
- return this.paginationBucket;
- }
-
- /**
- * Setter for the pagination bucket variable which stores in this object the size of results to return
- *
- * @param pb
- */
- public void setPaginationBucket(int pb) {
- this.paginationBucket = pb;
- }
-
- /**
- * Getter to return the pagination index requested by the user when requesting paginated results
- *
- * @return
- */
- public int getPaginationIndex() {
- return this.paginationIndex;
- }
-
- /**
- * Sets the pagination index that was passed in by the user, to determine which index or results to retrieve when
- * paginated
- *
- * @param pi
- */
- public void setPaginationIndex(int pi) {
- if (pi == 0) {
- pi = 1;
- }
- this.paginationIndex = pi;
- }
-
- /**
- * Sets the total vertices variables and calculates the amount of pages based on size and total vertices
- *
- * @param totalVertices
- * @param paginationBucketSize
- */
- public void setTotalsForPaging(int totalVertices, int paginationBucketSize) {
- this.totalVertices = totalVertices;
- // set total number of buckets equal to full pages
- this.totalPaginationBuckets = totalVertices / paginationBucketSize;
- // conditionally add a page for the remainder
- if (totalVertices % paginationBucketSize > 0) {
- this.totalPaginationBuckets++;
- }
- }
-
- /**
- * @return the total amount of pages
- */
- public int getTotalPaginationBuckets() {
- return this.totalPaginationBuckets;
- }
-
- /**
- *
- * @return the total number of vertices when paginated
- */
- public int getTotalVertices() {
- return this.totalVertices;
- }
-
public Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests, String sourceOfTruth) throws AAIException {
return this.process(requests, sourceOfTruth, true);
}
@@ -679,8 +568,10 @@ public class HttpEntry {
) {
String myvertid = v.id().toString();
if (paginationResult != null && paginationResult.getTotalCount() != null) {
+ long totalPages = getTotalPages(queryOptions, paginationResult);
response = Response.status(status).header("vertex-id", myvertid)
.header("total-results", paginationResult.getTotalCount())
+ .header("total-pages", totalPages)
.entity(result)
.type(outputMediaType).build();
} else {
@@ -741,6 +632,17 @@ public class HttpEntry {
return Pair.with(success, responses);
}
+ private long getTotalPages(QueryOptions queryOptions, PaginationResult<Vertex> paginationResult) {
+ long totalCount = paginationResult.getTotalCount();
+ int pageSize = queryOptions.getPageable().getPageSize();
+ long totalPages = totalCount / pageSize;
+ // conditionally add a page for the remainder
+ if (totalCount % pageSize > 0) {
+ totalPages++;
+ }
+ return totalPages;
+ }
+
private List<Vertex> executeQuery(QueryParser query, QueryOptions queryOptions) {
return (queryOptions != null && queryOptions.getSort() != null)
? query.getQueryBuilder().sort(queryOptions.getSort()).toList()
@@ -1122,67 +1024,4 @@ public class HttpEntry {
}
}
}
-
- public void setPaginationParameters(String resultIndex, String resultSize) {
- if (resultIndex != null && !"-1".equals(resultIndex) && resultSize != null && !"-1".equals(resultSize)) {
- this.setPaginationIndex(Integer.parseInt(resultIndex));
- this.setPaginationBucket(Integer.parseInt(resultSize));
- }
- }
-
- @Deprecated
- public List<Object> getPaginatedVertexListForAggregateFormat(List<Object> aggregateVertexList) throws AAIException {
- List<Object> finalList = new Vector<>();
- if (this.isPaginated()) {
- if (aggregateVertexList != null && !aggregateVertexList.isEmpty()) {
- int listSize = aggregateVertexList.size();
- if (listSize == 1) {
- List<Object> vertexList = (List<Object>) aggregateVertexList.get(0);
- this.setTotalsForPaging(vertexList.size(), this.getPaginationBucket());
- int startIndex = (this.getPaginationIndex() - 1) * this.getPaginationBucket();
- int endIndex =
- Math.min((this.getPaginationBucket() * this.getPaginationIndex()), vertexList.size());
- if (startIndex > endIndex) {
- throw new AAIException("AAI_6150",
- " ResultIndex is not appropriate for the result set, Needs to be <= " + endIndex);
- }
- finalList.add(new ArrayList<Object>());
- for (int i = startIndex; i < endIndex; i++) {
- ((ArrayList<Object>) finalList.get(0))
- .add(((ArrayList<Object>) aggregateVertexList.get(0)).get(i));
- }
- return finalList;
- }
- }
- }
- // If the list size is greater than 1 or if pagination is not needed, return the original list.
- return aggregateVertexList;
- }
-
- /**
- * This method is used to paginate the vertex list based on the pagination index and bucket size
- *
- * @deprecated
- * This method is no longer supported. Use {@link #process(List, String, Set, boolean, QueryOptions)} instead.
- * @param vertexList
- * @return
- * @throws AAIException
- */
- @Deprecated
- public List<Object> getPaginatedVertexList(List<Object> vertexList) throws AAIException {
- List<Object> vertices;
- if (this.isPaginated()) {
- this.setTotalsForPaging(vertexList.size(), this.getPaginationBucket());
- int startIndex = (this.getPaginationIndex() - 1) * this.getPaginationBucket();
- int endIndex = Math.min((this.getPaginationBucket() * this.getPaginationIndex()), vertexList.size());
- if (startIndex > endIndex) {
- throw new AAIException("AAI_6150",
- " ResultIndex is not appropriate for the result set, Needs to be <= " + endIndex);
- }
- vertices = vertexList.subList(startIndex, endIndex);
- } else {
- vertices = vertexList;
- }
- return vertices;
- }
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
index 0dcec24d..3bf991ec 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
@@ -319,8 +319,10 @@ public class HttpEntryTest extends AAISetup {
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, queryOptions);
JSONObject actualResponseBody = new JSONObject(response.getEntity().toString());
String totalCount = response.getHeaderString("total-results");
+ String totalPages = response.getHeaderString("total-pages");
assertEquals(2, Integer.parseInt(totalCount));
+ assertEquals(2, Integer.parseInt(totalPages));
assertEquals(1, actualResponseBody.getJSONArray("pserver").length());
assertEquals("Expected the pservers to be returned", 200, response.getStatus());
verify(validationService, times(1)).validate(any());
@@ -986,19 +988,6 @@ public class HttpEntryTest extends AAISetup {
}
@Test
- public void testSetGetPaginationMethods() {
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
- traversalHttpEntry.setPaginationBucket(10);
- traversalHttpEntry.setPaginationIndex(1);
- traversalHttpEntry.setTotalsForPaging(101, traversalHttpEntry.getPaginationBucket());
- assertEquals("Expected the pagination bucket size to be 10", 10, traversalHttpEntry.getPaginationBucket());
- assertEquals("Expected the total number of pagination buckets to be 11", 11,
- traversalHttpEntry.getTotalPaginationBuckets());
- assertEquals("Expected the pagination index to be 1", 1, traversalHttpEntry.getPaginationIndex());
- assertEquals("Expected the total amount of vertices to be 101", 101, traversalHttpEntry.getTotalVertices());
- }
-
- @Test
public void setDepthTest() throws AAIException {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/main/test/resources");