Reduced duplicate code in *Resource.java

This commit is contained in:
debojyotidey 2021-10-27 19:57:12 +05:30
parent d9a35e4b5c
commit 48d95aefca
11 changed files with 133 additions and 170 deletions

View File

@ -217,15 +217,7 @@ public class ChartResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateChart create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Chart chart =
new Chart().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withChartType(create.getChartType()).withChartUrl(create.getChartUrl())
.withTables(create.getTables()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Chart chart = getChart(securityContext, create);
chart = addHref(uriInfo, dao.create(chart));
return Response.created(chart.getHref()).entity(chart).build();
}
@ -267,15 +259,7 @@ public class ChartResource {
@Context SecurityContext securityContext,
@Valid CreateChart create) throws IOException, ParseException {
Chart chart =
new Chart().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withChartType(create.getChartType()).withChartUrl(create.getChartUrl())
.withTables(create.getTables()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Chart chart = getChart(securityContext, create);
PutResponse<Chart> response = dao.createOrUpdate(chart);
chart = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(chart).build();
@ -332,4 +316,15 @@ public class ChartResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Chart getChart(SecurityContext securityContext, CreateChart create) {
return new Chart().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withChartType(create.getChartType()).withChartUrl(create.getChartUrl())
.withTables(create.getTables()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -223,13 +223,7 @@ public class DashboardResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateDashboard create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Dashboard dashboard = new Dashboard().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withCharts(create.getCharts())
.withDashboardUrl(create.getDashboardUrl()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Dashboard dashboard = getDashboard(securityContext, create);
dashboard = addHref(uriInfo, dao.create(dashboard));
return Response.created(dashboard.getHref()).entity(dashboard).build();
}
@ -271,14 +265,7 @@ public class DashboardResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreateDashboard create) throws IOException, ParseException {
Dashboard dashboard = new Dashboard().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withCharts(create.getCharts())
.withDashboardUrl(create.getDashboardUrl()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Dashboard dashboard = getDashboard(securityContext, create);
PutResponse<Dashboard> response = dao.createOrUpdate(dashboard);
dashboard = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(dashboard).build();
@ -335,4 +322,14 @@ public class DashboardResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Dashboard getDashboard(SecurityContext securityContext, CreateDashboard create) {
return new Dashboard().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withCharts(create.getCharts())
.withDashboardUrl(create.getDashboardUrl()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -223,11 +223,7 @@ public class DatabaseResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateDatabase create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Database database = new Database().withId(UUID.randomUUID()).withName(create.getName())
.withDescription(create.getDescription()).withService(create.getService())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Database database = getDatabase(securityContext, create);
database = addHref(uriInfo, dao.create(database));
return Response.created(database.getHref()).entity(database).build();
}
@ -266,11 +262,7 @@ public class DatabaseResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreateDatabase create) throws IOException, ParseException {
Database database = new Database().withId(UUID.randomUUID()).withName(create.getName())
.withDescription(create.getDescription()).withOwner(create.getOwner())
.withService(create.getService()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Database database = getDatabase(securityContext, create);
PutResponse<Database> response = dao.createOrUpdate(database);
Database db = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(db).build();
@ -288,4 +280,12 @@ public class DatabaseResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Database getDatabase(SecurityContext securityContext, CreateDatabase create) {
return new Database().withId(UUID.randomUUID()).withName(create.getName())
.withDescription(create.getDescription()).withService(create.getService())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -222,14 +222,7 @@ public class TableResource {
@Context SecurityContext securityContext,
@Valid CreateTable create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Table table = new Table().withId(UUID.randomUUID()).withName(create.getName())
.withColumns(create.getColumns()).withDescription(create.getDescription())
.withTableConstraints(create.getTableConstraints()).withTableType(create.getTableType())
.withTags(create.getTags()).withViewDefinition(create.getViewDefinition())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withOwner(create.getOwner())
.withUpdatedAt(new Date())
.withDatabase(new EntityReference().withId(create.getDatabase()));
Table table = getTable(securityContext, create);
table = addHref(uriInfo, dao.create(validateNewTable(table)));
return Response.created(table.getHref()).entity(table).build();
}
@ -246,14 +239,7 @@ public class TableResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreateTable create) throws IOException, ParseException {
Table table = new Table().withId(UUID.randomUUID()).withName(create.getName())
.withColumns(create.getColumns()).withDescription(create.getDescription())
.withTableConstraints(create.getTableConstraints()).withTableType(create.getTableType())
.withTags(create.getTags()).withViewDefinition(create.getViewDefinition())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withOwner(create.getOwner())
.withUpdatedAt(new Date())
.withDatabase(new EntityReference().withId(create.getDatabase()));
Table table = getTable(securityContext, create);
SecurityUtil.checkAdminRoleOrPermissions(authorizer, securityContext, dao.getOwnerReference(table));
PutResponse<Table> response = dao.createOrUpdate(validateNewTable(table));
table = addHref(uriInfo, response.getEntity());
@ -400,4 +386,15 @@ public class TableResource {
DatabaseUtil.validateColumns(table);
return table;
}
private Table getTable(SecurityContext securityContext, CreateTable create) {
return new Table().withId(UUID.randomUUID()).withName(create.getName())
.withColumns(create.getColumns()).withDescription(create.getDescription())
.withTableConstraints(create.getTableConstraints()).withTableType(create.getTableType())
.withTags(create.getTags()).withViewDefinition(create.getViewDefinition())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withOwner(create.getOwner())
.withUpdatedAt(new Date())
.withDatabase(new EntityReference().withId(create.getDatabase()));
}
}

View File

@ -136,7 +136,7 @@ public class MetricsResource {
public Response create(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid Metrics metrics) throws IOException, ParseException {
metrics.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName()).withUpdatedAt(new Date());
addToMetrics(securityContext, metrics);
addHref(uriInfo, dao.create(metrics));
return Response.created(metrics.getHref()).entity(metrics).build();
}
@ -153,10 +153,13 @@ public class MetricsResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid Metrics metrics) throws IOException, ParseException {
metrics.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
addToMetrics(securityContext, metrics);
PutResponse<Metrics> response = dao.createOrUpdate(metrics);
addHref(uriInfo, metrics);
return Response.status(response.getStatus()).entity(metrics).build();
}
private void addToMetrics(SecurityContext securityContext, Metrics metrics) {
metrics.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName()).withUpdatedAt(new Date());
}
}

View File

@ -217,15 +217,7 @@ public class ModelResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateModel create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Model model = new Model().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withDashboard(create.getDashboard()) //ADDED
.withAlgorithm(create.getAlgorithm()) //ADDED
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Model model = getModel(securityContext, create);
model = addHref(uriInfo, dao.create(model));
return Response.created(model.getHref()).entity(model).build();
}
@ -267,16 +259,7 @@ public class ModelResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreateModel create) throws IOException, ParseException {
Model model = new Model().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withDashboard(create.getDashboard()) //ADDED
.withAlgorithm(create.getAlgorithm()) //ADDED
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Model model = getModel(securityContext, create);
PutResponse<Model> response = dao.createOrUpdate(model);
model = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(model).build();
@ -333,4 +316,16 @@ public class ModelResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Model getModel(SecurityContext securityContext, CreateModel create) {
return new Model().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withDashboard(create.getDashboard()) //ADDED
.withAlgorithm(create.getAlgorithm()) //ADDED
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -223,14 +223,7 @@ public class PipelineResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreatePipeline create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Pipeline pipeline = new Pipeline().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withTasks(create.getTasks())
.withPipelineUrl(create.getPipelineUrl()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Pipeline pipeline = getPipeline(securityContext, create);
pipeline = addHref(uriInfo, dao.create(pipeline));
return Response.created(pipeline.getHref()).entity(pipeline).build();
}
@ -272,15 +265,8 @@ public class PipelineResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreatePipeline create) throws IOException, ParseException {
Pipeline pipeline = new Pipeline().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withTasks(create.getTasks())
.withPipelineUrl(create.getPipelineUrl()).withTags(create.getTags())
.withConcurrency(create.getConcurrency()).withStartDate(create.getStartDate())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Pipeline pipeline = getPipeline(securityContext, create).withConcurrency(create.getConcurrency())
.withStartDate(create.getStartDate());
PutResponse<Pipeline> response = dao.createOrUpdate(pipeline);
pipeline = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(pipeline).build();
@ -337,4 +323,14 @@ public class PipelineResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Pipeline getPipeline(SecurityContext securityContext, CreatePipeline create) {
return new Pipeline().withId(UUID.randomUUID()).withName(create.getName())
.withDisplayName(create.getDisplayName())
.withDescription(create.getDescription()).withService(create.getService()).withTasks(create.getTasks())
.withPipelineUrl(create.getPipelineUrl()).withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -135,8 +135,7 @@ public class ReportResource {
public Response create(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid Report report) throws IOException, ParseException {
report.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
addToReport(securityContext, report);
addHref(uriInfo, dao.create(report));
return Response.created(report.getHref()).entity(report).build();
}
@ -153,10 +152,14 @@ public class ReportResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid Report report) throws IOException, ParseException {
report.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
addToReport(securityContext, report);
PutResponse<Report> response = dao.createOrUpdate(report);
addHref(uriInfo, report);
return Response.status(response.getStatus()).entity(report).build();
}
private void addToReport(SecurityContext securityContext, Report report) {
report.withId(UUID.randomUUID()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -216,19 +216,7 @@ public class TaskResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateTask create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Task task =
new Task().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withStartDate(create.getStartDate())
.withEndDate(create.getEndDate())
.withTaskType(create.getTaskType())
.withTaskSQL(create.getTaskSQL())
.withTaskUrl(create.getTaskUrl())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Task task = getTask(securityContext, create);
task = addHref(uriInfo, dao.create(task));
return Response.created(task.getHref()).entity(task).build();
}
@ -269,27 +257,12 @@ public class TaskResource {
public Response createOrUpdate(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid CreateTask create) throws IOException, ParseException {
Task task =
new Task().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withTaskUrl(create.getTaskUrl())
.withDownstreamTasks(create.getDownstreamTasks())
.withStartDate(create.getStartDate())
.withEndDate(create.getEndDate())
.withTaskType(create.getTaskType())
.withTaskSQL(create.getTaskSQL())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Task task = getTask(securityContext, create).withDownstreamTasks(create.getDownstreamTasks());
PutResponse<Task> response = dao.createOrUpdate(task);
task = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(task).build();
}
@DELETE
@Path("/{id}")
@Operation(summary = "Delete a Task", tags = "tasks",
@ -302,4 +275,19 @@ public class TaskResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Task getTask(SecurityContext securityContext, CreateTask create) {
return new Task().withId(UUID.randomUUID()).withName(create.getName()).withDisplayName(create.getDisplayName())
.withDescription(create.getDescription())
.withService(create.getService())
.withStartDate(create.getStartDate())
.withEndDate(create.getEndDate())
.withTaskType(create.getTaskType())
.withTaskSQL(create.getTaskSQL())
.withTaskUrl(create.getTaskUrl())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -235,12 +235,7 @@ public class UserResource {
if (create.getIsAdmin() != null && create.getIsAdmin()) {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
}
User user = new User().withId(UUID.randomUUID()).withName(create.getName()).withEmail(create.getEmail())
.withDisplayName(create.getDisplayName()).withIsBot(create.getIsBot()).withIsAdmin(create.getIsAdmin())
.withProfile(create.getProfile()).withTimezone(create.getTimezone())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date())
.withTeams(dao.validateTeams(create.getTeams()));
User user = getUser(securityContext, create);
addHref(uriInfo, dao.create(user));
return Response.created(user.getHref()).entity(user).build();
}
@ -260,12 +255,7 @@ public class UserResource {
if (create.getIsAdmin() != null && create.getIsAdmin()) {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
}
User user = new User().withId(UUID.randomUUID()).withName(create.getName()).withEmail(create.getEmail())
.withDisplayName(create.getDisplayName()).withIsBot(create.getIsBot()).withIsAdmin(create.getIsAdmin())
.withProfile(create.getProfile()).withTimezone(create.getTimezone())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date())
.withTeams(dao.validateTeams(create.getTeams()));
User user = getUser(securityContext, create);
SecurityUtil.checkAdminRoleOrPermissions(authorizer, securityContext,
new UserEntityInterface(user).getEntityReference());
RestUtil.PutResponse<User> response = dao.createOrUpdate(user);
@ -310,4 +300,13 @@ public class UserResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private User getUser(SecurityContext securityContext, CreateUser create) throws IOException {
return new User().withId(UUID.randomUUID()).withName(create.getName()).withEmail(create.getEmail())
.withDisplayName(create.getDisplayName()).withIsBot(create.getIsBot()).withIsAdmin(create.getIsAdmin())
.withProfile(create.getProfile()).withTimezone(create.getTimezone())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date())
.withTeams(dao.validateTeams(create.getTeams()));
}
}

View File

@ -215,19 +215,7 @@ public class TopicResource {
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext,
@Valid CreateTopic create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
Topic topic =
new Topic().withId(UUID.randomUUID()).withName(create.getName()).withDescription(create.getDescription())
.withService(create.getService()).withPartitions(create.getPartitions())
.withSchemaText(create.getSchemaText()).withSchemaType(create.getSchemaType())
.withCleanupPolicies(create.getCleanupPolicies())
.withMaximumMessageSize(create.getMaximumMessageSize())
.withMinimumInSyncReplicas(create.getMinimumInSyncReplicas())
.withRetentionSize(create.getRetentionSize()).withRetentionTime(create.getRetentionTime())
.withReplicationFactor(create.getReplicationFactor())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Topic topic = getTopic(securityContext, create);
topic = addHref(uriInfo, dao.create(topic));
return Response.created(topic.getHref()).entity(topic).build();
@ -270,20 +258,7 @@ public class TopicResource {
@Context SecurityContext securityContext,
@Valid CreateTopic create) throws IOException, ParseException {
Topic topic =
new Topic().withId(UUID.randomUUID()).withName(create.getName()).withDescription(create.getDescription())
.withService(create.getService()).withPartitions(create.getPartitions())
.withSchemaText(create.getSchemaText()).withSchemaType(create.getSchemaType())
.withCleanupPolicies(create.getCleanupPolicies())
.withMaximumMessageSize(create.getMaximumMessageSize())
.withMinimumInSyncReplicas(create.getMinimumInSyncReplicas())
.withRetentionSize(create.getRetentionSize()).withRetentionTime(create.getRetentionTime())
.withReplicationFactor(create.getReplicationFactor())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
Topic topic = getTopic(securityContext, create);
PutResponse<Topic> response = dao.createOrUpdate(topic);
topic = addHref(uriInfo, response.getEntity());
return Response.status(response.getStatus()).entity(topic).build();
@ -341,4 +316,19 @@ public class TopicResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private Topic getTopic(SecurityContext securityContext, CreateTopic create) {
return new Topic().withId(UUID.randomUUID()).withName(create.getName()).withDescription(create.getDescription())
.withService(create.getService()).withPartitions(create.getPartitions())
.withSchemaText(create.getSchemaText()).withSchemaType(create.getSchemaType())
.withCleanupPolicies(create.getCleanupPolicies())
.withMaximumMessageSize(create.getMaximumMessageSize())
.withMinimumInSyncReplicas(create.getMinimumInSyncReplicas())
.withRetentionSize(create.getRetentionSize()).withRetentionTime(create.getRetentionTime())
.withReplicationFactor(create.getReplicationFactor())
.withTags(create.getTags())
.withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}