Search in sources :

Example 1 with EsupPapercutSessionObject

use of org.esupportail.papercut.domain.EsupPapercutSessionObject in project esup-papercut by EsupPortail.

the class PayBoxResourceController method getStats.

@RequestMapping(value = "/statsPapercut")
public void getStats(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException {
    HttpSession session = request.getSession();
    String sharedSessionId = request.getParameter("sharedSessionId");
    if (sharedSessionId != null) {
        EsupPapercutSessionObject objectShared = (EsupPapercutSessionObject) session.getAttribute(sharedSessionId);
        String requeteNbTransactions = objectShared.getRequeteNbTransactions();
        String requeteMontantTransactions = objectShared.getRequeteMontantTransactions();
        String requeteCumulTransactions = objectShared.getRequeteCumulTransactions();
        String requeteCumulMontants = objectShared.getRequeteCumulMontants();
        if (objectShared.isIsAdmin()) {
            String flexJsonString = "Aucune statistique à récupérer";
            try {
                JSONSerializer serializer = new JSONSerializer();
                flexJsonString = serializer.deepSerialize(statsService.getStatsPapercut(requeteNbTransactions, requeteMontantTransactions, requeteCumulTransactions, requeteCumulMontants));
            } 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 : EsupPapercutSessionObject(org.esupportail.papercut.domain.EsupPapercutSessionObject) HttpSession(javax.servlet.http.HttpSession) InputStream(java.io.InputStream) IOException(java.io.IOException) ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) JSONSerializer(flexjson.JSONSerializer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EsupPapercutSessionObject

use of org.esupportail.papercut.domain.EsupPapercutSessionObject in project esup-papercut by EsupPortail.

the class EsupPapercutPortletController method adminList.

@RequestMapping(params = "action=admin")
public ModelAndView adminList(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, @RequestParam(value = "sortFieldName", required = false) String sortFieldName, @RequestParam(value = "sortOrder", required = false) String sortOrder, RenderRequest request, RenderResponse response) {
    boolean isAdmin = isAdmin(request);
    boolean isManager = isManager(request);
    ModelMap model = new ModelMap();
    model.put("isAdmin", isAdmin);
    model.put("adminView", true);
    model.put("isManager", isManager);
    if (isAdmin || isManager) {
        String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
        if (sortFieldName == null) {
            sortFieldName = "transactionDate";
            sortOrder = "desc";
        }
        if (size == null) {
            size = 10;
        }
        if (page != null || size != null) {
            int sizeNo = size == null ? 10 : size.intValue();
            final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
            model.put("payboxpapercuttransactionlogs", PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByPaperCutContextEquals(paperCutContext, sortFieldName, sortOrder).setFirstResult(firstResult).setMaxResults(sizeNo).getResultList());
            float nrOfPages = (float) PayboxPapercutTransactionLog.countFindPayboxPapercutTransactionLogsByPaperCutContextEquals(paperCutContext) / sizeNo;
            model.put("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
        } else {
            model.put("payboxpapercuttransactionlogs", PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByPaperCutContextEquals(paperCutContext, sortFieldName, sortOrder).getResultList());
        }
        addDateTimeFormatPatterns(model);
        String sharedSessionId = response.getNamespace();
        EsupPapercutSessionObject objectShared = new EsupPapercutSessionObject();
        objectShared.setIsAdmin(true);
        objectShared.setPaperCutContext(paperCutContext);
        final PortletPreferences prefs = request.getPreferences();
        objectShared.setRequeteCumulMontants(prefs.getValue(PREF_CUMUL_MONTANT, "useOriginal"));
        objectShared.setRequeteCumulTransactions(prefs.getValue(PREF_CUMUL_TRANSACTIONS, "useOriginal"));
        objectShared.setRequeteMontantTransactions((String) prefs.getValue(PREF_MONTANT_TRANSACTIONS, "useOriginal"));
        objectShared.setRequeteNbTransactions((String) prefs.getValue(PREF_NB_TRANSCATIONS, "useOriginal"));
        PortletUtils.setSessionAttribute(request, sharedSessionId, objectShared, PortletSession.APPLICATION_SCOPE);
        model.put("sharedSessionId", sharedSessionId);
        model.put("active", "admin");
    }
    model.put("sortFieldName", sortFieldName);
    model.put("sortOrder", sortOrder);
    return new ModelAndView(getViewName(request, "history"), model);
}
Also used : EsupPapercutSessionObject(org.esupportail.papercut.domain.EsupPapercutSessionObject) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with EsupPapercutSessionObject

use of org.esupportail.papercut.domain.EsupPapercutSessionObject in project esup-papercut by EsupPortail.

the class EsupPapercutPortletController method renderStats.

@RequestMapping(params = "action=stats")
public ModelAndView renderStats(RenderRequest request, RenderResponse response) {
    boolean isAdmin = isAdmin(request);
    boolean isManager = isManager(request);
    ModelMap model = new ModelMap();
    if (isAdmin || isManager) {
        String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
        String sharedSessionId = response.getNamespace();
        EsupPapercutSessionObject objectShared = new EsupPapercutSessionObject();
        objectShared.setIsAdmin(true);
        objectShared.setPaperCutContext(paperCutContext);
        model.put("sharedSessionId", sharedSessionId);
        model.put("sessionId", sharedSessionId);
        model.put("objectShared", objectShared);
        final PortletPreferences prefs = request.getPreferences();
        objectShared.setRequeteCumulMontants(prefs.getValue(PREF_CUMUL_MONTANT, "useOriginal"));
        objectShared.setRequeteCumulTransactions(prefs.getValue(PREF_CUMUL_TRANSACTIONS, "useOriginal"));
        objectShared.setRequeteMontantTransactions((String) prefs.getValue(PREF_MONTANT_TRANSACTIONS, "useOriginal"));
        objectShared.setRequeteNbTransactions((String) prefs.getValue(PREF_NB_TRANSCATIONS, "useOriginal"));
        PortletUtils.setSessionAttribute(request, sharedSessionId, objectShared, PortletSession.APPLICATION_SCOPE);
    }
    model.put("isAdmin", isAdmin);
    model.put("isManager", isManager);
    model.put("active", "stats");
    return new ModelAndView(getViewName(request, "stats"), model);
}
Also used : EsupPapercutSessionObject(org.esupportail.papercut.domain.EsupPapercutSessionObject) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with EsupPapercutSessionObject

use of org.esupportail.papercut.domain.EsupPapercutSessionObject in project esup-papercut by EsupPortail.

the class PayBoxResourceController method getCsv.

@RequestMapping("/csv")
@Transactional
public void getCsv(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpSession session = request.getSession();
    String sharedSessionId = request.getParameter("sharedSessionId");
    if (sharedSessionId != null) {
        EsupPapercutSessionObject objectShared = (EsupPapercutSessionObject) session.getAttribute(sharedSessionId);
        if (objectShared.isIsAdmin()) {
            StopWatch stopWatch = new StopWatch("Stream - build CSV and send it");
            stopWatch.start();
            response.setContentType("text/csv");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-Disposition", "attachment; filename=\"paybox_papercut_transaction_log.csv\"");
            Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
            String csv = "Date transaction,uid,montant,ID transaction paybox";
            writer.write(csv);
            TypedQuery<PayboxPapercutTransactionLog> txLogsQuery = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByPaperCutContextEquals(objectShared.getPaperCutContext(), "transactionDate", "asc");
            int offset = 0;
            int nbLine = 0;
            List<PayboxPapercutTransactionLog> txLogs;
            while ((txLogs = txLogsQuery.setFirstResult(offset).setMaxResults(1000).getResultList()).size() > 0) {
                log.debug("Build CSV Iteration - offset : " + offset);
                for (PayboxPapercutTransactionLog txLog : txLogs) {
                    csv = "";
                    csv = csv + "\r\n";
                    csv = csv + txLog.getTransactionDate() + ",";
                    csv = csv + txLog.getUid() + ",";
                    csv = csv + txLog.getMontant() + ",";
                    csv = csv + txLog.getIdtrans();
                    writer.write(csv);
                    nbLine++;
                }
                offset += txLogs.size();
            }
            stopWatch.stop();
            log.info("CSV of " + nbLine + " lines sent in " + stopWatch.getTotalTimeSeconds() + " sec.");
            writer.close();
        }
    }
}
Also used : EsupPapercutSessionObject(org.esupportail.papercut.domain.EsupPapercutSessionObject) HttpSession(javax.servlet.http.HttpSession) OutputStreamWriter(java.io.OutputStreamWriter) PayboxPapercutTransactionLog(org.esupportail.papercut.domain.PayboxPapercutTransactionLog) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) StopWatch(org.springframework.util.StopWatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EsupPapercutSessionObject (org.esupportail.papercut.domain.EsupPapercutSessionObject)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PortletPreferences (javax.portlet.PortletPreferences)2 HttpSession (javax.servlet.http.HttpSession)2 ModelMap (org.springframework.ui.ModelMap)2 ModelAndView (org.springframework.web.portlet.ModelAndView)2 JSONSerializer (flexjson.JSONSerializer)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 PayboxPapercutTransactionLog (org.esupportail.papercut.domain.PayboxPapercutTransactionLog)1 Transactional (org.springframework.transaction.annotation.Transactional)1 StopWatch (org.springframework.util.StopWatch)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1