mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 10:39:30 +00:00 
			
		
		
		
	Added cursor pagination (#1057)
This commit is contained in:
		
							parent
							
								
									bdbb15f581
								
							
						
					
					
						commit
						66a034c825
					
				| @ -16,25 +16,20 @@ | |||||||
| 
 | 
 | ||||||
| package org.openmetadata.catalog.resources.metrics; | package org.openmetadata.catalog.resources.metrics; | ||||||
| 
 | 
 | ||||||
| import com.google.inject.Inject; | import java.io.IOException; | ||||||
| import io.swagger.annotations.Api; | import java.security.GeneralSecurityException; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import java.text.ParseException; | ||||||
| import io.swagger.v3.oas.annotations.Parameter; | import java.util.Arrays; | ||||||
| import io.swagger.v3.oas.annotations.media.Content; | import java.util.Date; | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; | import java.util.List; | ||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | import java.util.Objects; | ||||||
| import org.openmetadata.catalog.entity.data.Metrics; | import java.util.UUID; | ||||||
| import org.openmetadata.catalog.jdbi3.CollectionDAO; |  | ||||||
| import org.openmetadata.catalog.jdbi3.MetricsRepository; |  | ||||||
| import org.openmetadata.catalog.resources.Collection; |  | ||||||
| import org.openmetadata.catalog.security.CatalogAuthorizer; |  | ||||||
| import org.openmetadata.catalog.util.EntityUtil.Fields; |  | ||||||
| import org.openmetadata.catalog.util.RestUtil; |  | ||||||
| import org.openmetadata.catalog.util.RestUtil.PutResponse; |  | ||||||
| import org.openmetadata.catalog.util.ResultList; |  | ||||||
| 
 | 
 | ||||||
| import javax.validation.Valid; | import javax.validation.Valid; | ||||||
|  | import javax.validation.constraints.Max; | ||||||
|  | import javax.validation.constraints.Min; | ||||||
| import javax.ws.rs.Consumes; | import javax.ws.rs.Consumes; | ||||||
|  | import javax.ws.rs.DefaultValue; | ||||||
| import javax.ws.rs.GET; | import javax.ws.rs.GET; | ||||||
| import javax.ws.rs.POST; | import javax.ws.rs.POST; | ||||||
| import javax.ws.rs.PUT; | import javax.ws.rs.PUT; | ||||||
| @ -47,14 +42,25 @@ import javax.ws.rs.core.MediaType; | |||||||
| import javax.ws.rs.core.Response; | import javax.ws.rs.core.Response; | ||||||
| import javax.ws.rs.core.SecurityContext; | import javax.ws.rs.core.SecurityContext; | ||||||
| import javax.ws.rs.core.UriInfo; | import javax.ws.rs.core.UriInfo; | ||||||
| import java.io.IOException; | 
 | ||||||
| import java.security.GeneralSecurityException; | import com.google.inject.Inject; | ||||||
| import java.text.ParseException; | 
 | ||||||
| import java.util.Arrays; | import org.openmetadata.catalog.entity.data.Metrics; | ||||||
| import java.util.Date; | import org.openmetadata.catalog.jdbi3.CollectionDAO; | ||||||
| import java.util.List; | import org.openmetadata.catalog.jdbi3.MetricsRepository; | ||||||
| import java.util.Objects; | import org.openmetadata.catalog.resources.Collection; | ||||||
| import java.util.UUID; | import org.openmetadata.catalog.security.CatalogAuthorizer; | ||||||
|  | import org.openmetadata.catalog.util.EntityUtil.Fields; | ||||||
|  | import org.openmetadata.catalog.util.RestUtil; | ||||||
|  | import org.openmetadata.catalog.util.RestUtil.PutResponse; | ||||||
|  | import org.openmetadata.catalog.util.ResultList; | ||||||
|  | 
 | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.v3.oas.annotations.Operation; | ||||||
|  | import io.swagger.v3.oas.annotations.Parameter; | ||||||
|  | import io.swagger.v3.oas.annotations.media.Content; | ||||||
|  | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
|  | import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||||
| 
 | 
 | ||||||
| @Path("/v1/metrics") | @Path("/v1/metrics") | ||||||
| @Api(value = "Metrics collection", tags = "Metrics collection") | @Api(value = "Metrics collection", tags = "Metrics collection") | ||||||
| @ -97,11 +103,29 @@ public class MetricsResource { | |||||||
|   public ResultList<Metrics> list(@Context UriInfo uriInfo, |   public ResultList<Metrics> list(@Context UriInfo uriInfo, | ||||||
|                                   @Parameter(description = "Fields requested in the returned resource", |                                   @Parameter(description = "Fields requested in the returned resource", | ||||||
|                                   schema = @Schema(type = "string", example = FIELDS)) |                                   schema = @Schema(type = "string", example = FIELDS)) | ||||||
|                           @QueryParam("fields") String fieldsParam) throws IOException, GeneralSecurityException, |                           @QueryParam("fields") String fieldsParam, | ||||||
|           ParseException { |                           @DefaultValue("10") | ||||||
|  |                           @Min(1) | ||||||
|  |                           @Max(1000000) | ||||||
|  |                           @QueryParam("limit") int limitParam, | ||||||
|  |                                   @Parameter(description = "Returns list of tables before this cursor", | ||||||
|  |                                   schema = @Schema(type = "string")) | ||||||
|  |                           @QueryParam("before") String before, | ||||||
|  |                                   @Parameter(description = "Returns list of tables 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); |     Fields fields = new Fields(FIELD_LIST, fieldsParam); | ||||||
|     ResultList<Metrics> metricsList = dao.listAfter(fields, null, 10000, null); | 
 | ||||||
|  |     ResultList<Metrics> metricsList; | ||||||
|  |     if (before != null) { // Reverse paging | ||||||
|  |       metricsList = dao.listBefore(fields, null, limitParam, before); | ||||||
|  |     } else { // Forward paging or first page | ||||||
|  |       metricsList = dao.listAfter(fields, null, limitParam, after); | ||||||
|  |     } | ||||||
|     metricsList.getData().forEach(m -> addHref(uriInfo, m)); |     metricsList.getData().forEach(m -> addHref(uriInfo, m)); | ||||||
|  |      | ||||||
|     return metricsList; |     return metricsList; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,29 +16,20 @@ | |||||||
| 
 | 
 | ||||||
| package org.openmetadata.catalog.resources.services.dashboard; | package org.openmetadata.catalog.resources.services.dashboard; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | import java.io.IOException; | ||||||
| import com.google.inject.Inject; | import java.security.GeneralSecurityException; | ||||||
| import io.swagger.annotations.Api; | import java.text.ParseException; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import java.util.Date; | ||||||
| import io.swagger.v3.oas.annotations.Parameter; | import java.util.List; | ||||||
| import io.swagger.v3.oas.annotations.media.Content; | import java.util.Objects; | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; | import java.util.UUID; | ||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; |  | ||||||
| import org.openmetadata.catalog.api.services.CreateDashboardService; |  | ||||||
| import org.openmetadata.catalog.api.services.UpdateDashboardService; |  | ||||||
| import org.openmetadata.catalog.entity.services.DashboardService; |  | ||||||
| import org.openmetadata.catalog.jdbi3.CollectionDAO; |  | ||||||
| import org.openmetadata.catalog.jdbi3.DashboardServiceRepository; |  | ||||||
| import org.openmetadata.catalog.resources.Collection; |  | ||||||
| import org.openmetadata.catalog.security.CatalogAuthorizer; |  | ||||||
| import org.openmetadata.catalog.security.SecurityUtil; |  | ||||||
| import org.openmetadata.catalog.type.EntityReference; |  | ||||||
| import org.openmetadata.catalog.util.RestUtil; |  | ||||||
| import org.openmetadata.catalog.util.ResultList; |  | ||||||
| 
 | 
 | ||||||
| import javax.validation.Valid; | import javax.validation.Valid; | ||||||
|  | import javax.validation.constraints.Max; | ||||||
|  | import javax.validation.constraints.Min; | ||||||
| import javax.ws.rs.Consumes; | import javax.ws.rs.Consumes; | ||||||
| import javax.ws.rs.DELETE; | import javax.ws.rs.DELETE; | ||||||
|  | import javax.ws.rs.DefaultValue; | ||||||
| import javax.ws.rs.GET; | import javax.ws.rs.GET; | ||||||
| import javax.ws.rs.POST; | import javax.ws.rs.POST; | ||||||
| import javax.ws.rs.PUT; | import javax.ws.rs.PUT; | ||||||
| @ -51,13 +42,27 @@ import javax.ws.rs.core.MediaType; | |||||||
| import javax.ws.rs.core.Response; | import javax.ws.rs.core.Response; | ||||||
| import javax.ws.rs.core.SecurityContext; | import javax.ws.rs.core.SecurityContext; | ||||||
| import javax.ws.rs.core.UriInfo; | import javax.ws.rs.core.UriInfo; | ||||||
| import java.io.IOException; | 
 | ||||||
| import java.security.GeneralSecurityException; | import com.google.inject.Inject; | ||||||
| import java.text.ParseException; | 
 | ||||||
| import java.util.Date; | import org.openmetadata.catalog.api.services.CreateDashboardService; | ||||||
| import java.util.List; | import org.openmetadata.catalog.api.services.UpdateDashboardService; | ||||||
| import java.util.Objects; | import org.openmetadata.catalog.entity.services.DashboardService; | ||||||
| import java.util.UUID; | import org.openmetadata.catalog.jdbi3.CollectionDAO; | ||||||
|  | import org.openmetadata.catalog.jdbi3.DashboardServiceRepository; | ||||||
|  | import org.openmetadata.catalog.resources.Collection; | ||||||
|  | import org.openmetadata.catalog.security.CatalogAuthorizer; | ||||||
|  | import org.openmetadata.catalog.security.SecurityUtil; | ||||||
|  | import org.openmetadata.catalog.type.EntityReference; | ||||||
|  | import org.openmetadata.catalog.util.RestUtil; | ||||||
|  | import org.openmetadata.catalog.util.ResultList; | ||||||
|  | 
 | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.v3.oas.annotations.Operation; | ||||||
|  | import io.swagger.v3.oas.annotations.Parameter; | ||||||
|  | import io.swagger.v3.oas.annotations.media.Content; | ||||||
|  | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
|  | import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||||
| 
 | 
 | ||||||
| @Path("/v1/services/dashboardServices") | @Path("/v1/services/dashboardServices") | ||||||
| @Api(value = "Dashboard service collection", tags = "Services -> Dashboard service collection") | @Api(value = "Dashboard service collection", tags = "Services -> Dashboard service collection") | ||||||
| @ -104,9 +109,29 @@ public class DashboardServiceResource { | |||||||
|                           content = @Content(mediaType = "application/json", |                           content = @Content(mediaType = "application/json", | ||||||
|                           schema = @Schema(implementation = DashboardServiceList.class))) |                           schema = @Schema(implementation = DashboardServiceList.class))) | ||||||
|           }) |           }) | ||||||
|   public ResultList<DashboardService> list(@Context UriInfo uriInfo, @QueryParam("name") String name) throws IOException, GeneralSecurityException, ParseException { |   public ResultList<DashboardService> list(@Context UriInfo uriInfo,  | ||||||
|     ResultList<DashboardService> list = dao.listAfter(null, null, 10000, null); |                                   @QueryParam("name") String name, | ||||||
|  |                                   @DefaultValue("10") | ||||||
|  |                                   @Min(1) | ||||||
|  |                                   @Max(1000000) | ||||||
|  |                                   @QueryParam("limit") int limitParam, | ||||||
|  |                                            @Parameter(description = "Returns list of tables before this cursor", | ||||||
|  |                                            schema = @Schema(type = "string")) | ||||||
|  |                                   @QueryParam("before") String before, | ||||||
|  |                                            @Parameter(description = "Returns list of tables after this cursor", | ||||||
|  |                                            schema = @Schema(type = "string")) | ||||||
|  |                                   @QueryParam("after") String after) | ||||||
|  |           throws IOException, GeneralSecurityException, ParseException { | ||||||
|  |     RestUtil.validateCursors(before, after); | ||||||
|  | 
 | ||||||
|  |     ResultList<DashboardService> list; | ||||||
|  |     if (before != null) { // Reverse paging | ||||||
|  |       list = dao.listBefore(null, null, limitParam, before); | ||||||
|  |     } else { // Forward paging or first page | ||||||
|  |       list = dao.listAfter(null, null, limitParam, after); | ||||||
|  |     } | ||||||
|     list.getData().forEach(d -> addHref(uriInfo, d)); |     list.getData().forEach(d -> addHref(uriInfo, d)); | ||||||
|  | 
 | ||||||
|     return list; |     return list; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,14 +16,35 @@ | |||||||
| 
 | 
 | ||||||
| package org.openmetadata.catalog.resources.services.database; | package org.openmetadata.catalog.resources.services.database; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | import java.io.IOException; | ||||||
|  | import java.security.GeneralSecurityException; | ||||||
|  | import java.text.ParseException; | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Objects; | ||||||
|  | import java.util.UUID; | ||||||
|  | 
 | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import javax.validation.constraints.Max; | ||||||
|  | import javax.validation.constraints.Min; | ||||||
|  | import javax.ws.rs.Consumes; | ||||||
|  | import javax.ws.rs.DELETE; | ||||||
|  | import javax.ws.rs.DefaultValue; | ||||||
|  | import javax.ws.rs.GET; | ||||||
|  | import javax.ws.rs.POST; | ||||||
|  | import javax.ws.rs.PUT; | ||||||
|  | import javax.ws.rs.Path; | ||||||
|  | import javax.ws.rs.PathParam; | ||||||
|  | import javax.ws.rs.Produces; | ||||||
|  | import javax.ws.rs.QueryParam; | ||||||
|  | import javax.ws.rs.core.Context; | ||||||
|  | import javax.ws.rs.core.MediaType; | ||||||
|  | import javax.ws.rs.core.Response; | ||||||
|  | import javax.ws.rs.core.SecurityContext; | ||||||
|  | import javax.ws.rs.core.UriInfo; | ||||||
|  | 
 | ||||||
| import com.google.inject.Inject; | import com.google.inject.Inject; | ||||||
| import io.swagger.annotations.Api; | 
 | ||||||
| import io.swagger.v3.oas.annotations.Operation; |  | ||||||
| import io.swagger.v3.oas.annotations.Parameter; |  | ||||||
| import io.swagger.v3.oas.annotations.media.Content; |  | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; |  | ||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; |  | ||||||
| import org.openmetadata.catalog.api.services.CreateDatabaseService; | import org.openmetadata.catalog.api.services.CreateDatabaseService; | ||||||
| import org.openmetadata.catalog.api.services.UpdateDatabaseService; | import org.openmetadata.catalog.api.services.UpdateDatabaseService; | ||||||
| import org.openmetadata.catalog.entity.services.DatabaseService; | import org.openmetadata.catalog.entity.services.DatabaseService; | ||||||
| @ -36,27 +57,12 @@ import org.openmetadata.catalog.type.EntityReference; | |||||||
| import org.openmetadata.catalog.util.RestUtil; | import org.openmetadata.catalog.util.RestUtil; | ||||||
| import org.openmetadata.catalog.util.ResultList; | import org.openmetadata.catalog.util.ResultList; | ||||||
| 
 | 
 | ||||||
| import javax.validation.Valid; | import io.swagger.annotations.Api; | ||||||
| import javax.ws.rs.Consumes; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| import javax.ws.rs.DELETE; | import io.swagger.v3.oas.annotations.Parameter; | ||||||
| import javax.ws.rs.GET; | import io.swagger.v3.oas.annotations.media.Content; | ||||||
| import javax.ws.rs.POST; | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
| import javax.ws.rs.PUT; | import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||||
| import javax.ws.rs.Path; |  | ||||||
| import javax.ws.rs.PathParam; |  | ||||||
| import javax.ws.rs.Produces; |  | ||||||
| import javax.ws.rs.core.Context; |  | ||||||
| import javax.ws.rs.core.MediaType; |  | ||||||
| import javax.ws.rs.core.Response; |  | ||||||
| import javax.ws.rs.core.SecurityContext; |  | ||||||
| import javax.ws.rs.core.UriInfo; |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.security.GeneralSecurityException; |  | ||||||
| import java.text.ParseException; |  | ||||||
| import java.util.Date; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Objects; |  | ||||||
| import java.util.UUID; |  | ||||||
| 
 | 
 | ||||||
| @Path("/v1/services/databaseServices") | @Path("/v1/services/databaseServices") | ||||||
| @Api(value = "Database service collection", tags = "Services -> Database service collection") | @Api(value = "Database service collection", tags = "Services -> Database service collection") | ||||||
| @ -102,9 +108,29 @@ public class DatabaseServiceResource { | |||||||
|                           content = @Content(mediaType = "application/json", |                           content = @Content(mediaType = "application/json", | ||||||
|                           schema = @Schema(implementation = DatabaseServiceList.class))) |                           schema = @Schema(implementation = DatabaseServiceList.class))) | ||||||
|           }) |           }) | ||||||
|   public ResultList<DatabaseService> list(@Context UriInfo uriInfo) throws IOException, GeneralSecurityException, ParseException { |   public ResultList<DatabaseService> list(@Context UriInfo uriInfo,  | ||||||
|     ResultList<DatabaseService> list = dao.listAfter(null, null, 10000, null); |                               @DefaultValue("10") | ||||||
|  |                               @Min(1) | ||||||
|  |                               @Max(1000000) | ||||||
|  |                               @QueryParam("limit") int limitParam, | ||||||
|  |                                           @Parameter(description = "Returns list of tables before this cursor", | ||||||
|  |                                           schema = @Schema(type = "string")) | ||||||
|  |                               @QueryParam("before") String before, | ||||||
|  |                                           @Parameter(description = "Returns list of tables after this cursor", | ||||||
|  |                                           schema = @Schema(type = "string")) | ||||||
|  |                               @QueryParam("after") String after)  | ||||||
|  |           throws IOException, GeneralSecurityException, ParseException { | ||||||
|  |     RestUtil.validateCursors(before, after); | ||||||
|  | 
 | ||||||
|  |     ResultList<DatabaseService> list; | ||||||
|  |     if(before == null) { | ||||||
|  |       list = dao.listBefore(null, null, limitParam, before); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |       list = dao.listAfter(null, null, limitParam, after); | ||||||
|  |     } | ||||||
|     list.getData().forEach(d -> addHref(uriInfo, d)); |     list.getData().forEach(d -> addHref(uriInfo, d)); | ||||||
|  |      | ||||||
|     return list; |     return list; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 ReyhanPatria
						ReyhanPatria