package eu.eudat.controllers; import eu.eudat.services.ApiContext; import eu.eudat.validators.DataManagementPlanTableRequestValidator; import eu.eudat.validators.DatasetProfileValidator; import eu.eudat.validators.ProjectModelValidator; import eu.eudat.validators.ProjectTableRequestValidator; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; public abstract class BaseController { private ApiContext apiContext; public ApiContext getApiContext() { return apiContext; } public BaseController(ApiContext apiContext) { this.apiContext = apiContext; } @InitBinder() protected void initBinder(WebDataBinder binder) { if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("dataManagementPlanTableRequestValidator", DataManagementPlanTableRequestValidator.class)); if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("projectTableRequestValidator", ProjectTableRequestValidator.class)); if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("datasetProfileValidator", DatasetProfileValidator.class)); if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("projectModelValidator", ProjectModelValidator.class)); } }