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());
}
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);
}
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());
}
}
}
}
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";
}
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";
}
Aggregations