Skip to content

Commit

Permalink
apply spotless (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
idoberko2 authored Jan 7, 2025
1 parent f059d21 commit 009b356
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public static final class AutomationRuleEvaluatorLlmAsJudge extends AutomationRu
@Schema(accessMode = Schema.AccessMode.READ_WRITE)
JsonNode code;

@ConstructorProperties({"id", "projectId", "name", "samplingRate", "code", "createdAt", "createdBy", "lastUpdatedAt", "lastUpdatedBy"})
public AutomationRuleEvaluatorLlmAsJudge(UUID id, UUID projectId, @NotBlank String name, float samplingRate, @NotNull JsonNode code,
Instant createdAt, String createdBy, Instant lastUpdatedAt, String lastUpdatedBy) {
@ConstructorProperties({"id", "projectId", "name", "samplingRate", "code", "createdAt", "createdBy",
"lastUpdatedAt", "lastUpdatedBy"})
public AutomationRuleEvaluatorLlmAsJudge(UUID id, UUID projectId, @NotBlank String name, float samplingRate,
@NotNull JsonNode code,
Instant createdAt, String createdBy, Instant lastUpdatedAt, String lastUpdatedBy) {
super(id, projectId, name, samplingRate, createdAt, createdBy, lastUpdatedAt, lastUpdatedBy);
this.code = code;
}
Expand All @@ -60,8 +62,7 @@ public AutomationRuleEvaluatorType type() {
UUID id;

@JsonView({View.Public.class, View.Write.class})
@NotNull
UUID projectId;
@NotNull UUID projectId;

@JsonView({View.Public.class, View.Write.class})
@Schema(accessMode = Schema.AccessMode.READ_WRITE)
Expand Down Expand Up @@ -100,17 +101,21 @@ public AutomationRuleAction getAction() {
}

public static class View {
public static class Write {}
public static class Public {}
public static class Write {
}
public static class Public {
}
}

@Builder(toBuilder = true)
public record AutomationRuleEvaluatorPage(
@JsonView({View.Public.class}) int page,
@JsonView( {
View.Public.class}) int page,
@JsonView({View.Public.class}) int size,
@JsonView({View.Public.class}) long total,
@JsonView({View.Public.class}) List<AutomationRuleEvaluatorLlmAsJudge> content)
implements Page<AutomationRuleEvaluatorLlmAsJudge>{
implements
Page<AutomationRuleEvaluatorLlmAsJudge>{

public static AutomationRuleEvaluator.AutomationRuleEvaluatorPage empty(int page) {
return new AutomationRuleEvaluator.AutomationRuleEvaluatorPage(page, 0, 0, List.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public class AutomationRuleEvaluatorsResource {
})
@JsonView(AutomationRuleEvaluator.View.Public.class)
public Response find(@PathParam("projectId") UUID projectId,
@QueryParam("name") String name,
@QueryParam("page") @Min(1) @DefaultValue("1") int page,
@QueryParam("size") @Min(1) @DefaultValue("10") int size) {
@QueryParam("name") String name,
@QueryParam("page") @Min(1) @DefaultValue("1") int page,
@QueryParam("size") @Min(1) @DefaultValue("10") int size) {

String workspaceId = requestContext.get().getWorkspaceId();
log.info("Looking for automated evaluators for project id '{}' on workspaceId '{}' (page {})", projectId,
workspaceId, page);
Page<AutomationRuleEvaluator.AutomationRuleEvaluatorLlmAsJudge> definitionPage = service.find(projectId, workspaceId, name, page, size);
Page<AutomationRuleEvaluator.AutomationRuleEvaluatorLlmAsJudge> definitionPage = service.find(projectId,
workspaceId, name, page, size);
log.info("Found {} automated evaluators for project id '{}' on workspaceId '{}' (page {}, total {})",
definitionPage.size(), projectId, workspaceId, page, definitionPage.total());

Expand Down Expand Up @@ -99,8 +100,7 @@ public Response getEvaluator(@PathParam("projectId") UUID projectId, @PathParam(
})
@RateLimited
public Response createEvaluator(
@RequestBody(content = @Content(schema = @Schema(implementation = AutomationRuleEvaluator.class)))
@JsonView(AutomationRuleEvaluator.View.Write.class) @NotNull @Valid AutomationRuleEvaluator<?> evaluator,
@RequestBody(content = @Content(schema = @Schema(implementation = AutomationRuleEvaluator.class))) @JsonView(AutomationRuleEvaluator.View.Write.class) @NotNull @Valid AutomationRuleEvaluator<?> evaluator,
@Context UriInfo uriInfo) {

String workspaceId = requestContext.get().getWorkspaceId();
Expand Down Expand Up @@ -148,12 +148,15 @@ public Response updateEvaluator(@PathParam("id") UUID id,
@ApiResponse(responseCode = "204", description = "No Content"),
})
public Response deleteEvaluators(
@NotNull @RequestBody(content = @Content(schema = @Schema(implementation = BatchDelete.class))) @Valid BatchDelete batchDelete, @PathParam("projectId") UUID projectId) {
@NotNull @RequestBody(content = @Content(schema = @Schema(implementation = BatchDelete.class))) @Valid BatchDelete batchDelete,
@PathParam("projectId") UUID projectId) {
String workspaceId = requestContext.get().getWorkspaceId();
log.info("Deleting automation rule evaluators by ids, count '{}', on workspace_id '{}'", batchDelete.ids().size(),
log.info("Deleting automation rule evaluators by ids, count '{}', on workspace_id '{}'",
batchDelete.ids().size(),
workspaceId);
service.delete(batchDelete.ids(), projectId, workspaceId);
log.info("Deleted automation rule evaluators by ids, count '{}', on workspace_id '{}'", batchDelete.ids().size(),
log.info("Deleted automation rule evaluators by ids, count '{}', on workspace_id '{}'",
batchDelete.ids().size(),
workspaceId);
return Response.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
@RegisterConstructorMapper(AutomationRuleEvaluator.class)
interface AutomationRuleDAO {

@SqlUpdate("INSERT INTO automation_rules(id, project_id, workspace_id, `action`, name, sampling_rate) "+
"VALUES (:rule.id, :rule.projectId, :workspaceId, :rule.action, :rule.name, :rule.samplingRate)")
@SqlUpdate("INSERT INTO automation_rules(id, project_id, workspace_id, `action`, name, sampling_rate) " +
"VALUES (:rule.id, :rule.projectId, :workspaceId, :rule.action, :rule.name, :rule.samplingRate)")
<T> void saveBaseRule(@BindMethods("rule") AutomationRuleModel<T> rule, @Bind("workspaceId") String workspaceId);

@SqlUpdate("""
Expand All @@ -34,32 +34,33 @@ interface AutomationRuleDAO {
WHERE id = :id AND project_id = :projectId AND workspace_id = :workspaceId
""")
int updateBaseRule(@Bind("id") UUID id,
@Bind("projectId") UUID projectId,
@Bind("workspaceId") String workspaceId,
@Bind("name") String name,
@Bind("samplingRate") float samplingRate,
@Bind("lastUpdatedBy") String lastUpdatedBy);
@Bind("projectId") UUID projectId,
@Bind("workspaceId") String workspaceId,
@Bind("name") String name,
@Bind("samplingRate") float samplingRate,
@Bind("lastUpdatedBy") String lastUpdatedBy);

@SqlUpdate("""
DELETE FROM automation_rules
WHERE project_id = :projectId AND workspace_id = :workspaceId
<if(ids)> AND id IN (<ids>) <endif>
""")
DELETE FROM automation_rules
WHERE project_id = :projectId AND workspace_id = :workspaceId
<if(ids)> AND id IN (<ids>) <endif>
""")
@UseStringTemplateEngine
@AllowUnusedBindings
void deleteBaseRules(@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids,
@Bind("projectId") UUID projectId,
@Bind("workspaceId") String workspaceId);
void deleteBaseRules(
@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids,
@Bind("projectId") UUID projectId,
@Bind("workspaceId") String workspaceId);

@SqlQuery("""
SELECT COUNT(*)
FROM automation_rules
WHERE project_id = :projectId AND workspace_id = :workspaceId
<if(action)> AND `action` = :action <endif>
""")
SELECT COUNT(*)
FROM automation_rules
WHERE project_id = :projectId AND workspace_id = :workspaceId
<if(action)> AND `action` = :action <endif>
""")
@UseStringTemplateEngine
@AllowUnusedBindings
long findCount(@Bind("projectId") UUID projectId,
@Bind("workspaceId") String workspaceId,
@Define("action") @Bind("action") AutomationRule.AutomationRuleAction action);
@Bind("workspaceId") String workspaceId,
@Define("action") @Bind("action") AutomationRule.AutomationRuleAction action);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
@RegisterRowMapper(AutomationRuleEvaluatorRowMapper.class)
public interface AutomationRuleEvaluatorDAO extends AutomationRuleDAO {

@SqlUpdate("INSERT INTO automation_rule_evaluators(id, `type`, code, created_by, last_updated_by) "+
"VALUES (:rule.id, :rule.type, :rule.code, :rule.createdBy, :rule.lastUpdatedBy)")
@SqlUpdate("INSERT INTO automation_rule_evaluators(id, `type`, code, created_by, last_updated_by) " +
"VALUES (:rule.id, :rule.type, :rule.code, :rule.createdBy, :rule.lastUpdatedBy)")
<T> void saveEvaluator(@BindMethods("rule") AutomationRuleEvaluatorModel<T> rule);

@SqlUpdate("""
Expand All @@ -36,7 +36,8 @@ public interface AutomationRuleEvaluatorDAO extends AutomationRuleDAO {
last_updated_by = :userName
WHERE id = :id
""")
int updateEvaluator(@Bind("id") UUID id, @BindMethods("rule") AutomationRuleEvaluatorUpdate ruleUpdate, @Bind("userName") String userName);
int updateEvaluator(@Bind("id") UUID id, @BindMethods("rule") AutomationRuleEvaluatorUpdate ruleUpdate,
@Bind("userName") String userName);

@SqlQuery("""
SELECT rule.id, rule.project_id, rule.action, rule.name, rule.sampling_rate, evaluator.type, evaluator.code,
Expand All @@ -53,25 +54,25 @@ public interface AutomationRuleEvaluatorDAO extends AutomationRuleDAO {
@UseStringTemplateEngine
@AllowUnusedBindings
List<AutomationRuleEvaluatorModel<?>> find(@Bind("workspaceId") String workspaceId,
@Bind("projectId") UUID projectId,
@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids,
@Define("name") @Bind("name") String name,
@Bind("action") AutomationRule.AutomationRuleAction action,
@Bind("offset") int offset,
@Bind("limit") int limit);
@Bind("projectId") UUID projectId,
@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids,
@Define("name") @Bind("name") String name,
@Bind("action") AutomationRule.AutomationRuleAction action,
@Bind("offset") int offset,
@Bind("limit") int limit);

@SqlUpdate("""
DELETE FROM automation_rule_evaluators
WHERE id IN (
SELECT id
FROM automation_rules
WHERE workspace_id = :workspaceId AND project_id = :projectId
<if(ids)> AND id IN (<ids>) <endif>
)
""")
DELETE FROM automation_rule_evaluators
WHERE id IN (
SELECT id
FROM automation_rules
WHERE workspace_id = :workspaceId AND project_id = :projectId
<if(ids)> AND id IN (<ids>) <endif>
)
""")
@UseStringTemplateEngine
@AllowUnusedBindings
void deleteEvaluatorsByIds(@Bind("workspaceId") String workspaceId,
@Bind("projectId") UUID projectId,
@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids);
@Bind("projectId") UUID projectId,
@Define("ids") @BindList(onEmpty = BindList.EmptyHandling.NULL_VALUE, value = "ids") Set<UUID> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public sealed interface AutomationRuleEvaluatorModel<T> extends AutomationRuleModel<T>
permits LlmAsJudgeAutomationRuleEvaluatorModel {

@Json T code();
@Json
T code();
AutomationRuleEvaluatorType type();

@Override
Expand Down
Loading

0 comments on commit 009b356

Please sign in to comment.