
com.commercetools.sunrise.framework.controllers.WithFormFlow Maven / Gradle / Ivy
The newest version!
package com.commercetools.sunrise.framework.controllers;
import io.sphere.sdk.client.ClientErrorException;
import org.slf4j.Logger;
import play.data.Form;
import play.libs.concurrent.HttpExecution;
import play.mvc.Result;
import java.util.concurrent.CompletionStage;
import static io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture;
import static io.sphere.sdk.utils.CompletableFutureUtils.recoverWith;
import static java.util.concurrent.CompletableFuture.completedFuture;
/**
* Approach to handle form data (Template Method Pattern).
* @param type of the input data, possibly a parameter object
* @param type of the output object, normally the updated object if the form is valid
* @param stereotype of the in a form wrapped class
*/
public interface WithFormFlow extends WithForm {
Logger getLogger();
default CompletionStage processForm(final I input) {
return validateForm(input, bindForm()).thenComposeAsync(form -> {
if (!form.hasErrors()) {
return handleValidForm(input, form);
} else {
return handleInvalidForm(input, form);
}
}, HttpExecution.defaultContext());
}
default CompletionStage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy