-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-218] Remove limitations in dataset items (#369)
* [OPIK-218] Remove limitations in dataset items * Add tests * Address PR review * Fixing contract * Fix fixture generation * Deprecate metadata * Add PR review comments * Remove dead code
- Loading branch information
1 parent
a593751
commit 6e5bb09
Showing
15 changed files
with
446 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/opik-backend/src/main/java/com/comet/opik/api/validate/DatasetItemInputValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.comet.opik.api.validate; | ||
|
||
import jakarta.validation.Constraint; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = {DatasetItemInputValidator.class}) | ||
@Documented | ||
public @interface DatasetItemInputValidation { | ||
|
||
String message() default "must provide either input or data field"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<?>[] payload() default {}; | ||
} |
43 changes: 43 additions & 0 deletions
43
apps/opik-backend/src/main/java/com/comet/opik/api/validate/DatasetItemInputValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.comet.opik.api.validate; | ||
|
||
import com.comet.opik.api.DatasetItem; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import org.apache.commons.collections4.MapUtils; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class DatasetItemInputValidator implements ConstraintValidator<DatasetItemInputValidation, DatasetItem> { | ||
|
||
@Override | ||
public boolean isValid(DatasetItem datasetItem, ConstraintValidatorContext context) { | ||
boolean result = datasetItem.input() != null || MapUtils.isNotEmpty(datasetItem.data()); | ||
|
||
if (!result) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate("must provide either input or data field") | ||
.addPropertyNode("input") | ||
.addConstraintViolation(); | ||
} | ||
|
||
if (result && datasetItem.data() != null) { | ||
Optional<Map.Entry<String, JsonNode>> error = datasetItem.data().entrySet() | ||
.stream() | ||
.filter(entry -> entry.getValue() == null) | ||
.findAny(); | ||
|
||
if (error.isPresent()) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate("field must not contain null key or value") | ||
.addPropertyNode("data") | ||
.addConstraintViolation(); | ||
} | ||
|
||
result = error.isEmpty(); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.