-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API for object pagination, count(*) (#288)
Former-commit-id: a389687
- Loading branch information
1 parent
4169bcd
commit 3de8017
Showing
46 changed files
with
545 additions
and
342 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
18 changes: 18 additions & 0 deletions
18
cineast-api/src/main/java/org/vitrivr/cineast/api/messages/general/IntegerMessage.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,18 @@ | ||
package org.vitrivr.cineast.api.messages.general; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class IntegerMessage { | ||
|
||
private final int value; | ||
|
||
@JsonCreator | ||
public IntegerMessage(@JsonProperty("value") int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...src/main/java/org/vitrivr/cineast/api/rest/handlers/actions/bool/CountRowsGetHandler.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,52 @@ | ||
package org.vitrivr.cineast.api.rest.handlers.actions.bool; | ||
|
||
import static org.vitrivr.cineast.api.util.APIConstants.TABLE_NAME; | ||
|
||
import io.javalin.http.Context; | ||
import io.javalin.plugin.openapi.dsl.OpenApiBuilder; | ||
import io.javalin.plugin.openapi.dsl.OpenApiDocumentation; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.vitrivr.cineast.api.messages.general.IntegerMessage; | ||
import org.vitrivr.cineast.api.rest.handlers.interfaces.GetRestHandler; | ||
import org.vitrivr.cineast.standalone.config.Config; | ||
|
||
public class CountRowsGetHandler implements GetRestHandler<IntegerMessage> { | ||
|
||
public static final String ROUTE = "count/table/{" + TABLE_NAME + "}"; | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(CountRowsGetHandler.class); | ||
|
||
@Override | ||
public IntegerMessage doGet(Context ctx) { | ||
try (final var selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get()) { | ||
var tableName = ctx.pathParam(TABLE_NAME); | ||
selector.open(tableName); | ||
var count = selector.rowCount(); | ||
LOGGER.trace("counted {} objects in table {}", count, tableName); | ||
return new IntegerMessage(count); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<IntegerMessage> outClass() { | ||
return IntegerMessage.class; | ||
} | ||
|
||
@Override | ||
public String route() { | ||
return ROUTE; | ||
} | ||
|
||
@Override | ||
public OpenApiDocumentation docs() { | ||
return OpenApiBuilder.document() | ||
.operation(op -> { | ||
op.summary("Count objects"); | ||
op.description("Equivalent to calling SELECT count(*) FROM table. Used to determined #pages for pagination in a frontend or statistical purposes"); | ||
op.operationId("countRows"); | ||
op.addTagsItem("Misc"); | ||
}) | ||
.json("200", outClass()); | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
...vitrivr/cineast/api/rest/handlers/actions/mediaobject/FindObjectPaginationGetHandler.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,66 @@ | ||
package org.vitrivr.cineast.api.rest.handlers.actions.mediaobject; | ||
|
||
import static org.vitrivr.cineast.api.util.APIConstants.LIMIT_NAME; | ||
import static org.vitrivr.cineast.api.util.APIConstants.SKIP_NAME; | ||
|
||
import io.javalin.http.Context; | ||
import io.javalin.plugin.openapi.dsl.OpenApiBuilder; | ||
import io.javalin.plugin.openapi.dsl.OpenApiDocumentation; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.vitrivr.cineast.api.messages.result.MediaObjectQueryResult; | ||
import org.vitrivr.cineast.api.rest.handlers.interfaces.GetRestHandler; | ||
import org.vitrivr.cineast.core.db.dao.reader.MediaObjectReader; | ||
import org.vitrivr.cineast.standalone.config.Config; | ||
|
||
public class FindObjectPaginationGetHandler implements GetRestHandler<MediaObjectQueryResult> { | ||
|
||
public static final String ROUTE = "find/object/all/{" + SKIP_NAME + "}/{" + LIMIT_NAME + "}"; | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(FindObjectPaginationGetHandler.class); | ||
|
||
@Override | ||
public MediaObjectQueryResult doGet(Context ctx) { | ||
final Map<String, String> parameters = ctx.pathParamMap(); | ||
|
||
try (final MediaObjectReader ol = new MediaObjectReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get())) { | ||
final var skipParam = parameters.get(SKIP_NAME); | ||
final var skip = skipParam == null ? 0 : Integer.parseInt(skipParam); | ||
final var limitParam = parameters.get(LIMIT_NAME); | ||
final var limit = limitParam == null ? Integer.MAX_VALUE : Integer.parseInt(limitParam); | ||
|
||
var result = ol.getAllObjects(skip, limit); | ||
LOGGER.trace("returning {} elements for skip {} and limit {}", result.size(), skip, limit); | ||
return new MediaObjectQueryResult("", result); | ||
} catch (Exception e) { | ||
LOGGER.error("Error during request", e); | ||
return new MediaObjectQueryResult("", new ArrayList<>()); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<MediaObjectQueryResult> outClass() { | ||
return MediaObjectQueryResult.class; | ||
} | ||
|
||
@Override | ||
public String route() { | ||
return ROUTE; | ||
} | ||
|
||
@Override | ||
public OpenApiDocumentation docs() { | ||
return OpenApiBuilder.document() | ||
.operation(op -> { | ||
op.summary("Get a fixed amount of objects from the sorted list"); | ||
op.description("Equivalent to calling SELECT * FROM multimediaobject ORDER BY objectid ASC LIMIT limit SKIP skip. Mostly used for pagination when wanting to retrieve all objects"); | ||
op.operationId("findObjectsPagination"); | ||
op.addTagsItem("Object"); | ||
}) | ||
.pathParam(LIMIT_NAME, Integer.class, p -> p.description("How many object at most should be fetched")) | ||
.pathParam(SKIP_NAME, Integer.class, p -> p.description("How many objects should be skipped")) | ||
.json("200", outClass()); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...vitrivr/cineast/api/rest/handlers/actions/metadata/FindObjectMetadataByKeyGetHandler.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
2 changes: 1 addition & 1 deletion
2
...itrivr/cineast/api/rest/handlers/actions/metadata/FindObjectMetadataByKeyPostHandler.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
Oops, something went wrong.