mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 10:39:30 +00:00 
			
		
		
		
	Move listBefore to EntityRepository and remove other implementations
This commit is contained in:
		
							parent
							
								
									d686738863
								
							
						
					
					
						commit
						dcf8aaa4eb
					
				| @ -61,12 +61,6 @@ public class ChartRepositoryHelper extends EntityRepository<Chart>{ | |||||||
|     return (chart.getService().getName() + "." + chart.getName()); |     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 |   @Transaction | ||||||
|   public Chart create(Chart chart) throws IOException { |   public Chart create(Chart chart) throws IOException { | ||||||
|     validateRelationships(chart); |     validateRelationships(chart); | ||||||
|  | |||||||
| @ -77,12 +77,6 @@ public class DashboardRepositoryHelper extends EntityRepository<Dashboard> { | |||||||
|     return new DashboardList(entities, beforeCursor, afterCursor, total); |     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 |   @Transaction | ||||||
|   public Dashboard create(Dashboard dashboard) throws IOException { |   public Dashboard create(Dashboard dashboard) throws IOException { | ||||||
|     validateRelationships(dashboard); |     validateRelationships(dashboard); | ||||||
|  | |||||||
| @ -76,12 +76,6 @@ public class DatabaseRepositoryHelper extends EntityRepository<Database> { | |||||||
|     return refList; |     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 |   @Transaction | ||||||
|   public Database create(Database database) throws IOException { |   public Database create(Database database) throws IOException { | ||||||
|     validateRelationships(database); |     validateRelationships(database); | ||||||
|  | |||||||
| @ -49,8 +49,23 @@ public abstract class EntityRepository<T> { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @Transaction |   @Transaction | ||||||
|   public final List<String> listBefore(String fqnPrefix, int limitParam, String before) { |   public final ResultList<T> listBefore(Fields fields, String fqnPrefix, int limitParam, String before) throws IOException, GeneralSecurityException, ParseException { | ||||||
|     return dao.listBefore(fqnPrefix, limitParam, before); |     // 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 |   @Transaction | ||||||
|  | |||||||
| @ -64,41 +64,6 @@ public class PipelineRepositoryHelper extends EntityRepository<Pipeline> { | |||||||
|   public static String getFQN(Pipeline pipeline) { |   public static String getFQN(Pipeline pipeline) { | ||||||
|     return (pipeline.getService().getName() + "." + pipeline.getName()); |     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 |   @Transaction | ||||||
|   public Pipeline create(Pipeline pipeline) throws IOException { |   public Pipeline create(Pipeline pipeline) throws IOException { | ||||||
|     validateRelationships(pipeline); |     validateRelationships(pipeline); | ||||||
|  | |||||||
| @ -120,12 +120,6 @@ public class TableRepositoryHelper extends EntityRepository<Table> { | |||||||
|     return (table.getDatabase().getName() + "." + table.getName()); |     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 |   @Transaction | ||||||
|   public Table create(Table table, UUID databaseId) throws IOException { |   public Table create(Table table, UUID databaseId) throws IOException { | ||||||
|     validateRelationships(table, databaseId); |     validateRelationships(table, databaseId); | ||||||
|  | |||||||
| @ -64,27 +64,6 @@ public class TaskRepositoryHelper extends EntityRepository<Task>{ | |||||||
| 
 | 
 | ||||||
|   private final TaskRepository3 repo3; |   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 |   @Transaction | ||||||
|   public Task create(Task task) throws IOException { |   public Task create(Task task) throws IOException { | ||||||
|     validateRelationships(task); |     validateRelationships(task); | ||||||
|  | |||||||
| @ -65,12 +65,6 @@ public class TopicRepositoryHelper extends EntityRepository<Topic> { | |||||||
| 
 | 
 | ||||||
|   private final TopicRepository3 repo3; |   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 |   @Transaction | ||||||
|   public Topic create(Topic topic) throws IOException { |   public Topic create(Topic topic) throws IOException { | ||||||
|     validateRelationships(topic); |     validateRelationships(topic); | ||||||
|  | |||||||
| @ -84,12 +84,6 @@ public class UserRepositoryHelper extends EntityRepository<User> { | |||||||
|     return new UserList(entities, beforeCursor, afterCursor, total); |     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 |   @Transaction | ||||||
|   public User get(String id) throws IOException { |   public User get(String id) throws IOException { | ||||||
|     return validateUser(id); |     return validateUser(id); | ||||||
|  | |||||||
| @ -149,7 +149,7 @@ public class UserResource { | |||||||
| 
 | 
 | ||||||
|     ResultList<User> users; |     ResultList<User> users; | ||||||
|     if (before != null) { // Reverse paging |     if (before != null) { // Reverse paging | ||||||
|       users = dao.listBefore(fields, limitParam, before); |       users = dao.listBefore(fields, null, limitParam, before); | ||||||
|     } else { // Forward paging or first page |     } else { // Forward paging or first page | ||||||
|       users = dao.listAfter(fields, null, limitParam, after); |       users = dao.listAfter(fields, null, limitParam, after); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -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) { |   public static List<UUID> getIDList(List<EntityReference> refList) { | ||||||
|     if (refList == null) { |     if (refList == null) { | ||||||
|       return null; |       return null; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 sureshms
						sureshms