Search in sources :

Example 1 with SearchRequestParameters

use of org.talend.esb.client.app.model.SearchRequestParameters in project tesb-rt-se by Talend.

the class AppController method search.

@RequestMapping(value = "/search", method = RequestMethod.POST)
public String search(@Valid @ModelAttribute("inputData") SearchRequestParameters req, BindingResult bindResult, Model model, HttpSession session) {
    if (session.isNew()) {
        return redirectToMainPage();
    }
    Stages stage = getSessionAttribute(session, Stages.class);
    if (stage != null && stage.equals(Stages.DATA_INPUT)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Received a request to search: customerName(").append(req.getCustomerName()).append("), pickupDate(").append(req.getPickupDate()).append("), returnDate(").append(req.getReturnDate()).append(")");
        LOG.info(sb);
        if (bindResult.hasErrors()) {
            model.addAttribute("knownCustomers", KNOWS_CUSTOMERS);
            return stage.getView();
        }
        try {
            searchModel.search(req.getCustomerName(), req.getPickupDate(), req.getReturnDate());
        } catch (Exception e) {
            model.addAttribute("excptMessage", e);
            return "error";
        }
        setSessionAttribute(session, SearchRequestParameters.class, new SearchRequestParameters(req));
        return setStageAndRedirect(session, Stages.CAR_LIST);
    }
    return redirectToMainPage();
}
Also used : SearchRequestParameters(org.talend.esb.client.app.model.SearchRequestParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SearchRequestParameters

use of org.talend.esb.client.app.model.SearchRequestParameters in project tesb-rt-se by Talend.

the class AppController method createRequestParameters.

@ModelAttribute("inputData")
public SearchRequestParameters createRequestParameters() {
    SimpleDateFormat sdf = new SimpleDateFormat(DateFormatValidator.DEFAULT_FORMAT);
    SearchRequestParameters params = new SearchRequestParameters();
    params.setCustomerName("aebert");
    params.setPickupDate(sdf.format(new Date()));
    params.setReturnDate(sdf.format(new Date(System.currentTimeMillis() + ADAY)));
    return params;
}
Also used : SearchRequestParameters(org.talend.esb.client.app.model.SearchRequestParameters) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 3 with SearchRequestParameters

use of org.talend.esb.client.app.model.SearchRequestParameters in project tesb-rt-se by Talend.

the class AppController method reserve.

@RequestMapping(value = "/reserve", method = RequestMethod.POST)
public String reserve(@RequestParam(value = "carIndex", required = false) Integer carIndex, Model model, HttpSession session) {
    if (session.isNew()) {
        return redirectToMainPage();
    }
    if (carIndex != null && carIndex >= 0) {
        List<RESCarType> cars = searchModel.getCars();
        if (carIndex < cars.size()) {
            CustomerDetailsType customerDetails = searchModel.getCustomer();
            RESCarType selectedCar = cars.get(carIndex);
            SearchRequestParameters requestParams = getSessionAttribute(session, SearchRequestParameters.class);
            RESStatusType resStatus = null;
            ConfirmationType confirm = null;
            try {
                resStatus = reserveModel.reserveCar(customerDetails, selectedCar, requestParams.getPickupDate(), requestParams.getReturnDate());
                confirm = reserveModel.getConfirmation(resStatus, customerDetails, selectedCar, requestParams.getPickupDate(), requestParams.getReturnDate());
            } catch (Exception e) {
                model.addAttribute("excptMessage", e);
                return "error";
            }
            setSessionAttribute(session, ConfirmationType.class, confirm);
            RESStatucCodeType code = confirm.getDescription().contains("failed") ? RESStatucCodeType.FAILED : RESStatucCodeType.OK;
            setSessionAttribute(session, RESStatucCodeType.class, code);
            setSessionAttribute(session, Stages.class, Stages.RESERVATION_INFO);
        }
    }
    return redirectToMainPage();
}
Also used : ConfirmationType(org.talend.services.reservation.types.ConfirmationType) RESCarType(org.talend.services.reservation.types.RESCarType) RESStatucCodeType(org.talend.services.reservation.types.RESStatucCodeType) CustomerDetailsType(org.talend.services.crm.types.CustomerDetailsType) RESStatusType(org.talend.services.reservation.types.RESStatusType) SearchRequestParameters(org.talend.esb.client.app.model.SearchRequestParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SearchRequestParameters (org.talend.esb.client.app.model.SearchRequestParameters)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 CustomerDetailsType (org.talend.services.crm.types.CustomerDetailsType)1 ConfirmationType (org.talend.services.reservation.types.ConfirmationType)1 RESCarType (org.talend.services.reservation.types.RESCarType)1 RESStatucCodeType (org.talend.services.reservation.types.RESStatucCodeType)1 RESStatusType (org.talend.services.reservation.types.RESStatusType)1