Package web.operator.message

Source Code of web.operator.message.NewMessageController

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package web.operator.message;

import domain.Client;
import domain.Collaborator;
import domain.Message;
import domain.editors.Editor;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import web.generic.GenericSFController;

/**
* Контроллер, позволяющий добавить пациента на подтверждение
* @author petr
*/
public class NewMessageController extends GenericSFController {

    public NewMessageController() {
        setSessionForm(true);
        setCommandClass(MessageDTO.class);
        setFormView("operator/message/newmessage");
    }

    @Override
    protected Object formBackingObject(HttpServletRequest request) throws Exception {
        return new MessageDTO();
    }

    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
        MessageDTO dto = (MessageDTO)command;

        //check DTO
        if (dto.getText() == null || dto.getText().trim().isEmpty()) {
            errors.rejectValue("text", "message.emptytext");
            return showForm(request, errors, getFormView());
        }
        if (dto.getClient() == null) {
            errors.rejectValue("client", "message.emptyclient");
            return showForm(request, errors, getFormView());
        }
        //end check DTO

        Message mss = new Message();
        mss.setClient(dto.getClient());
        mss.setDate(new Date());
        Client sender = getDao().getById(Collaborator.class, getUserInfo().getCurrentCollaboratorId()).getClient();
        mss.setSender(sender);
        mss.setSubject(dto.getSubject());
        mss.setText(dto.getText());
        getDao().save(mss);
        return new ModelAndView("redirect:/operator/message/outbox.htm");
    }

    @Override
    protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
        Map referenceData = new HashMap();
        //STUB
        List<Client> clients = new ArrayList<Client>();
        clients.add(getDao().getById(Client.class, 337244));
        clients.add(getDao().getById(Client.class, 355574));
        //ENDSTUB
        referenceData.put("clients", clients);
        return referenceData;
    }

    @Override
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
        binder.registerCustomEditor(Client.class, new Editor(getDao(), Client.class));
    }


}
TOP

Related Classes of web.operator.message.NewMessageController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.