SEBSERV-58 point 6
This commit is contained in:
parent
40b83111cb
commit
3f6bc5098d
2 changed files with 59 additions and 0 deletions
|
@ -8,17 +8,25 @@
|
|||
|
||||
package ch.ethz.seb.sebserver.webservice.weblayer.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
|
||||
import ch.ethz.seb.sebserver.gbl.api.APIMessage.APIMessageException;
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Pair;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
|
@ -86,6 +94,26 @@ public class IndicatorController extends EntityController<Indicator, Indicator>
|
|||
return Result.of(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result<Indicator> validForCreate(final Indicator entity) {
|
||||
final Result<Indicator> validForCreate = super.validForCreate(entity);
|
||||
if (validForCreate.hasError()) {
|
||||
return validForCreate;
|
||||
}
|
||||
|
||||
return checkThresholdConsistency(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result<Indicator> validForSave(final Indicator entity) {
|
||||
final Result<Indicator> validForSave = super.validForSave(entity);
|
||||
if (validForSave.hasError()) {
|
||||
return validForSave;
|
||||
}
|
||||
|
||||
return checkThresholdConsistency(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GrantEntity toGrantEntity(final Indicator entity) {
|
||||
if (entity == null) {
|
||||
|
@ -128,4 +156,33 @@ public class IndicatorController extends EntityController<Indicator, Indicator>
|
|||
|
||||
}
|
||||
|
||||
private Result<Indicator> checkThresholdConsistency(final Indicator entity) {
|
||||
if (entity != null) {
|
||||
final List<Threshold> emptyThresholds = entity.thresholds.stream()
|
||||
.filter(t -> t.getValue() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!emptyThresholds.isEmpty()) {
|
||||
throw new APIMessageException(APIMessage.fieldValidationError(
|
||||
new FieldError(
|
||||
Domain.EXAM.TYPE_NAME,
|
||||
Domain.EXAM.ATTR_SUPPORTER,
|
||||
"indicator:thresholds:thresholdEmpty")));
|
||||
}
|
||||
|
||||
final Set<Double> values = entity.thresholds.stream()
|
||||
.map(t -> t.getValue())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (values.size() != entity.thresholds.size()) {
|
||||
throw new APIMessageException(APIMessage.fieldValidationError(
|
||||
new FieldError(
|
||||
Domain.EXAM.TYPE_NAME,
|
||||
Domain.EXAM.ATTR_SUPPORTER,
|
||||
"indicator:thresholds:thresholdDuplicate")));
|
||||
}
|
||||
}
|
||||
return Result.of(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ sebserver.form.validation.fieldError.exists=This name already exists. Please cho
|
|||
sebserver.form.validation.fieldError.email=Invalid mail address
|
||||
sebserver.form.validation.fieldError.serverNotAvailable=No service seems to be available within the given URL
|
||||
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached.
|
||||
sebserver.form.validation.fieldError.thresholdDuplicate=There are duplicate threshold values.
|
||||
sebserver.form.validation.fieldError.thresholdEmpty=There are empty threshold entries.
|
||||
sebserver.error.unexpected=Unexpected Error
|
||||
sebserver.page.message=Information
|
||||
sebserver.dialog.confirm.title=Confirmation
|
||||
|
|
Loading…
Reference in a new issue