mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-12 17:02:23 +00:00
Co-authored-by: Allan Krueger <allankrg@amazon.com>
This commit is contained in:
parent
805839f9f4
commit
67a257a384
@ -17,9 +17,10 @@
|
|||||||
package org.openmetadata.catalog;
|
package org.openmetadata.catalog;
|
||||||
|
|
||||||
import com.codahale.metrics.health.HealthCheck;
|
import com.codahale.metrics.health.HealthCheck;
|
||||||
|
import org.openmetadata.catalog.entity.teams.User;
|
||||||
import org.openmetadata.catalog.jdbi3.UserRepository;
|
import org.openmetadata.catalog.jdbi3.UserRepository;
|
||||||
import org.openmetadata.catalog.resources.teams.UserResource.UserList;
|
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
|
import org.openmetadata.catalog.util.ResultList;
|
||||||
import org.skife.jdbi.v2.DBI;
|
import org.skife.jdbi.v2.DBI;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -38,7 +39,7 @@ public class CatalogHealthCheck extends HealthCheck {
|
|||||||
@Override
|
@Override
|
||||||
protected Result check() throws Exception {
|
protected Result check() throws Exception {
|
||||||
try {
|
try {
|
||||||
UserList users = userRepository.listAfter(fields, 1, "");
|
ResultList<User> users = userRepository.listAfter(fields, 1, "");
|
||||||
return Result.healthy();
|
return Result.healthy();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return Result.unhealthy(e.getMessage());
|
return Result.unhealthy(e.getMessage());
|
||||||
|
|||||||
@ -42,7 +42,7 @@ import org.openmetadata.catalog.util.EntityUtil.Fields;
|
|||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
import org.openmetadata.catalog.util.RestUtil;
|
import org.openmetadata.catalog.util.RestUtil;
|
||||||
import org.openmetadata.catalog.util.RestUtil.PutResponse;
|
import org.openmetadata.catalog.util.RestUtil.PutResponse;
|
||||||
import org.openmetadata.common.utils.CipherText;
|
import org.openmetadata.catalog.util.ResultList;
|
||||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||||
import org.skife.jdbi.v2.sqlobject.CreateSqlObject;
|
import org.skife.jdbi.v2.sqlobject.CreateSqlObject;
|
||||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||||
@ -55,7 +55,9 @@ import javax.json.JsonPatch;
|
|||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -122,45 +124,48 @@ public abstract class UserRepository {
|
|||||||
@CreateSqlObject
|
@CreateSqlObject
|
||||||
abstract ModelDAO modelDAO();
|
abstract ModelDAO modelDAO();
|
||||||
|
|
||||||
|
EntityRepository<User> entityRepository = new EntityRepository<User>() {
|
||||||
|
@Override
|
||||||
|
public List<String> listAfter(String fqnPrefix, int limitParam, String after) {
|
||||||
|
return UserRepository.this.userDAO().listAfter(limitParam, after);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> listBefore(String fqnPrefix, int limitParam, String before) {
|
||||||
|
return UserRepository.this.userDAO().listBefore(limitParam, before);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int listCount(String fqnPrefix) {
|
||||||
|
return UserRepository.this.userDAO().listCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullyQualifiedName(User entity) {
|
||||||
|
// User does not have a FullyQualifiedName but needs a valid field to paginate
|
||||||
|
return entity.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User setFields(User entity, Fields fields) throws IOException, ParseException {
|
||||||
|
return UserRepository.this.setFields(entity, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultList<User> getResultList(List<User> entities, String beforeCursor, String afterCursor,
|
||||||
|
int total) throws GeneralSecurityException, UnsupportedEncodingException {
|
||||||
|
return new UserList(entities, beforeCursor, afterCursor, total);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public UserList listAfter(Fields fields, int limitParam, String after) throws IOException, GeneralSecurityException {
|
public ResultList<User> listAfter(Fields fields, int limitParam, String after) throws IOException, GeneralSecurityException, ParseException {
|
||||||
// forward scrolling, if after == null then first page is being asked being asked
|
return EntityUtil.listAfter(entityRepository, User.class, fields, null, limitParam, after);
|
||||||
List<String> jsons = userDAO().listAfter(limitParam + 1, after == null ? "" :
|
|
||||||
CipherText.instance().decrypt(after));
|
|
||||||
|
|
||||||
List<User> users = new ArrayList<>();
|
|
||||||
for (String json : jsons) {
|
|
||||||
users.add(setFields(JsonUtils.readValue(json, User.class), fields));
|
|
||||||
}
|
|
||||||
int total = userDAO().listCount();
|
|
||||||
|
|
||||||
String beforeCursor, afterCursor = null;
|
|
||||||
beforeCursor = after == null ? null : users.get(0).getName();
|
|
||||||
if (users.size() > limitParam) { // If extra result exists, then next page exists - return after cursor
|
|
||||||
users.remove(limitParam);
|
|
||||||
afterCursor = users.get(limitParam - 1).getName();
|
|
||||||
}
|
|
||||||
return new UserList(users, beforeCursor, afterCursor, total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public UserList listBefore(Fields fields, int limitParam, String before) throws IOException, GeneralSecurityException {
|
public ResultList<User> listBefore(Fields fields, int limitParam, String before) throws IOException, GeneralSecurityException, ParseException {
|
||||||
// Reverse scrolling - Get one extra result used for computing before cursor
|
return EntityUtil.listBefore(entityRepository, User.class, fields, null, limitParam, before);
|
||||||
List<String> jsons = userDAO().listBefore(limitParam + 1, CipherText.instance().decrypt(before));
|
|
||||||
|
|
||||||
List<User> users = new ArrayList<>();
|
|
||||||
for (String json : jsons) {
|
|
||||||
users.add(setFields(JsonUtils.readValue(json, User.class), fields));
|
|
||||||
}
|
|
||||||
int total = userDAO().listCount();
|
|
||||||
|
|
||||||
String beforeCursor = null, afterCursor;
|
|
||||||
if (users.size() > limitParam) { // If extra result exists, then previous page exists - return before cursor
|
|
||||||
users.remove(0);
|
|
||||||
beforeCursor = users.get(0).getName();
|
|
||||||
}
|
|
||||||
afterCursor = users.get(users.size() - 1).getName();
|
|
||||||
return new UserList(users, beforeCursor, afterCursor, total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
|
|||||||
@ -63,6 +63,7 @@ import javax.ws.rs.core.UriInfo;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -125,7 +126,7 @@ public class UserResource {
|
|||||||
content = @Content(mediaType = "application/json",
|
content = @Content(mediaType = "application/json",
|
||||||
schema = @Schema(implementation = UserList.class)))
|
schema = @Schema(implementation = UserList.class)))
|
||||||
})
|
})
|
||||||
public UserList list(@Context UriInfo uriInfo,
|
public ResultList<User> list(@Context UriInfo uriInfo,
|
||||||
@Context SecurityContext securityContext,
|
@Context SecurityContext securityContext,
|
||||||
@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))
|
||||||
@ -141,11 +142,12 @@ public class UserResource {
|
|||||||
@QueryParam("before") String before,
|
@QueryParam("before") String before,
|
||||||
@Parameter(description = "Returns list of users after this cursor",
|
@Parameter(description = "Returns list of users after this cursor",
|
||||||
schema = @Schema(type = "string"))
|
schema = @Schema(type = "string"))
|
||||||
@QueryParam("after") String after) throws IOException, GeneralSecurityException {
|
@QueryParam("after") String after)
|
||||||
|
throws IOException, GeneralSecurityException, ParseException {
|
||||||
RestUtil.validateCursors(before, after);
|
RestUtil.validateCursors(before, after);
|
||||||
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
||||||
|
|
||||||
UserList users;
|
ResultList<User> users;
|
||||||
if (before != null) { // Reverse paging
|
if (before != null) { // Reverse paging
|
||||||
users = dao.listBefore(fields, limitParam, before);
|
users = dao.listBefore(fields, limitParam, before);
|
||||||
} else { // Forward paging or first page
|
} else { // Forward paging or first page
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user