use of org.springframework.validation.BeanPropertyBindingResult in project mots by motech-implementations.
the class ModuleController method validateCourseForRelease.
private void validateCourseForRelease(Course course) {
BindingResult bindingResult = new BeanPropertyBindingResult(course, COURSE);
validator.validate(course, bindingResult, CourseReleaseCheck.class);
checkBindingResult(bindingResult);
}
use of org.springframework.validation.BeanPropertyBindingResult in project entando-core by entando.
the class AbstractListViewerWidgetValidator method validate.
@Override
public BeanPropertyBindingResult validate(WidgetConfigurationRequest widget, IPage page) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widget, widget.getClass().getSimpleName());
try {
logger.debug("validating widget {} for page {}", widget.getCode(), page.getCode());
WidgetValidatorCmsHelper.validateTitle(widget, getLangManager(), bindingResult);
WidgetValidatorCmsHelper.validateLink(widget, getLangManager(), getPageManager(), bindingResult);
} catch (Throwable e) {
logger.error("error in validate wiget {} in page {}", widget.getCode(), page.getCode());
throw new RestServerError("error in widget config validation", e);
}
return bindingResult;
}
use of org.springframework.validation.BeanPropertyBindingResult in project entando-core by entando.
the class AbstractEntityService method deleteEntityType.
protected void deleteEntityType(String entityManagerCode, String entityTypeCode) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
try {
IApsEntity entityType = entityManager.getEntityPrototype(entityTypeCode);
if (null == entityType) {
return;
}
List<String> ids = entityManager.searchId(entityTypeCode, null);
if (null != ids && ids.size() > 0) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(entityType, "entityType");
bindingResult.reject(EntityTypeValidator.ERRCODE_ENTITY_TYPE_REFERENCES, new Object[] { entityTypeCode }, "entityType.cannot.delete.references");
throw new ValidationConflictException(bindingResult);
}
((IEntityTypesConfigurer) entityManager).removeEntityPrototype(entityTypeCode);
} catch (ApsSystemException e) {
logger.error("Error in delete entityType {}", entityTypeCode, e);
throw new RestServerError("error in delete entityType", e);
}
}
use of org.springframework.validation.BeanPropertyBindingResult in project alf.io by alfio-event.
the class EventApiV1Controller method create.
@PostMapping("/create")
@Transactional
public ResponseEntity<String> create(@RequestBody EventCreationRequest request, Principal user) {
String imageRef = Optional.ofNullable(request.getImageUrl()).map(this::fetchImage).orElse(null);
Organization organization = userManager.findUserOrganizations(user.getName()).get(0);
AtomicReference<Errors> errorsContainer = new AtomicReference<>();
Result<String> result = new Result.Builder<String>().checkPrecondition(() -> isNotBlank(request.getTitle()), ErrorCode.custom("invalid.title", "Invalid title")).checkPrecondition(() -> isBlank(request.getSlug()) || eventNameManager.isUnique(request.getSlug()), ErrorCode.custom("invalid.slug", "Invalid slug")).checkPrecondition(() -> isNotBlank(request.getWebsiteUrl()), ErrorCode.custom("invalid.websiteUrl", "Invalid Website URL")).checkPrecondition(() -> isNotBlank(request.getTermsAndConditionsUrl()), ErrorCode.custom("invalid.tc", "Invalid Terms and Conditions")).checkPrecondition(() -> isNotBlank(request.getImageUrl()), ErrorCode.custom("invalid.imageUrl", "Invalid Image URL")).checkPrecondition(() -> isNotBlank(request.getTimezone()), ErrorCode.custom("invalid.timezone", "Invalid Timezone")).checkPrecondition(() -> isNotBlank(imageRef), ErrorCode.custom("invalid.image", "Image is either missing or too big (max 200kb)")).checkPrecondition(() -> {
EventModification eventModification = request.toEventModification(organization, eventNameManager::generateShortName, imageRef);
errorsContainer.set(new BeanPropertyBindingResult(eventModification, "event"));
int descriptionMaxLength = configurationManager.getFor(ConfigurationKeys.DESCRIPTION_MAXLENGTH, ConfigurationLevel.system()).getValueAsIntOrDefault(4096);
ValidationResult validationResult = validateEvent(eventModification, errorsContainer.get(), descriptionMaxLength);
if (!validationResult.isSuccess()) {
log.warn("validation failed {}", validationResult.getValidationErrors());
}
return validationResult.isSuccess();
}, ErrorCode.lazy(() -> toErrorCode(errorsContainer.get()))).build(() -> insertEvent(request, user, imageRef).map(Event::getShortName).orElseThrow(IllegalStateException::new));
if (result.isSuccess()) {
return ResponseEntity.ok(result.getData());
} else {
return ResponseEntity.badRequest().body(Json.toJson(result.getErrors()));
}
}
use of org.springframework.validation.BeanPropertyBindingResult in project alf.io by alfio-event.
the class PromoCodeRequestManager method makeSimpleReservation.
private Pair<Optional<String>, BindingResult> makeSimpleReservation(Event event, int ticketCategoryId, String promoCode, ServletWebRequest request, Optional<PromoCodeDiscount> promoCodeDiscount, Principal principal) {
Locale locale = RequestUtils.getMatchingLocale(request, event);
ReservationForm form = new ReservationForm();
form.setPromoCode(promoCode);
TicketReservationModification reservation = new TicketReservationModification();
reservation.setQuantity(1);
reservation.setTicketCategoryId(ticketCategoryId);
form.setReservation(Collections.singletonList(reservation));
var bindingRes = new BeanPropertyBindingResult(form, "reservationForm");
return Pair.of(createTicketReservation(form, bindingRes, event, locale, promoCodeDiscount.map(PromoCodeDiscount::getPromoCode), principal), bindingRes);
}
Aggregations