TravelRequisitionController_Roo_Controller.aj 7.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).

package br.ufpr.c3sl.sapos.web;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.joda.time.format.DateTimeFormat;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.WebUtils;

import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.scholar.TravelRequisition;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequestStatus;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequesterKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TicketKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TripKind;

privileged aspect TravelRequisitionController_Roo_Controller {
    
33 34 35 36 37 38 39 40 41 42 43
//    @RequestMapping(method = RequestMethod.POST)
//    public String TravelRequisitionController.create(@Valid TravelRequisition travelRequisition, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
//        if (bindingResult.hasErrors()) {
//            uiModel.addAttribute("travelRequisition", travelRequisition);
//            addDateTimeFormatPatterns(uiModel);
//            return "travelrequisitions/create";
//        }
//        uiModel.asMap().clear();
//        travelRequisition.persist();
//        return "redirect:/travelrequisitions/" + encodeUrlPathSegment(travelRequisition.getId().toString(), httpServletRequest);
//    }
44 45 46 47 48 49 50 51 52

    void TravelRequisitionController.addDateTimeFormatPatterns(Model uiModel) {
        uiModel.addAttribute("travelrequisition_ticketstartdate_date_format", DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()));
        uiModel.addAttribute("travelrequisition_ticketenddate_date_format", DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()));
    	uiModel.addAttribute("travelrequisition_startdate_date_format", DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()));
        uiModel.addAttribute("travelrequisition_enddate_date_format", DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()));
    }
	
	
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    @RequestMapping(params = "form", method = RequestMethod.GET)
    public String TravelRequisitionController.createForm(Model uiModel) {
        uiModel.addAttribute("travelRequisition", new TravelRequisition());
        addDateTimeFormatPatterns(uiModel);
        return "travelrequisitions/create";
    }
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String TravelRequisitionController.show(@PathVariable("id") Long id, Model uiModel) {
    	addDateTimeFormatPatterns(uiModel);
        uiModel.addAttribute("travelrequisition", TravelRequisition.findTravelRequisition(id));
        uiModel.addAttribute("itemId", id);
        return "travelrequisitions/show";
    }
    
68 69 70 71 72 73 74 75 76 77 78 79
//    @RequestMapping(method = RequestMethod.GET)
//    public String TravelRequisitionController.list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
//        if (page != null || size != null) {
//            int sizeNo = size == null ? 10 : size.intValue();
//            uiModel.addAttribute("travelrequisitions", TravelRequisition.findTravelRequisitionEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));
//            float nrOfPages = (float) TravelRequisition.countTravelRequisitions() / sizeNo;
//            uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
//        } else {
//            uiModel.addAttribute("travelrequisitions", TravelRequisition.findAllTravelRequisitions());
//        }
//        return "travelrequisitions/list";
//    }
80
    
81 82 83 84 85 86 87 88 89 90 91
//    @RequestMapping(method = RequestMethod.PUT)
//    public String TravelRequisitionController.update(@Valid TravelRequisition travelRequisition, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
//        if (bindingResult.hasErrors()) {
//            uiModel.addAttribute("travelRequisition", travelRequisition);
//            addDateTimeFormatPatterns(uiModel);
//            return "travelrequisitions/update";
//        }
//        uiModel.asMap().clear();
//        travelRequisition.merge();
//        return "redirect:/travelrequisitions/" + encodeUrlPathSegment(travelRequisition.getId().toString(), httpServletRequest);
//    }
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    
    @RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
    public String TravelRequisitionController.updateForm(@PathVariable("id") Long id, Model uiModel) {
        uiModel.addAttribute("travelRequisition", TravelRequisition.findTravelRequisition(id));
        addDateTimeFormatPatterns(uiModel);
        return "travelrequisitions/update";
    }
    
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String TravelRequisitionController.delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
        TravelRequisition.findTravelRequisition(id).remove();
        uiModel.asMap().clear();
        uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
        uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
        return "redirect:/travelrequisitions";
    }
    
    @ModelAttribute("people")
    public java.util.Collection<Person> TravelRequisitionController.populatePeople() {
        return Person.findAllPeople();
    }
    
    @ModelAttribute("travelrequisitions")
    public java.util.Collection<TravelRequisition> TravelRequisitionController.populateTravelRequisitions() {
        return TravelRequisition.findAllTravelRequisitions();
    }
    
    @ModelAttribute("requesterkinds")
    public java.util.Collection<RequesterKind> TravelRequisitionController.populateRequesterKinds() {
        return Arrays.asList(RequesterKind.class.getEnumConstants());
    }
    
    @ModelAttribute("tripkinds")
    public java.util.Collection<TripKind> TravelRequisitionController.populateTripKinds() {
        return Arrays.asList(TripKind.class.getEnumConstants());
    }
    
    @ModelAttribute("ticketkinds")
    public java.util.Collection<TicketKind> TravelRequisitionController.populateTicketKinds() {
        return Arrays.asList(TicketKind.class.getEnumConstants());
    }
    @ModelAttribute("requeststatuses")
    public java.util.Collection<RequestStatus> TravelRequisitionController.populateRequestStatuses() {
        return Arrays.asList(RequestStatus.class.getEnumConstants());
    }
137
        
138 139 140 141 142 143 144 145 146 147 148 149 150
    String TravelRequisitionController.encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
        String enc = httpServletRequest.getCharacterEncoding();
        if (enc == null) {
            enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
        }
        try {
            pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
        }
        catch (UnsupportedEncodingException uee) {}
        return pathSegment;
    }
    
}