/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web.operator.request;
import domain.Client;
import domain.UserClient;
import domain.UserClientPK;
import domain.UserRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import web.generic.CH;
import web.generic.GenericAbstractController;
/**
* Контроллер подтверждения пациента
* Обязательные параметры:
* client - ID пациента из базы
* clientrequested - ID UserRequestа
* @author lacoste
*/
public class AcceptController extends GenericAbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String clientStr = request.getParameter("client");
if (clientStr == null || clientStr.isEmpty()) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
Client client = null;
try {
client = CH.get(getDao(), Client.class, clientStr);
} catch (Exception ex) {
}
if (client == null) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
String requestedStr = request.getParameter("clientrequested");
if (requestedStr == null || requestedStr.isEmpty()) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
UserRequest requested = null;
try {
requested = CH.get(getDao(), UserRequest.class, requestedStr);
} catch (Exception ex) {
}
if (requested == null) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
UserClient userClient = new UserClient();
userClient.setUserClientPK(new UserClientPK(getUserInfo().getLogin(), client.getId()));
userClient.setClient(client);
userClient.setUserLogin(requested.getRequesterLogin());
getDao().save(userClient);
return new ModelAndView("redirect:/operator/request/index.htm");
}
}