Move listBefore to EntityRepository and remove other implementations

This commit is contained in:
sureshms 2021-10-22 06:12:20 -07:00
parent d686738863
commit dcf8aaa4eb
11 changed files with 18 additions and 116 deletions

View File

@ -61,12 +61,6 @@ public class ChartRepositoryHelper extends EntityRepository<Chart>{
return (chart.getService().getName() + "." + chart.getName());
}
@Transaction
public ResultList<Chart> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
GeneralSecurityException, ParseException {
return EntityUtil.listBefore(this, Chart.class, fields, serviceName, limitParam, before);
}
@Transaction
public Chart create(Chart chart) throws IOException {
validateRelationships(chart);

View File

@ -77,12 +77,6 @@ public class DashboardRepositoryHelper extends EntityRepository<Dashboard> {
return new DashboardList(entities, beforeCursor, afterCursor, total);
}
@Transaction
public ResultList<Dashboard> listBefore(Fields fields, String serviceName, int limitParam, String before)
throws IOException, GeneralSecurityException, ParseException {
return EntityUtil.listBefore(this, Dashboard.class, fields, serviceName, limitParam, before);
}
@Transaction
public Dashboard create(Dashboard dashboard) throws IOException {
validateRelationships(dashboard);

View File

@ -76,12 +76,6 @@ public class DatabaseRepositoryHelper extends EntityRepository<Database> {
return refList;
}
@Transaction
public ResultList<Database> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
GeneralSecurityException, ParseException {
return EntityUtil.listBefore(this, Database.class, fields, serviceName, limitParam, before);
}
@Transaction
public Database create(Database database) throws IOException {
validateRelationships(database);

View File

@ -49,8 +49,23 @@ public abstract class EntityRepository<T> {
}
@Transaction
public final List<String> listBefore(String fqnPrefix, int limitParam, String before) {
return dao.listBefore(fqnPrefix, limitParam, before);
public final ResultList<T> listBefore(Fields fields, String fqnPrefix, int limitParam, String before) throws IOException, GeneralSecurityException, ParseException {
// Reverse scrolling - Get one extra result used for computing before cursor
List<String> jsons = dao.listBefore(fqnPrefix, limitParam + 1, CipherText.instance().decrypt(before));
List<T> entities = new ArrayList<>();
for (String json : jsons) {
entities.add(setFields(JsonUtils.readValue(json, entityClass), fields));
}
int total = dao.listCount(fqnPrefix);
String beforeCursor = null, afterCursor;
if (entities.size() > limitParam) { // If extra result exists, then previous page exists - return before cursor
entities.remove(0);
beforeCursor = getFullyQualifiedName(entities.get(0));
}
afterCursor = getFullyQualifiedName(entities.get(entities.size() - 1));
return getResultList(entities, beforeCursor, afterCursor, total);
}
@Transaction

View File

@ -64,41 +64,6 @@ public class PipelineRepositoryHelper extends EntityRepository<Pipeline> {
public static String getFQN(Pipeline pipeline) {
return (pipeline.getService().getName() + "." + pipeline.getName());
}
@Transaction
public PipelineList listBefore(Fields fields, String serviceName, int limitParam, String before)
throws IOException, GeneralSecurityException {
// Reverse scrolling - Get one extra result used for computing before cursor
List<String> jsons = repo3.pipelineDAO().listBefore(serviceName, limitParam + 1, CipherText.instance().decrypt(before));
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 Pipeline setFields(Pipeline entity, Fields fields) throws IOException, ParseException {
return PipelineRepository.this.setFields(entity, fields);
}
@Override
public ResultList<Pipeline> getResultList(List<Pipeline> entities, String beforeCursor, String afterCursor, int total) throws GeneralSecurityException, UnsupportedEncodingException {
return new PipelineList(entities, beforeCursor, afterCursor, total);
}
};
@Transaction
public ResultList<Pipeline> listAfter(Fields fields, String serviceName, int limitParam, String after) throws IOException,
GeneralSecurityException, ParseException {
return EntityUtil.listAfter(entityRepository, Pipeline.class, fields, serviceName, limitParam, after);
}
@Transaction
public ResultList<Pipeline> listBefore(Fields fields, String serviceName, int limitParam, String before)
throws IOException, GeneralSecurityException, ParseException {
return EntityUtil.listBefore(entityRepository, Pipeline.class, fields, serviceName, limitParam, before);
}
@Transaction
public Pipeline create(Pipeline pipeline) throws IOException {
validateRelationships(pipeline);

View File

@ -120,12 +120,6 @@ public class TableRepositoryHelper extends EntityRepository<Table> {
return (table.getDatabase().getName() + "." + table.getName());
}
@Transaction
public ResultList<Table> listBefore(Fields fields, String databaseFQN, int limitParam, String before)
throws IOException, ParseException, GeneralSecurityException {
return EntityUtil.listBefore(this, Table.class, fields, databaseFQN, limitParam, before);
}
@Transaction
public Table create(Table table, UUID databaseId) throws IOException {
validateRelationships(table, databaseId);

View File

@ -64,27 +64,6 @@ public class TaskRepositoryHelper extends EntityRepository<Task>{
private final TaskRepository3 repo3;
@Transaction
public TaskList listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
GeneralSecurityException {
// Reverse scrolling - Get one extra result used for computing before cursor
List<String> jsons = repo3.taskDAO().listBefore(serviceName, limitParam + 1, CipherText.instance().decrypt(before));
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 = null, afterCursor;
if (tasks.size() > limitParam) { // If extra result exists, then previous page exists - return before cursor
tasks.remove(0);
beforeCursor = tasks.get(0).getFullyQualifiedName();
}
afterCursor = tasks.get(tasks.size() - 1).getFullyQualifiedName();
return new TaskList(tasks, beforeCursor, afterCursor, total);
}
@Transaction
public Task create(Task task) throws IOException {
validateRelationships(task);

View File

@ -65,12 +65,6 @@ public class TopicRepositoryHelper extends EntityRepository<Topic> {
private final TopicRepository3 repo3;
@Transaction
public ResultList<Topic> listBefore(Fields fields, String serviceName, int limitParam, String before) throws IOException,
GeneralSecurityException, ParseException {
return EntityUtil.listBefore(this, Topic.class, fields, serviceName, limitParam, before);
}
@Transaction
public Topic create(Topic topic) throws IOException {
validateRelationships(topic);

View File

@ -84,12 +84,6 @@ public class UserRepositoryHelper extends EntityRepository<User> {
return new UserList(entities, beforeCursor, afterCursor, total);
}
@Transaction
public ResultList<User> listBefore(Fields fields, int limitParam, String before) throws IOException,
GeneralSecurityException, ParseException {
return EntityUtil.listBefore(this, User.class, fields, null, limitParam, before);
}
@Transaction
public User get(String id) throws IOException {
return validateUser(id);

View File

@ -149,7 +149,7 @@ public class UserResource {
ResultList<User> users;
if (before != null) { // Reverse paging
users = dao.listBefore(fields, limitParam, before);
users = dao.listBefore(fields, null, limitParam, before);
} else { // Forward paging or first page
users = dao.listAfter(fields, null, limitParam, after);
}

View File

@ -711,27 +711,6 @@ public final class EntityUtil {
}
}
public static <T> ResultList<T> listBefore(EntityRepository<T> dao, Class<T> clz, Fields fields, String databaseFQN,
int limitParam, String before)
throws IOException, ParseException, GeneralSecurityException {
// Reverse scrolling - Get one extra result used for computing before cursor
List<String> jsons = dao.listBefore(databaseFQN, limitParam + 1, CipherText.instance().decrypt(before));
List<T> entities = new ArrayList<>();
for (String json : jsons) {
entities.add(dao.setFields(JsonUtils.readValue(json, clz), fields));
}
int total = dao.listCount(databaseFQN);
String beforeCursor = null, afterCursor;
if (entities.size() > limitParam) { // If extra result exists, then previous page exists - return before cursor
entities.remove(0);
beforeCursor = dao.getFullyQualifiedName(entities.get(0));
}
afterCursor = dao.getFullyQualifiedName(entities.get(entities.size() - 1));
return dao.getResultList(entities, beforeCursor, afterCursor, total);
}
public static List<UUID> getIDList(List<EntityReference> refList) {
if (refList == null) {
return null;