Part3 - Move common operations to EntityRepository class

This commit is contained in:
sureshms 2021-10-21 22:43:26 -07:00
parent 282e894dfe
commit 1b6e5fe780
21 changed files with 22 additions and 73 deletions

View File

@ -73,12 +73,6 @@ public class ChartRepositoryHelper extends EntityRepository<Chart>{
return EntityUtil.listBefore(this, Chart.class, fields, serviceName, limitParam, before);
}
@Transaction
public Chart getByName(String fqn, Fields fields) throws IOException {
Chart chart = repo3.chartDAO().findEntityByName(fqn);
return setFields(chart, fields);
}
@Transaction
public Chart create(Chart chart) throws IOException {
validateRelationships(chart);

View File

@ -89,12 +89,6 @@ public class DashboardRepositoryHelper extends EntityRepository<Dashboard> {
return EntityUtil.listBefore(this, Dashboard.class, fields, serviceName, limitParam, before);
}
@Transaction
public Dashboard getByName(String fqn, Fields fields) throws IOException {
Dashboard dashboard = repo3.dashboardDAO().findEntityByName(fqn);
return setFields(dashboard, fields);
}
@Transaction
public Dashboard create(Dashboard dashboard) throws IOException {
validateRelationships(dashboard);

View File

@ -88,12 +88,6 @@ public class DatabaseRepositoryHelper extends EntityRepository<Database> {
return EntityUtil.listBefore(this, Database.class, fields, serviceName, limitParam, before);
}
@Transaction
public Database getByName(String fqn, Fields fields) throws IOException {
Database database = repo3.databaseDAO().findEntityByName(fqn);
return setFields(database, fields);
}
@Transaction
public Database create(Database database) throws IOException {
validateRelationships(database);

View File

@ -1,6 +1,7 @@
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.Fields;
import org.openmetadata.catalog.util.ResultList;
@ -44,6 +45,11 @@ public abstract class EntityRepository<T> {
return setFields(dao.findEntityById(id), fields);
}
@Transaction
public final T getByName(String fqn, Fields fields) throws IOException, ParseException {
return setFields(dao.findEntityByName(fqn), fields);
}
/**
* Entity related operations
*/

View File

@ -108,12 +108,6 @@ public class ModelRepositoryHelper extends EntityRepository<Model> {
return new ModelList(models, beforeCursor, afterCursor, total);
}
@Transaction
public Model getByName(String fqn, Fields fields) throws IOException {
Model model = repo3.modelDAO().findEntityByName(fqn);
return setFields(model, fields);
}
@Transaction
public Model create(Model model) throws IOException {
validateRelationships(model);

View File

@ -117,12 +117,6 @@ public class PipelineRepositoryHelper extends EntityRepository<Pipeline> {
return EntityUtil.listBefore(entityRepository, Pipeline.class, fields, serviceName, limitParam, before);
}
@Transaction
public Pipeline getByName(String fqn, Fields fields) throws IOException {
Pipeline pipeline = repo3.pipelineDAO().findEntityByName(fqn);
return setFields(pipeline, fields);
}
@Transaction
public Pipeline create(Pipeline pipeline) throws IOException {
validateRelationships(pipeline);

View File

@ -132,11 +132,6 @@ public class TableRepositoryHelper extends EntityRepository<Table> {
return EntityUtil.listBefore(this, Table.class, fields, databaseFQN, limitParam, before);
}
@Transaction
public Table getByName(String fqn, Fields fields) throws IOException, ParseException {
return setFields(repo3.tableDAO().findEntityByName(fqn), fields);
}
@Transaction
public Table create(Table table, UUID databaseId) throws IOException {
validateRelationships(table, databaseId);

View File

@ -106,12 +106,6 @@ public class TaskRepositoryHelper extends EntityRepository<Task>{
return new TaskList(tasks, beforeCursor, afterCursor, total);
}
@Transaction
public Task getByName(String fqn, Fields fields) throws IOException {
Task task = repo3.taskDAO().findEntityByName(fqn);
return setFields(task, fields);
}
@Transaction
public Task create(Task task) throws IOException {
validateRelationships(task);

View File

@ -78,11 +78,6 @@ public class TeamRepositoryHelper extends EntityRepository<Team> {
return team;
}
@Transaction
public Team getByName(String name, Fields fields) throws IOException {
return setFields(repo3.teamDAO().findEntityByName(name), fields);
}
@Transaction
public TeamList listAfter(Fields fields, int limitParam, String after) throws IOException, GeneralSecurityException {
// Forward scrolling, either because after != null or first page is being asked

View File

@ -77,12 +77,6 @@ public class TopicRepositoryHelper extends EntityRepository<Topic> {
return EntityUtil.listBefore(this, Topic.class, fields, serviceName, limitParam, before);
}
@Transaction
public Topic getByName(String fqn, Fields fields) throws IOException {
Topic topic = repo3.topicDAO().findEntityByName(fqn);
return setFields(topic, fields);
}
@Transaction
public Topic create(Topic topic) throws IOException {
validateRelationships(topic);

View File

@ -101,12 +101,6 @@ public class UserRepositoryHelper extends EntityRepository<User> {
return validateUser(id);
}
@Transaction
public User getByName(String name, Fields fields) throws IOException {
User user = repo3.userDAO().findEntityByName(name);
return setFields(user, fields);
}
@Transaction
public User getByEmail(String email, Fields fields) throws IOException {
User user = EntityUtil.validate(email, repo3.userDAO().findByEmail(email), User.class);

View File

@ -199,7 +199,7 @@ public class ChartResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Chart chart = dao.getByName(fqn, fields);
addHref(uriInfo, chart);

View File

@ -203,7 +203,7 @@ public class DashboardResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Dashboard dashboard = dao.getByName(fqn, fields);
return addHref(uriInfo, dashboard);

View File

@ -204,7 +204,7 @@ public class DatabaseResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Database database = dao.getByName(fqn, fields);
addHref(uriInfo, database);

View File

@ -196,7 +196,7 @@ public class ModelResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Model model = dao.getByName(fqn, fields);
return addHref(uriInfo, model);

View File

@ -203,7 +203,7 @@ public class PipelineResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Pipeline pipeline = dao.getByName(fqn, fields);
return addHref(uriInfo, pipeline);

View File

@ -201,7 +201,7 @@ public class TaskResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Task task = dao.getByName(fqn, fields);
addHref(uriInfo, task);

View File

@ -189,7 +189,7 @@ public class TeamResource {
@PathParam("name") String name,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
EntityUtil.Fields fields = new EntityUtil.Fields(FIELD_LIST, fieldsParam);
return addHref(uriInfo, dao.getByName(name, fields));
}

View File

@ -192,7 +192,7 @@ public class UserResource {
@PathParam("name") String name,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
User user = dao.getByName(name, fields);
return addHref(uriInfo, user);
@ -212,7 +212,7 @@ public class UserResource {
public User getCurrentLoggedInUser(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
String currentUserName = securityContext.getUserPrincipal().getName();
User user = dao.getByName(currentUserName, fields);

View File

@ -196,7 +196,7 @@ public class TopicResource {
@Context SecurityContext securityContext,
@Parameter(description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields") String fieldsParam) throws IOException {
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
Fields fields = new Fields(FIELD_LIST, fieldsParam);
Topic topic = dao.getByName(fqn, fields);
addHref(uriInfo, topic);

View File

@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@ -73,7 +74,7 @@ public class DefaultCatalogAuthorizer implements CatalogAuthorizer {
return false;
}
return true;
} catch (IOException | EntityNotFoundException ex) {
} catch (IOException | EntityNotFoundException | ParseException ex) {
return true;
}
})
@ -92,7 +93,7 @@ public class DefaultCatalogAuthorizer implements CatalogAuthorizer {
return false;
}
return true;
} catch (IOException |EntityNotFoundException ex) {
} catch (IOException | EntityNotFoundException | ParseException ex) {
return true;
}
})
@ -121,7 +122,7 @@ public class DefaultCatalogAuthorizer implements CatalogAuthorizer {
return user.getName().equals(owner.getName());
}
return false;
} catch (IOException |EntityNotFoundException ex) {
} catch (IOException | EntityNotFoundException | ParseException ex) {
return false;
}
}
@ -137,7 +138,7 @@ public class DefaultCatalogAuthorizer implements CatalogAuthorizer {
return false;
}
return user.getIsAdmin();
} catch (IOException |EntityNotFoundException ex) {
} catch (IOException | EntityNotFoundException | ParseException ex) {
return false;
}
}
@ -153,7 +154,7 @@ public class DefaultCatalogAuthorizer implements CatalogAuthorizer {
return false;
}
return user.getIsBot();
} catch (IOException |EntityNotFoundException ex) {
} catch (IOException | EntityNotFoundException | ParseException ex) {
return false;
}
}