Search in sources :

Example 21 with ServiceException

use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.

the class JReportUtils method fillReportToResponse.

public static void fillReportToResponse(String reportId, Map<String, Object> paramMap, HttpServletResponse response) throws ServiceException, Exception {
    if (StringUtils.isBlank(reportId)) {
        throw new java.lang.IllegalArgumentException("error, reportId is blank");
    }
    TbSysJreport sysJreport = new TbSysJreport();
    sysJreport.setReportId(reportId);
    DefaultResult<TbSysJreport> result = sysJreportService.findEntityByUK(sysJreport);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    sysJreport = result.getValue();
    String jasperFileFullPath = Constants.getDeployJasperReportDir() + "/" + sysJreport.getReportId() + "/" + sysJreport.getReportId() + ".jasper";
    File jasperFile = new File(jasperFileFullPath);
    if (!jasperFile.exists()) {
        jasperFile = null;
        throw new Exception("error, Files are missing : " + jasperFileFullPath);
    }
    InputStream reportSource = new FileInputStream(jasperFile);
    Connection conn = null;
    try {
        conn = DataUtils.getConnection();
        ServletOutputStream ouputStream = response.getOutputStream();
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, paramMap, conn);
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline; filename=" + sysJreport.getReportId() + ".pdf");
        JRPdfExporter jrPdfExporter = new JRPdfExporter();
        jrPdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        jrPdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(ouputStream));
        SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
        jrPdfExporter.setConfiguration(configuration);
        configuration.setOwnerPassword(Constants.getEncryptorKey1());
        jrPdfExporter.exportReport();
        ouputStream.flush();
        ouputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DataUtils.doReleaseConnection(conn);
        if (null != reportSource) {
            try {
                reportSource.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        reportSource = null;
        jasperFile = null;
    }
}
Also used : TbSysJreport(com.netsteadfast.greenstep.po.hbm.TbSysJreport) ServletOutputStream(javax.servlet.ServletOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Connection(java.sql.Connection) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) IOException(java.io.IOException) JRException(net.sf.jasperreports.engine.JRException) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) FileInputStream(java.io.FileInputStream) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SimplePdfExporterConfiguration(net.sf.jasperreports.export.SimplePdfExporterConfiguration) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 22 with ServiceException

use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.

the class ApplicationSiteUtils method configureHost.

@SuppressWarnings("unchecked")
public static void configureHost(String sysId, String logConfFileFullPath) {
    String logValue = FSUtils.readStr(logConfFileFullPath).trim();
    if (!StringUtils.isBlank(logValue) && UPDATE_HOST_ONLY_FIRST_ONE.equals(Constants.getApplicationSiteHostUpdateMode())) {
        // has before start log file, and UPDATE_HOST_ONLY_FIRST_ONE mode
        FSUtils.writeStr2(logConfFileFullPath, UPDATE_HOST_ONLY_FIRST_ONE);
        return;
    }
    ISysService<SysVO, TbSys, String> sysService = (ISysService<SysVO, TbSys, String>) AppContext.getBean("core.service.SysService");
    SysVO sys = new SysVO();
    sys.setSysId(sysId);
    try {
        DefaultResult<SysVO> result = sysService.findByUK(sys);
        if (result.getValue() == null) {
            System.out.println(result.getSystemMessage().getValue());
            return;
        }
        sys = result.getValue();
        // 2016-06-29 rem
        /*
			String port = "";
			String tmp[] = sys.getHost().split(":");
			if ( tmp!=null && tmp.length==2 ) {
				port = tmp[1];
			}
			*/
        // 2016-06-29 add
        String port = String.valueOf(HostUtils.getHttpPort());
        String hostAddress = HostUtils.getHostAddress();
        sys.setHost(hostAddress);
        if (!StringUtils.isBlank(port)) {
            sys.setHost(hostAddress + ":" + port);
        }
        sysService.updateObject(sys);
        if (UPDATE_HOST_ALWAYS.equals(Constants.getApplicationSiteHostUpdateMode())) {
            FSUtils.writeStr2(logConfFileFullPath, UPDATE_HOST_ALWAYS);
        } else {
            FSUtils.writeStr2(logConfFileFullPath, UPDATE_HOST_ONLY_FIRST_ONE);
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TbSys(com.netsteadfast.greenstep.po.hbm.TbSys) ISysService(com.netsteadfast.greenstep.service.ISysService) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysVO(com.netsteadfast.greenstep.vo.SysVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 23 with ServiceException

use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.

the class ApplicationSiteUtils method getSystemsCheckCrossSiteWithTestConnection.

@SuppressWarnings("unchecked")
public static List<SysVO> getSystemsCheckCrossSiteWithTestConnection(HttpServletRequest request) {
    ISysService<SysVO, TbSys, String> sysService = (ISysService<SysVO, TbSys, String>) AppContext.getBean("core.service.SysService");
    List<SysVO> sysList = null;
    try {
        sysList = sysService.findListVOByParams(null);
        for (SysVO sys : sysList) {
            if (checkCrossSite(sys.getHost().toLowerCase(), request)) {
                sys.setCrossSiteFlag(YesNo.YES);
            } else {
                sys.setCrossSiteFlag(YesNo.NO);
            }
            if (checkTestConnection(sys.getHost(), sys.getContextPath(), request)) {
                sys.setTestFlag(YesNo.YES);
            } else {
                sys.setTestFlag(YesNo.NO);
            }
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sysList;
}
Also used : TbSys(com.netsteadfast.greenstep.po.hbm.TbSys) ISysService(com.netsteadfast.greenstep.service.ISysService) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysVO(com.netsteadfast.greenstep.vo.SysVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 24 with ServiceException

use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.

the class BusinessProcessManagementUtils method isRoleAllowApproval.

public static boolean isRoleAllowApproval(String resourceId, String roleId, String taskName) throws ServiceException, Exception {
    if (StringUtils.isBlank(resourceId) || StringUtils.isBlank(roleId) || StringUtils.isBlank(taskName)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    TbSysBpmnResourceRole resourceRole = new TbSysBpmnResourceRole();
    resourceRole.setId(resourceId);
    resourceRole.setRole(roleId);
    resourceRole.setTaskName(taskName);
    if (sysBpmnResourceRoleService.countByEntityUK(resourceRole) > 0) {
        return true;
    }
    return false;
}
Also used : TbSysBpmnResourceRole(com.netsteadfast.greenstep.po.hbm.TbSysBpmnResourceRole) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Example 25 with ServiceException

use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.

the class MenuSupportUtils method loadSysMenuData.

protected static List<SysMenuVO> loadSysMenuData(String system) throws ServiceException, Exception {
    List<SysMenuVO> menuList = null;
    TbSys sys = new TbSys();
    sys.setSysId(system);
    if (sysService.countByEntityUK(sys) != 1) {
        // 必需要有 TB_SYS 資料
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
    }
    Subject subject = SecurityUtils.getSubject();
    String account = (String) subject.getPrincipal();
    if (StringUtils.isBlank(account)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
    }
    if (subject.hasRole(Constants.SUPER_ROLE_ADMIN) || subject.hasRole(Constants.SUPER_ROLE_ALL)) {
        account = null;
    }
    DefaultResult<List<SysMenuVO>> result = sysMenuService.findForMenuGenerator(system, account);
    if (result.getValue() != null) {
        menuList = result.getValue();
    }
    if (menuList == null) {
        menuList = new ArrayList<SysMenuVO>();
    }
    return menuList;
}
Also used : TbSys(com.netsteadfast.greenstep.po.hbm.TbSys) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Subject(org.apache.shiro.subject.Subject)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)291 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)91 Transactional (org.springframework.transaction.annotation.Transactional)89 HashMap (java.util.HashMap)65 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)49 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)48 SysVO (com.netsteadfast.greenstep.vo.SysVO)30 IOException (java.io.IOException)24 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)20 EmployeeVO (com.netsteadfast.greenstep.vo.EmployeeVO)19 List (java.util.List)19 Map (java.util.Map)19 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)17 OrganizationVO (com.netsteadfast.greenstep.vo.OrganizationVO)16 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)15 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)15 SysUploadVO (com.netsteadfast.greenstep.vo.SysUploadVO)14 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)13 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)12