Search in sources :

Example 1 with EsupPapercutContext

use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.

the class AdminController method getStatsInfos.

@RequestMapping(value = "/statsPapercut")
public void getStatsInfos(HttpServletResponse response) throws IOException, ServletRequestBindingException {
    String flexJsonString = "Aucune statistique à récupérer";
    EsupPapercutContext context = config.getContext(ContextHelper.getCurrentContext());
    try {
        JSONSerializer serializer = new JSONSerializer();
        flexJsonString = serializer.deepSerialize(statsService.getStatsPapercut(context));
    } catch (Exception e) {
        log.warn("Impossible de récupérer les statistiques", e);
    }
    InputStream jsonStream = IOUtils.toInputStream(flexJsonString, "utf-8");
    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");
    FileCopyUtils.copy(jsonStream, response.getOutputStream());
}
Also used : InputStream(java.io.InputStream) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) IOException(java.io.IOException) ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) JSONSerializer(flexjson.JSONSerializer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EsupPapercutContext

use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.

the class UserController method izlypayForm.

@PostMapping(value = "izlypay", produces = "text/html")
public ModelAndView izlypayForm(@RequestParam Integer montant) {
    EsupPapercutContext context = config.getContext(ContextHelper.getCurrentContext());
    if (context == null) {
        new ModelAndView("redirect:/");
    }
    String uid = getUid();
    String userMail = getUserMail();
    String izlyPayUrl = esupPaperCutService.getIzlyPayUrl(context, uid, userMail, montant, ContextHelper.getCurrentContext());
    return new ModelAndView("redirect:" + izlyPayUrl);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with EsupPapercutContext

use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.

the class WebInterceptor method postHandle.

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    String context = WebUtils.getContext(request);
    if ("webjars".equals(context) || "resources".equals(context)) {
        super.postHandle(request, response, handler, modelAndView);
    } else {
        ContextHelper.setCurrentContext(context);
        super.postHandle(request, response, handler, modelAndView);
        if (modelAndView != null) {
            boolean isViewObject = modelAndView.getView() == null;
            boolean isRedirectView = !isViewObject && modelAndView.getView() instanceof RedirectView;
            boolean viewNameStartsWithRedirect = isViewObject && modelAndView.getViewName().startsWith(UrlBasedViewResolver.REDIRECT_URL_PREFIX);
            if (!isRedirectView && !viewNameStartsWithRedirect && context != null) {
                EsupPapercutContext configContext = config.getContext(context);
                if (configContext != null) {
                    modelAndView.addObject("title", configContext.getTitle());
                    modelAndView.addObject("htmlFooter", configContext.getHtmlFooter());
                    modelAndView.addObject("pContext", context);
                }
                modelAndView.addObject("isAdmin", WebUtils.isAdmin());
                modelAndView.addObject("isManager", WebUtils.isManager());
                modelAndView.addObject("availableContexts", WebUtils.availableContexts());
                modelAndView.addObject("payAvailable", !esupPaperCutService.getPayModes(configContext).isEmpty());
            }
        }
    }
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext)

Example 4 with EsupPapercutContext

use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.

the class UserController method userView.

@GetMapping(produces = "text/html")
public String userView(HttpServletRequest request, Model uiModel) {
    EsupPapercutContext context = config.getContext(ContextHelper.getCurrentContext());
    if (context == null) {
        return "redirect:/";
    }
    double papercutSheetCost = context.getPapercutSheetCost();
    double papercutColorSheetCost = context.getPapercutColorSheetCost();
    String uid = getUid();
    String userMail = getUserMail();
    // check if the user can make a transaction
    int transactionNbMax = context.getTransactionNbMax();
    int transactionMontantMax = context.getTransactionMontantMax();
    boolean canMakeTransaction = true;
    // constraints via transactionNbMax
    if (transactionNbMax > -1) {
        long nbTransactionsNotArchived = papercutDaoService.countByUidAndArchived(uid, false);
        if (transactionNbMax <= nbTransactionsNotArchived) {
            canMakeTransaction = false;
        }
    }
    Integer montantMin = context.getMontantMin();
    Integer montantMax = context.getMontantMax();
    Integer montantStep = context.getMontantStep();
    // constraints via transactionMontantMax
    if (canMakeTransaction && transactionMontantMax > -1) {
        Page<PayPapercutTransactionLog> transactionsNotArchived = papercutDaoService.findPayPapercutTransactionLogsByUidAndArchived(uid, false, PageRequest.of(0, Integer.MAX_VALUE));
        Integer montantTotalTransactionsNotArchived = 0;
        for (PayPapercutTransactionLog txLog : transactionsNotArchived.getContent()) {
            montantTotalTransactionsNotArchived = montantTotalTransactionsNotArchived + txLog.getMontant();
        }
        transactionMontantMax = transactionMontantMax - montantTotalTransactionsNotArchived;
        if (transactionMontantMax < montantMax) {
            montantMax = transactionMontantMax;
            if (montantMax.compareTo(montantMin) == -1) {
                canMakeTransaction = false;
            }
            uiModel.addAttribute("payboxMontantMax", montantMax.doubleValue());
        }
    }
    // generation de l'ensemble des payboxForm :  payboxMontantMin -> payboxMontantMax par pas de payboxMontantStep
    String contextPath = request.getContextPath();
    if (esupPaperCutService.getPayModes(context).contains(PayMode.PAYBOX)) {
        Map<Integer, PayBoxForm> payboxForms = new TreeMap<Integer, PayBoxForm>();
        for (Integer montant = montantMin; montant.compareTo(montantMax) <= 0; montant = montant + montantStep) {
            PayBoxForm payBoxForm = esupPaperCutService.getPayBoxForm(context, uid, userMail, montant, contextPath);
            payBoxForm.setToolTip(getToolTipMessage(payBoxForm.getMontant(), montant, papercutSheetCost, papercutColorSheetCost));
            payboxForms.put(montant, payBoxForm);
        }
        uiModel.addAttribute("payboxLegend", context.getPaybox().getLegend());
        uiModel.addAttribute("payboxForms", payboxForms);
    }
    if (esupPaperCutService.getPayModes(context).contains(PayMode.IZLYPAY)) {
        Map<Integer, IzlyPayForm> izlypayForms = new TreeMap<Integer, IzlyPayForm>();
        for (Integer montant = montantMin; montant.compareTo(montantMax) <= 0; montant = montant + montantStep) {
            IzlyPayForm izlypayForm = new IzlyPayForm();
            izlypayForm.setMontant(new Double(new Double(montant) / 100.0).toString());
            izlypayForm.setToolTip(getToolTipMessage(izlypayForm.getMontant(), montant, papercutSheetCost, papercutColorSheetCost));
            izlypayForms.put(montant, izlypayForm);
        }
        uiModel.addAttribute("izlypayLegend", context.getIzlypay().getLegend());
        uiModel.addAttribute("izlypayForms", izlypayForms);
    }
    if (esupPaperCutService.getPayModes(context).contains(PayMode.PAYBOX) || esupPaperCutService.getPayModes(context).contains(PayMode.IZLYPAY)) {
        uiModel.addAttribute("tipMessage4MontantMin", getToolTipMessage(new Double(new Double(montantMin) / 100.0).toString(), montantMin, papercutSheetCost, papercutColorSheetCost));
    }
    uiModel.addAttribute("canMakeTransaction", canMakeTransaction);
    UserPapercutInfos userPapercutInfos = esupPaperCutService.getUserPapercutInfos(context, uid);
    uiModel.addAttribute("userPapercutInfos", userPapercutInfos);
    uiModel.addAttribute("isAdmin", WebUtils.isAdmin());
    uiModel.addAttribute("isManager", WebUtils.isManager());
    uiModel.addAttribute("active", "home");
    uiModel.addAttribute("papercutContext", context);
    return "index";
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) IzlyPayForm(org.esupportail.papercut.domain.IzlyPayForm) TreeMap(java.util.TreeMap) PayBoxForm(org.esupportail.papercut.domain.PayBoxForm) UserPapercutInfos(org.esupportail.papercut.domain.UserPapercutInfos) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with EsupPapercutContext

use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.

the class UserController method renderViewAfterPaybox.

/**
 * When user is redirected on esup-papercut after the paybox process,
 * and if validatePayboxJustWithRedirection is true,
 * we validate the transaction regarding informations on queryString
 * (there is a paybox signature that secures this,
 * so we can do that even if we can consider it "less" secure than the direct call of paybox)
 */
@RequestMapping(params = "signature")
public String renderViewAfterPaybox(@PathVariable String papercutContext, @RequestParam(required = false) Integer montant, @RequestParam String reference, @RequestParam(required = false) String auto, @RequestParam String erreur, @RequestParam String idtrans, @RequestParam String signature) {
    EsupPapercutContext context = config.getContext(papercutContext);
    if ("true".equals(context.getValidatePayboxJustWithRedirection())) {
        String uid = getUid();
        String queryString = getQueryString(montant, reference, auto, erreur, idtrans, signature);
        log.debug(queryString);
        esupPaperCutService.payboxCallback(context, montant, reference, auto, erreur, idtrans, signature, queryString, null, uid);
    }
    return "redirect:/user";
}
Also used : EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EsupPapercutContext (org.esupportail.papercut.config.EsupPapercutContext)7 PayPapercutTransactionLog (org.esupportail.papercut.domain.PayPapercutTransactionLog)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONSerializer (flexjson.JSONSerializer)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 IzlyPayForm (org.esupportail.papercut.domain.IzlyPayForm)1 PayBoxForm (org.esupportail.papercut.domain.PayBoxForm)1 UserPapercutInfos (org.esupportail.papercut.domain.UserPapercutInfos)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1