Search in sources :

Example 1 with Registrant

use of site.model.Registrant in project jprime by bgjug.

the class TicketsController method register.

/**
 * User submitted the form.
 */
@Transactional
@RequestMapping(value = "/tickets/epay", method = RequestMethod.POST)
public String register(Model model, @Valid final Registrant registrant, BindingResult bindingResult, HttpServletRequest request) throws Exception {
    boolean invalidCaptcha = false;
    if (registrant.getCaptcha() == null || !registrant.getCaptcha().equals(request.getSession().getAttribute(CaptchaController.SESSION_PARAM_CAPTCHA_IMAGE))) {
        bindingResult.rejectValue("captcha", "invalid");
        invalidCaptcha = true;
    }
    if (bindingResult.hasErrors() || invalidCaptcha) {
        return TICKETS_REGISTER_JSP;
    }
    // check empty users, server side validation
    List<Visitor> toBeRemoved = registrant.getVisitors().stream().filter(v -> v.getEmail() == null || v.getEmail().isEmpty() || v.getName() == null || v.getName().isEmpty()).collect(Collectors.toList());
    registrant.getVisitors().removeAll(toBeRemoved);
    registrant.getVisitors().forEach(visitor -> visitor.setStatus(VisitorStatus.REQUESTING));
    if (!registrant.isCompany()) {
        handlePersonalRegistrant(registrant);
    }
    registrant.setPaymentType(Registrant.PaymentType.BANK_TRANSFER);
    Registrant savedRegistrant = registrantFacade.save(registrant);
    model.addAttribute("tags", userFacade.findAllTags());
    InvoiceData invoiceData = buildInvoiceData(savedRegistrant);
    byte[] pdf = invoiceExporter.exportInvoice(invoiceData, registrant.isCompany());
    sendPDF(savedRegistrant, generatePdfFilename(registrant, invoiceData.getSinglePriceWithVAT()), pdf);
    return result("ok", model);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) BindingResult(org.springframework.validation.BindingResult) MailService(site.facade.MailService) Controller(org.springframework.stereotype.Controller) InvoiceExporter(site.controller.invoice.InvoiceExporter) Valid(javax.validation.Valid) HttpServletRequest(javax.servlet.http.HttpServletRequest) Model(org.springframework.ui.Model) Calendar(java.util.Calendar) Visitor(site.model.Visitor) Qualifier(org.springframework.beans.factory.annotation.Qualifier) UserService(site.facade.UserService) Transactional(javax.transaction.Transactional) Registrant(site.model.Registrant) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Collectors(java.util.stream.Collectors) InvoiceData(site.controller.invoice.InvoiceData) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RegistrantService(site.facade.RegistrantService) LogManager(org.apache.logging.log4j.LogManager) VisitorStatus(site.model.VisitorStatus) Visitor(site.model.Visitor) InvoiceData(site.controller.invoice.InvoiceData) Registrant(site.model.Registrant) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Registrant

use of site.model.Registrant in project jprime by bgjug.

the class TicketsController method goToRegisterPage.

@RequestMapping(value = "/tickets/epay", method = RequestMethod.GET)
public String goToRegisterPage(Model model) {
    model.addAttribute("tags", userFacade.findAllTags());
    model.addAttribute("registrant", new Registrant());
    return site.config.Globals.PAGE_TICKETS;
}
Also used : Registrant(site.model.Registrant) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Registrant

use of site.model.Registrant in project jprime by bgjug.

the class AdminVisitorController method add.

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@Valid final Visitor visitor, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return VISITOR_EDIT_JSP;
    }
    // may be its better to use a set of registrants for sponsors?
    String redirectUrl = "redirect:/admin/visitor/view";
    Registrant registrant = new Registrant();
    if (visitor.getRegistrant().getId() == null) {
        // This means that we came here from the visitors admin panel
        registrant.setName(visitor.getName());
        registrant.setEmail(visitor.getEmail());
        registrant = adminFacade.saveRegistrant(registrant);
    } else {
        // This means that we came here from the registrant admin panel
        registrant = adminFacade.findOneRegistrant(visitor.getRegistrant().getId());
        redirectUrl = "redirect:/admin/registrant/edit/" + visitor.getRegistrant().getId();
    }
    visitor.setRegistrant(registrant);
    adminFacade.saveVisitor(visitor);
    return redirectUrl;
}
Also used : Registrant(site.model.Registrant) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Registrant

use of site.model.Registrant in project jprime by bgjug.

the class RegistrantControllerTest method insertTestRegistrants.

private void insertTestRegistrants() {
    adamsFamily = new Registrant(true, "Adams Family", "0001 Cemetery Lane", "666", "Gomez Adamz", "gomez@adams.com");
    List<Visitor> adamsVisitors = Arrays.asList(new Visitor(adamsFamily, "Lurch Adams", "lurch@adams.com", "Adams Family"), new Visitor(adamsFamily, "Morticia Adams", "morticia@adams.com", "Adams Family"));
    adamsFamily.setVisitors(adamsVisitors);
    adamsFamily = registrantRepository.save(adamsFamily);
    ivan = new Registrant("Ivan St. Ivanov", "ivan.st.ivanov@gmail.com");
    ivan.setVisitors(Arrays.asList(new Visitor(ivan, "Ivan St. Ivanov", "ivan.st.ivanov@gmail.com", "JUG")));
    ivan = registrantRepository.save(ivan);
}
Also used : Visitor(site.model.Visitor) Registrant(site.model.Registrant)

Example 5 with Registrant

use of site.model.Registrant in project jprime by bgjug.

the class TicketsEpayRegisterControllerTest method shouldBeAbleToSaveMoreVisitorsForOneRegistrant.

@Test
@Ignore("ignored since adding captcha, has to be updated")
public void shouldBeAbleToSaveMoreVisitorsForOneRegistrant() throws Exception {
    mockMvc.perform(post("/tickets/epay").param("visitors[0].name", "Lurch").param("visitors[0].email", "lurch@example.com").param("visitors[1].name", "Morticia Adams").param("visitors[1].email", "morticia@example.com").param("company", "true").param("name", "Adams Family").param("address", "0001 Cemetery Lane").param("vatNumber", "666").param("mol", "Gomez Adams").param("email", "gomez@adams.com")).andExpect(status().isOk()).andExpect(view().name(TICKETS_RESULT_JSP));
    List<Registrant> allRegistrants = (List<Registrant>) registrantRepository.findAll();
    assertThat(allRegistrants.size(), is(1));
    Registrant registrant = allRegistrants.get(0);
    assertThat(2, is(registrant.getVisitors().size()));
    assertThat(registrant.getVisitors().get(0).getName(), anyOf(is("Morticia Adams"), is("Lurch")));
    assertThat(VisitorStatus.REQUESTING, is(registrant.getVisitors().get(0).getStatus()));
}
Also used : Registrant(site.model.Registrant) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Registrant (site.model.Registrant)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 List (java.util.List)4 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (javax.transaction.Transactional)2 Visitor (site.model.Visitor)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Collectors (java.util.stream.Collectors)1 MessagingException (javax.mail.MessagingException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Valid (javax.validation.Valid)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Controller (org.springframework.stereotype.Controller)1 Model (org.springframework.ui.Model)1