use of javax.transaction.Transactional in project jprime by bgjug.
the class PartnerController method add.
@Transactional
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@Valid final Partner partner, BindingResult bindingResult, @RequestParam("file") MultipartFile file) {
if (bindingResult.hasErrors()) {
System.out.println(bindingResult.getAllErrors());
return "/admin/partner/edit.jsp";
}
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
partner.setLogo(thumbnailService.thumbImage(bytes, 180, 64));
} catch (Exception e) {
e.printStackTrace();
}
} else {
// empty file is it edit?
if (partner.getId() != null) {
Partner oldPartner = adminFacade.findOnePartner(partner.getId());
byte[] oldImage = oldPartner.getLogo();
partner.setLogo(oldImage);
}
}
this.adminFacade.savePartner(partner);
return "redirect:/admin/partner/view";
}
use of javax.transaction.Transactional 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);
}
use of javax.transaction.Transactional in project jprime by bgjug.
the class AdminSpeakerController method add.
@Transactional
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@Valid final Speaker speaker, BindingResult bindingResult, @RequestParam("file") MultipartFile file, Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("branches", Branch.values());
return "/admin/speaker/edit.jsp";
}
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
speaker.setPicture(thumbnailService.thumbImage(bytes, 280, 326));
} catch (Exception e) {
e.printStackTrace();
}
} else {
// empty file is it edit?
if (speaker.getId() != null) {
Speaker oldSpeaker = adminFacade.findOneSpeaker(speaker.getId());
byte[] oldImage = oldSpeaker.getPicture();
speaker.setPicture(oldImage);
}
}
this.adminFacade.saveSpeaker(speaker);
return "redirect:/admin/speaker/view";
}
use of javax.transaction.Transactional in project jprime by bgjug.
the class AdminSpeakerController method edit.
@Transactional
@RequestMapping(value = "/edit/{itemId}", method = RequestMethod.GET)
public String edit(@PathVariable("itemId") Long itemId, Model model) {
Speaker speaker = adminFacade.findOneSpeaker(itemId);
model.addAttribute("speaker", speaker);
model.addAttribute("branches", Branch.values());
return "/admin/speaker/edit.jsp";
}
use of javax.transaction.Transactional in project openlmis-stockmanagement by OpenLMIS.
the class StockCardTemplateService method saveOrUpdate.
/**
* Save or update stock card template by facility type id and program id.
*
* @param templateDto object to save or update.
* @return the saved or updated object.
*/
@Transactional
public StockCardTemplateDto saveOrUpdate(StockCardTemplateDto templateDto) {
checkProgramAndFacilityTypeIdNotNull(templateDto);
checkFieldsDuplication(templateDto);
StockCardTemplate template = templateDto.toModel(findAllFieldsFrom(cardFieldsRepo).collect(toList()), findAllFieldsFrom(lineItemFieldsRepo).collect(toList()));
StockCardTemplate found = templateRepository.findByProgramIdAndFacilityTypeId(template.getProgramId(), template.getFacilityTypeId());
if (found != null) {
template.setId(found.getId());
templateRepository.delete(found);
} else {
programFacilityTypeExistenceService.checkProgramAndFacilityTypeExist(template.getProgramId(), template.getFacilityTypeId());
}
return StockCardTemplateDto.from(templateRepository.save(template));
}
Aggregations