Search in sources :

Example 1 with Partner

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

the class IndexController method getPartnerChunks.

private List<List<Partner>> getPartnerChunks(List<Partner> partners) {
    List<List<Partner>> partnerChunks = new LinkedList<>();
    int partnersCount = 0;
    List<Partner> currentChunk = new LinkedList<>();
    for (Partner partner : partners) {
        currentChunk.add(partner);
        partnersCount++;
        if (partnersCount == PARTNERS_CHUNK_SIZE) {
            partnerChunks.add(currentChunk);
            partnersCount = 0;
            currentChunk = new LinkedList<>();
        }
    }
    if (partnersCount > 0) {
        partnerChunks.add(currentChunk);
    }
    return partnerChunks;
}
Also used : Partner(site.model.Partner)

Example 2 with Partner

use of site.model.Partner 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";
}
Also used : Partner(site.model.Partner) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Partner

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

the class PartnerController method edit.

@Transactional
@RequestMapping(value = "/edit/{itemId}", method = RequestMethod.GET)
public String edit(@PathVariable("itemId") Long itemId, Model model) {
    Partner partner = adminFacade.findOnePartner(itemId);
    model.addAttribute("partner", partner);
    return "/admin/partner/edit.jsp";
}
Also used : Partner(site.model.Partner) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Partner (site.model.Partner)3 Transactional (javax.transaction.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2