Skip to content

Commit

Permalink
#321: Add component (observation) title to configuration exception to…
Browse files Browse the repository at this point in the history
… have detailed information where the wrong config is located.
  • Loading branch information
benitsch committed Aug 8, 2024
1 parent 44d5ff8 commit eee11d0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ public enum Type {
WARNING
}

public static ValidationIssue NONE = new ValidationIssue(Type.None, null, null);
public static ValidationIssue NONE = new ValidationIssue(Type.None, null, null, null);

private final Type type;
private final String propertyId;
private final String message;
private String componentTitle;

private ValidationIssue(Type type, String propertyId, String message) {
private ValidationIssue(Type type, String propertyId, String message, String componentTitle) {
this.type = type;
this.propertyId = propertyId;
this.message = message;
this.componentTitle = componentTitle;
}

public static boolean nonNone(ValidationIssue issue) {
return issue != null && Type.None != issue.type;
}

public static ValidationIssue error(Value<?> value, String message) {
return new ValidationIssue(Type.ERROR, Optional.ofNullable(value).map(Value::getId).orElse(null), message);
return new ValidationIssue(Type.ERROR, Optional.ofNullable(value).map(Value::getId).orElse(null), message, null);
}

public static ValidationIssue warning(Value<?> value, String message) {
return new ValidationIssue(Type.WARNING, Optional.ofNullable(value).map(Value::getId).orElse(null), message);
return new ValidationIssue(Type.WARNING, Optional.ofNullable(value).map(Value::getId).orElse(null), message, null);
}

public static ValidationIssue requiredMissing(Value<?> value) {
Expand All @@ -61,4 +63,12 @@ public String getMessage() {
public String getPropertyId() {
return propertyId;
}

public String getComponentTitle() {
return componentTitle;
}

public void setComponentTitle(String componentTitle) {
this.componentTitle = componentTitle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private static ValidationReportItemDTO validationReportItemDTO_V1(ValidationIssu
return new ValidationReportItemDTO()
.message(issue.getMessage())
.propertyId(issue.getPropertyId())
.componentTitle(issue.getComponentTitle())
.type(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.ui.DataView;
import io.redlink.more.studymanager.core.ui.DataViewInfo;
import io.redlink.more.studymanager.core.validation.ValidationIssue;
import io.redlink.more.studymanager.exception.BadRequestException;
import io.redlink.more.studymanager.exception.NotFoundException;
import io.redlink.more.studymanager.model.Observation;
Expand Down Expand Up @@ -97,14 +98,35 @@ public void alignObservationsWithStudyState(Study study){

private void deactivateObservationsFor(Study study){ listObservationsFor(study).forEach(Component::deactivate); }

private void validateProperties(List<Observation> observations) {
for (Observation observation : observations) {
try {
factory(observation).validate(observation.getProperties());
} catch (ConfigurationValidationException e) {
for (ValidationIssue issue : e.getReport().getIssues()) {
issue.setComponentTitle(observation.getTitle());
}

throw e;
}
}
}

public List<io.redlink.more.studymanager.core.component.Observation> listObservationsFor(Study study){
return listObservations(study.getStudyId()).stream()
.map(observation -> factory(observation)
.create(
sdk.scopedObservationSDK(observation.getStudyId(), observation.getStudyGroupId(), observation.getObservationId()),
observation.getProperties()
))
.toList();
List<Observation> observations = listObservations(study.getStudyId());
List<io.redlink.more.studymanager.core.component.Observation> result = new ArrayList<>();

validateProperties(observations);

for (Observation observation : observations) {
result.add(factory(observation)
.create(
sdk.scopedObservationSDK(observation.getStudyId(), observation.getStudyGroupId(), observation.getObservationId()),
observation.getProperties()
));
}

return result;
}

public DataViewInfo[] listDataViews(Long studyId, Integer observationId) {
Expand Down
2 changes: 2 additions & 0 deletions studymanager/src/main/resources/openapi/StudyManagerAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,8 @@ components:
type: string
propertyId:
type: string
componentTitle:
type: string
type:
type: string

Expand Down

0 comments on commit eee11d0

Please sign in to comment.