Search in sources :

Example 1 with Visitor

use of site.model.Visitor 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 Visitor

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

the class RegistrantService method save.

/**
 * Complicated
 */
public synchronized Registrant save(Registrant registrant) {
    if (registrant.getPaymentType().equals(Registrant.PaymentType.BANK_TRANSFER)) {
        long counter = getProformaInvoiceNumber();
        registrant.setProformaInvoiceNumber(counter);
    } else {
        if (registrant.getEpayInvoiceNumber() == 0) {
            // only if new registrant
            long counter = getEpayInvoiceNumber();
            registrant.setEpayInvoiceNumber(counter);
        }
        // only if registrant has the epay info. now a real invoice number must be produced
        if (registrant.getEpayResponse() != null && registrant.getRealInvoiceNumber() == 0) {
            generateInvoiceNumber(registrant);
        }
    }
    // todo: mihail this is not optimal, but for now it works
    for (Visitor visitor : registrant.getVisitors()) {
        visitor.setRegistrant(registrant);
    }
    return registrantRepository.save(registrant);
}
Also used : Visitor(site.model.Visitor)

Example 3 with Visitor

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

the class AdminVisitorController method exportVisitors.

@RequestMapping(value = "/export", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<byte[]> exportVisitors() throws IOException {
    Iterable<Visitor> visitors = adminFacade.findAllVisitors();
    final String[] header = new String[] { "name", "email", "company", "status" };
    ICsvBeanWriter beanWriter = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        beanWriter = new CsvBeanWriter(new BufferedWriter(new OutputStreamWriter(out)), CsvPreference.STANDARD_PREFERENCE);
        beanWriter.writeHeader(header);
        for (Visitor visitor : visitors) {
            beanWriter.write(visitor, header, getProcessors());
        }
    } finally {
        if (beanWriter != null) {
            beanWriter.close();
        }
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    return ResponseEntity.ok().headers(headers).body(out.toByteArray());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Visitor(site.model.Visitor) ICsvBeanWriter(org.supercsv.io.ICsvBeanWriter) CsvBeanWriter(org.supercsv.io.CsvBeanWriter) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ICsvBeanWriter(org.supercsv.io.ICsvBeanWriter) BufferedWriter(java.io.BufferedWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Visitor

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

the class AdminVisitorController method getNewVisitorForm.

@RequestMapping(value = "/add", method = RequestMethod.GET)
public String getNewVisitorForm(Model model) {
    model.addAttribute("visitor", new Visitor());
    model.addAttribute("statuses", VisitorStatus.values());
    return VISITOR_EDIT_JSP;
}
Also used : Visitor(site.model.Visitor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Visitor

use of site.model.Visitor 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)

Aggregations

Visitor (site.model.Visitor)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Registrant (site.model.Registrant)2 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MessagingException (javax.mail.MessagingException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Transactional (javax.transaction.Transactional)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 HttpHeaders (org.springframework.http.HttpHeaders)1 Controller (org.springframework.stereotype.Controller)1