argos/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java

37 lines
1.8 KiB
Java
Raw Normal View History

2018-01-03 11:44:54 +01:00
package eu.eudat.controllers;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext;
2018-01-03 11:44:54 +01:00
import eu.eudat.validators.DataManagementPlanTableRequestValidator;
2018-01-03 17:36:31 +01:00
import eu.eudat.validators.DatasetProfileValidator;
import eu.eudat.validators.ProjectModelValidator;
2018-01-03 11:44:54 +01:00
import eu.eudat.validators.ProjectTableRequestValidator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
2018-02-01 10:08:06 +01:00
2018-01-03 11:44:54 +01:00
public abstract class BaseController {
2018-01-04 10:32:39 +01:00
private ApiContext apiContext;
2018-01-03 11:44:54 +01:00
2018-01-04 10:32:39 +01:00
public ApiContext getApiContext() {
return apiContext;
}
2018-02-16 11:34:02 +01:00
public BaseController(ApiContext apiContext) {
2018-01-04 10:32:39 +01:00
this.apiContext = apiContext;
2018-01-03 11:44:54 +01:00
}
@InitBinder()
protected void initBinder(WebDataBinder binder) {
2018-02-16 11:34:02 +01:00
if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("dataManagementPlanTableRequestValidator", DataManagementPlanTableRequestValidator.class));
if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("projectTableRequestValidator", ProjectTableRequestValidator.class));
if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("datasetProfileValidator", DatasetProfileValidator.class));
if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("projectModelValidator", ProjectModelValidator.class));
2018-01-03 17:36:31 +01:00
2018-01-03 11:44:54 +01:00
}
}