mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-29 17:49:14 +00:00
Move listAfter to EntityRepository and remove other implementations
This commit is contained in:
parent
a10861e444
commit
d686738863
@ -39,7 +39,7 @@ public class CatalogHealthCheck extends HealthCheck {
|
||||
@Override
|
||||
protected Result check() throws Exception {
|
||||
try {
|
||||
userRepositoryHelper.listAfter(fields, 1, "");
|
||||
userRepositoryHelper.listAfter(fields, null, 1, "");
|
||||
return Result.healthy();
|
||||
} catch (IOException e) {
|
||||
return Result.unhealthy(e.getMessage());
|
||||
|
||||
@ -51,7 +51,7 @@ public class ChartRepositoryHelper extends EntityRepository<Chart>{
|
||||
private static final Fields CHART_PATCH_FIELDS = new Fields(ChartResource.FIELD_LIST, "owner,service,tags");
|
||||
|
||||
public ChartRepositoryHelper(ChartRepository3 repo3) {
|
||||
super(repo3.chartDAO());
|
||||
super(Chart.class, repo3.chartDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -61,12 +61,6 @@ public class ChartRepositoryHelper extends EntityRepository<Chart>{
|
||||
return (chart.getService().getName() + "." + chart.getName());
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Chart> listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
return EntityUtil.listAfter(this, Chart.class, fields, serviceName, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Chart> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
|
||||
@ -56,7 +56,7 @@ public class DashboardRepositoryHelper extends EntityRepository<Dashboard> {
|
||||
"owner,service,tags,charts");
|
||||
|
||||
public DashboardRepositoryHelper(DashboardRepository3 repo3) {
|
||||
super(repo3.dashboardDAO());
|
||||
super(Dashboard.class, repo3.dashboardDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -77,12 +77,6 @@ public class DashboardRepositoryHelper extends EntityRepository<Dashboard> {
|
||||
return new DashboardList(entities, beforeCursor, afterCursor, total);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Dashboard> listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
return EntityUtil.listAfter(this, Dashboard.class, fields, serviceName, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Dashboard> listBefore(Fields fields, String serviceName, int limitParam, String before)
|
||||
throws IOException, GeneralSecurityException, ParseException {
|
||||
|
||||
@ -42,7 +42,7 @@ public class DashboardServiceRepositoryHelper extends EntityRepository<Dashboard
|
||||
private final DashboardServiceRepository3 repo3;
|
||||
|
||||
public DashboardServiceRepositoryHelper(DashboardServiceRepository3 repo3) {
|
||||
super(repo3.dashboardServiceDAO());
|
||||
super(DashboardService.class, repo3.dashboardServiceDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ public class DatabaseRepositoryHelper extends EntityRepository<Database> {
|
||||
"owner,service, usageSummary");
|
||||
|
||||
public DatabaseRepositoryHelper(DatabaseRepository3 repo3) {
|
||||
super(repo3.databaseDAO());
|
||||
super(Database.class, repo3.databaseDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -76,12 +76,6 @@ public class DatabaseRepositoryHelper extends EntityRepository<Database> {
|
||||
return refList;
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Database> listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
return EntityUtil.listAfter(this, Database.class, fields, serviceName, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Database> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
|
||||
@ -42,7 +42,7 @@ public class DatabaseServiceRepositoryHelper extends EntityRepository<DatabaseSe
|
||||
private final DatabaseServiceRepository3 repo3;
|
||||
|
||||
public DatabaseServiceRepositoryHelper(DatabaseServiceRepository3 repo3) {
|
||||
super(repo3.dbServiceDAO());
|
||||
super(DatabaseService.class, repo3.dbServiceDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||
import org.openmetadata.catalog.util.JsonUtils;
|
||||
import org.openmetadata.catalog.util.ResultList;
|
||||
import org.openmetadata.common.utils.CipherText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -17,18 +18,34 @@ import java.util.List;
|
||||
* This gives a uniform access so that common boiler plate code can be reduced.
|
||||
*/
|
||||
public abstract class EntityRepository<T> {
|
||||
private final Class<T> entityClass;
|
||||
private final EntityDAO<T> dao;
|
||||
|
||||
EntityRepository(EntityDAO<T> entityDAO) {
|
||||
EntityRepository(Class<T> entityClass, EntityDAO<T> entityDAO) {
|
||||
this.entityClass = entityClass;
|
||||
this.dao = entityDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* DAO related operations
|
||||
*/
|
||||
@Transaction
|
||||
public final List<String> listAfter(String fqnPrefix, int limitParam, String after) {
|
||||
return dao.listAfter(fqnPrefix, limitParam, after);
|
||||
public final ResultList<T> listAfter(Fields fields, String fqnPrefix, int limitParam, String after)
|
||||
throws GeneralSecurityException, IOException, ParseException {
|
||||
// forward scrolling, if after == null then first page is being asked
|
||||
List<String> jsons = dao.listAfter(fqnPrefix, limitParam + 1, after == null ? "" :
|
||||
CipherText.instance().decrypt(after));
|
||||
|
||||
List<T> entities = new ArrayList<>();
|
||||
for (String json : jsons) {
|
||||
entities.add(setFields(JsonUtils.readValue(json, entityClass), fields));
|
||||
}
|
||||
int total = dao.listCount(fqnPrefix);
|
||||
|
||||
String beforeCursor, afterCursor = null;
|
||||
beforeCursor = after == null ? null : getFullyQualifiedName(entities.get(0));
|
||||
if (entities.size() > limitParam) { // If extra result exists, then next page exists - return after cursor
|
||||
entities.remove(limitParam);
|
||||
afterCursor = getFullyQualifiedName(entities.get(limitParam - 1));
|
||||
}
|
||||
return getResultList(entities, beforeCursor, afterCursor, total);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
|
||||
@ -41,7 +41,7 @@ public class MessagingServiceRepositoryHelper extends EntityRepository<Messaging
|
||||
private final MessagingServiceRepository3 repo3;
|
||||
|
||||
public MessagingServiceRepositoryHelper(MessagingServiceRepository3 repo3) {
|
||||
super(repo3.messagingServiceDAO());
|
||||
super(MessagingService.class, repo3.messagingServiceDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ public class MetricsRepositoryHelper extends EntityRepository<Metrics> {
|
||||
private static final Fields METRICS_UPDATE_FIELDS = new Fields(MetricsResource.FIELD_LIST, "owner,service");
|
||||
|
||||
public MetricsRepositoryHelper(MetricsRepository3 repo3) {
|
||||
super(repo3.metricsDAO());
|
||||
super(Metrics.class, repo3.metricsDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ public class ModelRepositoryHelper extends EntityRepository<Model> {
|
||||
"owner,dashboard,tags");
|
||||
|
||||
public ModelRepositoryHelper(ModelRepository3 repo3) {
|
||||
super(repo3.modelDAO());
|
||||
super(Model.class, repo3.modelDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ public class PipelineRepositoryHelper extends EntityRepository<Pipeline> {
|
||||
"owner,service,tags,tasks");
|
||||
|
||||
public PipelineRepositoryHelper(PipelineRepository3 repo3) {
|
||||
super(repo3.pipelineDAO());
|
||||
super(Pipeline.class, repo3.pipelineDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -65,24 +65,6 @@ public class PipelineRepositoryHelper extends EntityRepository<Pipeline> {
|
||||
return (pipeline.getService().getName() + "." + pipeline.getName());
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public PipelineList listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException {
|
||||
// forward scrolling, if after == null then first page is being asked being asked
|
||||
List<String> jsons = repo3.pipelineDAO().listAfter(serviceName, limitParam + 1, after == null ? "" :
|
||||
CipherText.instance().decrypt(after));
|
||||
|
||||
List<Pipeline> pipelines = new ArrayList<>();
|
||||
for (String json : jsons) {
|
||||
pipelines.add(setFields(JsonUtils.readValue(json, Pipeline.class), fields));
|
||||
}
|
||||
int total = repo3.pipelineDAO().listCount(serviceName);
|
||||
|
||||
@Override
|
||||
public int listCount(String fqnPrefix) {
|
||||
return pipelineDAO().listCount(fqnPrefix);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public PipelineList listBefore(Fields fields, String serviceName, int limitParam, String before)
|
||||
throws IOException, GeneralSecurityException {
|
||||
|
||||
@ -40,7 +40,7 @@ import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityN
|
||||
|
||||
public class PipelineServiceRepositoryHelper extends EntityRepository<PipelineService> {
|
||||
public PipelineServiceRepositoryHelper(PipelineServiceRepository3 repo3) {
|
||||
super(repo3.pipelineServiceDAO());
|
||||
super(PipelineService.class, repo3.pipelineServiceDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ public class ReportRepositoryHelper extends EntityRepository<Report>{
|
||||
private static final Fields REPORT_UPDATE_FIELDS = new Fields(ReportResource.FIELD_LIST, "owner,service");
|
||||
|
||||
public ReportRepositoryHelper(ReportRepository3 repo3) {
|
||||
super(repo3.reportDAO());
|
||||
super(Report.class, repo3.reportDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ public class TableRepositoryHelper extends EntityRepository<Table> {
|
||||
"owner,columns,database,tags,tableConstraints");
|
||||
|
||||
public TableRepositoryHelper(TableRepository3 repo3) {
|
||||
super(repo3.tableDAO());
|
||||
super(Table.class, repo3.tableDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -120,12 +120,6 @@ public class TableRepositoryHelper extends EntityRepository<Table> {
|
||||
return (table.getDatabase().getName() + "." + table.getName());
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Table> listAfter(Fields fields, String databaseFQN, int limitParam, String after)
|
||||
throws IOException, ParseException, GeneralSecurityException {
|
||||
return EntityUtil.listAfter(this, Table.class, fields, databaseFQN, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Table> listBefore(Fields fields, String databaseFQN, int limitParam, String before)
|
||||
throws IOException, ParseException, GeneralSecurityException {
|
||||
|
||||
@ -58,33 +58,12 @@ public class TaskRepositoryHelper extends EntityRepository<Task>{
|
||||
}
|
||||
|
||||
public TaskRepositoryHelper(TaskRepository3 repo3) {
|
||||
super(repo3.taskDAO());
|
||||
super(Task.class,repo3.taskDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
private final TaskRepository3 repo3;
|
||||
|
||||
@Transaction
|
||||
public TaskList listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException {
|
||||
// forward scrolling, if after == null then first page is being asked being asked
|
||||
List<String> jsons = repo3.taskDAO().listAfter(serviceName, limitParam + 1, after == null ? "" :
|
||||
CipherText.instance().decrypt(after));
|
||||
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
for (String json : jsons) {
|
||||
tasks.add(setFields(JsonUtils.readValue(json, Task.class), fields));
|
||||
}
|
||||
int total = repo3.taskDAO().listCount(serviceName);
|
||||
|
||||
String beforeCursor, afterCursor = null;
|
||||
beforeCursor = after == null ? null : tasks.get(0).getFullyQualifiedName();
|
||||
if (tasks.size() > limitParam) { // If extra result exists, then next page exists - return after cursor
|
||||
tasks.remove(limitParam);
|
||||
afterCursor = tasks.get(limitParam - 1).getFullyQualifiedName();
|
||||
}
|
||||
return new TaskList(tasks, beforeCursor, afterCursor, total);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public TaskList listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
|
||||
|
||||
@ -51,7 +51,7 @@ public class TeamRepositoryHelper extends EntityRepository<Team> {
|
||||
static final Fields TEAM_PATCH_FIELDS = new Fields(TeamResource.FIELD_LIST, "profile,users");
|
||||
|
||||
public TeamRepositoryHelper(TeamRepository3 repo3) {
|
||||
super(repo3.teamDAO());
|
||||
super(Team.class,repo3.teamDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
|
||||
@ -59,18 +59,12 @@ public class TopicRepositoryHelper extends EntityRepository<Topic> {
|
||||
}
|
||||
|
||||
public TopicRepositoryHelper(TopicRepository3 repo3) {
|
||||
super(repo3.topicDAO());
|
||||
super(Topic.class, repo3.topicDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
private final TopicRepository3 repo3;
|
||||
|
||||
@Transaction
|
||||
public ResultList<Topic> listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
return EntityUtil.listAfter(this, Topic.class, fields, serviceName, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<Topic> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
|
||||
@ -63,7 +63,7 @@ public class UserRepositoryHelper extends EntityRepository<User> {
|
||||
|
||||
|
||||
public UserRepositoryHelper(UserRepository3 repo3) {
|
||||
super(repo3.userDAO());
|
||||
super(User.class,repo3.userDAO());
|
||||
this.repo3 = repo3;
|
||||
}
|
||||
|
||||
@ -84,12 +84,6 @@ public class UserRepositoryHelper extends EntityRepository<User> {
|
||||
return new UserList(entities, beforeCursor, afterCursor, total);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<User> listAfter(Fields fields, int limitParam, String after) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
return EntityUtil.listAfter(this, User.class, fields, null, limitParam, after);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public ResultList<User> listBefore(Fields fields, int limitParam, String before) throws IOException,
|
||||
GeneralSecurityException, ParseException {
|
||||
|
||||
@ -136,25 +136,25 @@ public class PipelineResource {
|
||||
schema = @Schema(implementation = PipelineList.class)))
|
||||
})
|
||||
public ResultList<Pipeline> list(@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "Fields requested in the returned resource",
|
||||
schema = @Schema(type = "string", example = FIELDS))
|
||||
@QueryParam("fields") String fieldsParam,
|
||||
@Parameter(description = "Filter pipelines by service name",
|
||||
schema = @Schema(type = "string", example = "airflow"))
|
||||
@QueryParam("service") String serviceParam,
|
||||
@Parameter(description = "Limit the number pipelines returned. (1 to 1000000, " +
|
||||
"default = 10)")
|
||||
@DefaultValue("10")
|
||||
@Min(1)
|
||||
@Max(1000000)
|
||||
@QueryParam("limit") int limitParam,
|
||||
@Parameter(description = "Returns list of pipelines before this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("before") String before,
|
||||
@Parameter(description = "Returns list of pipelines after this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("after") String after
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "Fields requested in the returned resource",
|
||||
schema = @Schema(type = "string", example = FIELDS))
|
||||
@QueryParam("fields") String fieldsParam,
|
||||
@Parameter(description = "Filter pipelines by service name",
|
||||
schema = @Schema(type = "string", example = "airflow"))
|
||||
@QueryParam("service") String serviceParam,
|
||||
@Parameter(description = "Limit the number pipelines returned. (1 to 1000000, " +
|
||||
"default = 10)")
|
||||
@DefaultValue("10")
|
||||
@Min(1)
|
||||
@Max(1000000)
|
||||
@QueryParam("limit") int limitParam,
|
||||
@Parameter(description = "Returns list of pipelines before this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("before") String before,
|
||||
@Parameter(description = "Returns list of pipelines after this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("after") String after
|
||||
) throws IOException, GeneralSecurityException, ParseException {
|
||||
RestUtil.validateCursors(before, after);
|
||||
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
||||
|
||||
@ -29,7 +29,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import org.openmetadata.catalog.api.data.CreateTask;
|
||||
import org.openmetadata.catalog.entity.data.Task;
|
||||
import org.openmetadata.catalog.jdbi3.TaskRepositoryHelper;
|
||||
import org.openmetadata.catalog.resources.Collection;
|
||||
import org.openmetadata.catalog.security.CatalogAuthorizer;
|
||||
import org.openmetadata.catalog.security.SecurityUtil;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
@ -125,7 +124,6 @@ public class TaskResource {
|
||||
.split(","));
|
||||
|
||||
@GET
|
||||
@Valid
|
||||
@Operation(summary = "List tasks", tags = "tasks",
|
||||
description = "Get a list of tasks, optionally filtered by `service` it belongs to. Use `fields` " +
|
||||
"parameter to get only necessary fields. Use cursor-based pagination to limit the number " +
|
||||
@ -135,30 +133,28 @@ public class TaskResource {
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = TaskList.class)))
|
||||
})
|
||||
public TaskList list(@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "Fields requested in the returned resource",
|
||||
public ResultList<Task> list(@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "Fields requested in the returned resource",
|
||||
schema = @Schema(type = "string", example = FIELDS))
|
||||
@QueryParam("fields") String fieldsParam,
|
||||
@Parameter(description = "Filter tasks by service name",
|
||||
@Parameter(description = "Filter tasks by service name",
|
||||
schema = @Schema(type = "string", example = "superset"))
|
||||
@QueryParam("service") String serviceParam,
|
||||
@Parameter(description = "Limit the number tasks returned. (1 to 1000000, default = 10)")
|
||||
@Parameter(description = "Limit the number tasks returned. (1 to 1000000, default = 10)")
|
||||
@DefaultValue("10")
|
||||
@Min(1)
|
||||
@Max(1000000)
|
||||
@QueryParam("limit") int limitParam,
|
||||
@Parameter(description = "Returns list of tasks before this cursor",
|
||||
@QueryParam("limit") @Min(1) @Max(1000000) int limitParam,
|
||||
@Parameter(description = "Returns list of tasks before this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("before") String before,
|
||||
@Parameter(description = "Returns list of tasks after this cursor",
|
||||
@Parameter(description = "Returns list of tasks after this cursor",
|
||||
schema = @Schema(type = "string"))
|
||||
@QueryParam("after") String after
|
||||
) throws IOException, GeneralSecurityException {
|
||||
) throws IOException, GeneralSecurityException, ParseException {
|
||||
RestUtil.validateCursors(before, after);
|
||||
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
||||
|
||||
TaskList tasks;
|
||||
ResultList<Task> tasks;
|
||||
if (before != null) { // Reverse paging
|
||||
tasks = dao.listBefore(fields, serviceParam, limitParam, before); // Ask for one extra entry
|
||||
} else { // Forward paging or first page
|
||||
|
||||
@ -151,7 +151,7 @@ public class UserResource {
|
||||
if (before != null) { // Reverse paging
|
||||
users = dao.listBefore(fields, limitParam, before);
|
||||
} else { // Forward paging or first page
|
||||
users = dao.listAfter(fields, limitParam, after);
|
||||
users = dao.listAfter(fields, null, limitParam, after);
|
||||
}
|
||||
Optional.ofNullable(users.getData()).orElse(Collections.emptyList()).forEach(u -> addHref(uriInfo, u));
|
||||
return users;
|
||||
|
||||
@ -711,28 +711,6 @@ public final class EntityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> ResultList<T> listAfter(EntityRepository<T> dao, Class<T> clz, Fields fields, String prefixFqn,
|
||||
int limitParam, String after)
|
||||
throws IOException, ParseException, GeneralSecurityException {
|
||||
// forward scrolling, if after == null then first page is being asked
|
||||
List<String> jsons = dao.listAfter(prefixFqn, limitParam + 1, after == null ? "" :
|
||||
CipherText.instance().decrypt(after));
|
||||
|
||||
List<T> entities = new ArrayList<>();
|
||||
for (String json : jsons) {
|
||||
entities.add(dao.setFields(JsonUtils.readValue(json, clz), fields));
|
||||
}
|
||||
int total = dao.listCount(prefixFqn);
|
||||
|
||||
String beforeCursor, afterCursor = null;
|
||||
beforeCursor = after == null ? null : dao.getFullyQualifiedName(entities.get(0));
|
||||
if (entities.size() > limitParam) { // If extra result exists, then next page exists - return after cursor
|
||||
entities.remove(limitParam);
|
||||
afterCursor = dao.getFullyQualifiedName(entities.get(limitParam - 1));
|
||||
}
|
||||
return dao.getResultList(entities, beforeCursor, afterCursor, total);
|
||||
}
|
||||
|
||||
public static <T> ResultList<T> listBefore(EntityRepository<T> dao, Class<T> clz, Fields fields, String databaseFQN,
|
||||
int limitParam, String before)
|
||||
throws IOException, ParseException, GeneralSecurityException {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user