Search in sources :

Example 1 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project cas by apereo.

the class WebUtils method produceErrorView.

/**
     * Produce error view model and view.
     *
     * @param e the e
     * @return the model and view
     */
public static ModelAndView produceErrorView(final Exception e) {
    final Map model = new HashMap<>();
    model.put("rootCauseException", e);
    return new ModelAndView(CasWebflowConstants.VIEW_ID_SERVICE_ERROR, model);
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) HashMap(java.util.HashMap) Map(java.util.Map) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap)

Example 2 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project logprocessing by cloudian.

the class SearchController method onSubmit.

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException arg3) throws Exception {
    SearchCommand cmd = (SearchCommand) command;
    ModelAndView mav = new ModelAndView(getSuccessView());
    CDRDataAccess cdrAccess = new CDRDataAccess();
    Date toDate = SearchCommand.m_sdf.parse(cmd.getToDate());
    long maxTimestamp = toDate.getTime();
    Date fromDate = SearchCommand.m_sdf.parse(cmd.getFromDate());
    long minTimestamp = fromDate.getTime();
    String msisdn = cmd.getMsisdn();
    String action = cmd.getAction();
    Vector<CDREntry> cdrs;
    if (action.compareToIgnoreCase("downloadcsv") == 0) {
        if (msisdn != null && msisdn.length() > 0) {
            cdrs = cdrAccess.getCDRsByMSISDN(cmd.getMsisdn(), minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), // 100,000 entries max
            100000);
        } else {
            cdrs = cdrAccess.getCDRsByHour(minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), MAX_ENTRIES_PER_PAGE);
        }
        StringBuffer sb = new StringBuffer();
        // Write column headers 
        sb.append("Date/Time,Market,Type,MSISDN,MO IP address,MT IP Address,Sender Domain,Recipient Domain\n");
        for (CDREntry entry : cdrs) {
            sb.append(entry.getDisplayTimestamp() + "," + entry.getMarket() + "," + entry.getType() + "," + entry.getMsisdn() + "," + entry.getMoIPAddress() + "," + entry.getMtIPAddress() + "," + entry.getSenderDomain() + "," + entry.getRecipientDomain() + "\n");
        }
        String csvString = sb.toString();
        response.setBufferSize(sb.length());
        response.setContentLength(sb.length());
        response.setContentType("text/plain; charset=UTF-8");
        //response.setContentType( "text/csv" );
        //response.setContentType("application/ms-excel");
        //response.setHeader("Content-disposition", "attachment;filename=cdrResults.csv");
        response.setHeader("Content-Disposition", "attachment; filename=" + "cdrResults.csv" + ";");
        ServletOutputStream os = response.getOutputStream();
        os.write(csvString.getBytes());
        os.flush();
        os.close();
        return null;
    } else if (action.compareToIgnoreCase("graph") == 0) {
        cmd.setGraph(true);
        List<ChartSeries> chartData;
        if (msisdn != null && msisdn.length() > 0) {
            chartData = cdrAccess.getChartDataByMSISDN(cmd.getMsisdn(), minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), 100000);
        } else {
            chartData = cdrAccess.getChartDataByHour(minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), 100000);
        }
        request.getSession().setAttribute("chartData", chartData);
    } else if (action.compareToIgnoreCase("getmore") == 0) {
        cdrs = (Vector<CDREntry>) request.getSession().getAttribute("currentcdrs");
        int numCDRs = cdrs.size();
        CDREntry lastCDR = cdrs.get(numCDRs - 1);
        long lastCDRTime = Long.parseLong(lastCDR.getTimestamp());
        if (msisdn != null && msisdn.length() > 0) {
            Vector<CDREntry> moreCDRs = cdrAccess.getCDRsByMSISDN(cmd.getMsisdn(), lastCDRTime, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), MAX_ENTRIES_PER_PAGE);
            cdrs.addAll(moreCDRs);
        } else {
            Vector<CDREntry> moreCDRs = cdrAccess.getCDRsByHour(lastCDRTime, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), MAX_ENTRIES_PER_PAGE);
            cdrs.addAll(moreCDRs);
        }
        request.getSession().setAttribute("currentcdrs", cdrs);
        mav.addObject("cdrs", cdrs);
    } else {
        // Normal search            
        if (msisdn != null && msisdn.length() > 0) {
            cdrs = cdrAccess.getCDRsByMSISDN(cmd.getMsisdn(), minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), MAX_ENTRIES_PER_PAGE);
        } else {
            cdrs = cdrAccess.getCDRsByHour(minTimestamp, maxTimestamp, cmd.getMarket(), cmd.getMessageType(), MAX_ENTRIES_PER_PAGE);
        }
        request.getSession().setAttribute("currentcdrs", cdrs);
        mav.addObject("cdrs", cdrs);
    }
    mav.addObject("searchCmd", cmd);
    List<Option> msgOptions = getMessageOptions();
    mav.addObject("msgTypes", msgOptions);
    List<Option> marketOptions = getMarketOptions();
    mav.addObject("marketTypes", marketOptions);
    return mav;
}
Also used : CDRDataAccess(com.geminimobile.CDRDataAccess) CDREntry(com.geminimobile.CDRDataAccess.CDREntry) ServletOutputStream(javax.servlet.ServletOutputStream) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project OpenAttestation by OpenAttestation.

the class DemoPortalDataController method getHostsReport.

/**
	 * Method to Bulk Update trust status for selected host.
	 * 
	 * @param req (HttpServletRequest Object)
	 * @param res (HttpServletResponse Object)
	 * @return
	 */
public ModelAndView getHostsReport(HttpServletRequest req, HttpServletResponse res) {
    log.info("DemoPortalDataController.getHostsReport >>");
    ModelAndView responseView = new ModelAndView(new JSONView());
    String[] list = req.getParameterValues("selectedHost");
    if (list == null) {
        responseView.addObject("message", "No hosts were selected for reports.");
        log.info("DemoPortalDataController.getHostsReport<<<");
        return responseView;
    }
    List<String> hosts = Arrays.asList(list);
    try {
        responseView.addObject("reports", demoPortalServices.getHostTrustReport(hosts, getAttestationService(req, ApiClient.class)));
        responseView.addObject("result", true);
    } catch (DemoPortalException e) {
        log.error(e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", e.getMessage());
        return responseView;
    }
    responseView.addObject("message", "");
    log.info("DemoPortalDataController.getHostsReport<<<");
    return responseView;
}
Also used : JSONView(com.intel.mountwilson.util.JSONView) ModelAndView(org.springframework.web.servlet.ModelAndView) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Example 4 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project OpenAttestation by OpenAttestation.

the class DemoPortalDataController method trustVerificationDetailsXML.

/**
	 * Method to get Trust Verification Details using SAML.
	 * 
	 * @param req (HttpServletRequest Object)
	 * @param res (HttpServletResponse Object)
	 * @return
	 */
public ModelAndView trustVerificationDetailsXML(HttpServletRequest req, HttpServletResponse res) {
    log.info("DemoPortalDataController.trustVerificationDetailsXML >>");
    ModelAndView responseView = new ModelAndView(new JSONView());
    String hostName = req.getParameter("hostName");
    try {
        responseView.addObject("trustSamlDetails", demoPortalServices.trustVerificationDetails(hostName, getAttestationService(req, AttestationService.class), getTrustedCertificates(req)));
        responseView.addObject("hostName", hostName);
        responseView.addObject("result", true);
    } catch (DemoPortalException e) {
        log.error(e.toString());
        e.printStackTrace();
        responseView.addObject("result", false);
        responseView.addObject("message", e.getMessage());
        e.printStackTrace();
        return responseView;
    }
    responseView.addObject("message", "");
    responseView.addObject("result", true);
    return responseView;
}
Also used : JSONView(com.intel.mountwilson.util.JSONView) ModelAndView(org.springframework.web.servlet.ModelAndView) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Example 5 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project OpenAttestation by OpenAttestation.

the class WLMDataController method addOSData.

/**
	 * Method to add OS Data into REST Services.
	 * 
	 * @param req (HttpServletRequest Object)
	 * @param res (HttpServletResponse Object)
	 * @return
	 */
public ModelAndView addOSData(HttpServletRequest req, HttpServletResponse res) {
    log.info("WLMDataController.addOSData >>");
    ModelAndView responseView = new ModelAndView(new JSONView());
    try {
        OSDataVO dataVONew = new OSDataVO();
        //Getting OS data from request parameter
        dataVONew.setOsName(req.getParameter("osName"));
        dataVONew.setOsVersion(req.getParameter("osVersion"));
        dataVONew.setOsDescription(req.getParameter("osDescription"));
        //Calling into Service Layer(OSClientServiceImpl) to add OS Data.
        responseView.addObject("result", osClientService.addOSInfo(dataVONew, getWhitelistService(req)));
    } catch (WLMPortalException e) {
        log.error("Error Wile Adding OS Data. Root cause " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", e.getMessage());
    }
    log.info("WLMDataController.addOSData <<<");
    return responseView;
}
Also used : WLMPortalException(com.intel.mountwilson.common.WLMPortalException) JSONView(com.intel.mountwilson.util.JSONView) ModelAndView(org.springframework.web.servlet.ModelAndView) OSDataVO(com.intel.mountwilson.datamodel.OSDataVO)

Aggregations

ModelAndView (org.springframework.web.servlet.ModelAndView)933 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)402 Test (org.junit.Test)235 HashMap (java.util.HashMap)120 ArrayList (java.util.ArrayList)109 RedirectView (org.springframework.web.servlet.view.RedirectView)60 Map (java.util.Map)54 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)51 List (java.util.List)45 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)39 Date (java.util.Date)37 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)35 JSONView (com.intel.mountwilson.util.JSONView)34 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)31 IOException (java.io.IOException)30 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)24 HandlerMethod (org.springframework.web.method.HandlerMethod)24 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)22 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)22 ServletException (javax.servlet.ServletException)21