Search in sources :

Example 11 with ServiceException

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

the class UploadSupportUtils method getRealFile.

public static File getRealFile(String uploadOid) throws ServiceException, IOException, Exception {
    if (StringUtils.isBlank(uploadOid)) {
        throw new Exception("parameter is blank!");
    }
    SysUploadVO uploadObj = findUpload(uploadOid);
    File packageFile = null;
    if (!YesNo.YES.equals(uploadObj.getIsFile())) {
        File dir = new File(Constants.getWorkTmpDir() + "/" + UploadSupportUtils.class.getSimpleName());
        if (!dir.exists() || !dir.isDirectory()) {
            FileUtils.forceMkdir(dir);
        }
        String tmpFileName = dir.getPath() + "/" + SimpleUtils.getUUIDStr() + "." + getFileExtensionName(uploadObj.getShowName());
        dir = null;
        OutputStream fos = null;
        try {
            packageFile = new File(tmpFileName);
            fos = new FileOutputStream(packageFile);
            IOUtils.write(uploadObj.getContent(), fos);
            fos.flush();
        } catch (IOException e) {
            throw e;
        } finally {
            if (fos != null) {
                fos.close();
            }
            fos = null;
        }
    } else {
        String uploadDir = getUploadFileDir(uploadObj.getSystem(), uploadObj.getSubDir(), uploadObj.getType());
        packageFile = new File(uploadDir + "/" + uploadObj.getFileName());
    }
    if (!packageFile.exists()) {
        throw new Exception("File is missing: " + uploadObj.getFileName());
    }
    return packageFile;
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SysUploadVO(com.netsteadfast.greenstep.vo.SysUploadVO) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Example 12 with ServiceException

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

the class HessianServiceProxyAspect method proxyProcess.

private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);
    /**
		 * 不需要被遠端代理的 service-bean
		 */
    if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
        //logger.info( "reject proxy service: " + serviceId );
        return pjp.proceed();
    }
    String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        /**
			 * 沒使用者資訊不能處理遠端代理的 service-bean
			 */
        if (StringUtils.isBlank(userId)) {
            logger.warn("no userId");
            pjp.proceed();
        }
        /**
			 * 此使用者不能存取遠端代理的 service-bean
			 */
        if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
            logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
            return pjp.proceed();
        }
    }
    String serviceInterfacesName = "";
    Class<?>[] serviceInterfaces = pjp.getTarget().getClass().getInterfaces();
    for (Class<?> clazz : serviceInterfaces) {
        if (clazz.getName().indexOf(".service.") > -1) {
            serviceInterfacesName = clazz.getName();
        }
    }
    if (StringUtils.isBlank(serviceInterfacesName)) {
        logger.error("error no service interface: " + serviceId);
        throw new Exception("error no service interface: " + serviceId);
    }
    String url = GreenStepHessianUtils.getServiceUrl(serviceId);
    String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem());
    /**
		 * 不要自己呼叫遠端代理的自己, 會造成 HessianServiceProxyAspect 一直重複觸發 (客戶端與server-remote同一台的情況下)
		 * 如客戶端是 http://127.0.0.1:8080/
		 * 但是客戶端有開啟 hessian.enable=Y 呼叫遠端代理, 然後遠端url設定為 hessian.serverUrl=http://127.0.0.1:8080/
		 * 
		 */
    if (url.indexOf(theSystemPath) > -1) {
        logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
        throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
    }
    logger.info("proxy url = " + url);
    HessianProxyFactory factory = null;
    Object proxyServiceObject = null;
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        // 一般要checkValue模式
        factory = new GreenStepHessianProxyFactory();
        ((GreenStepHessianProxyFactory) factory).setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
        proxyServiceObject = ((GreenStepHessianProxyFactory) factory).createForHeaderMode(Class.forName(serviceInterfacesName), url);
    } else {
        // 不使用checkValue模式
        factory = new HessianProxyFactory();
        proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
    }
    Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
    Method proxyObjectMethod = null;
    if (null == proxyObjectMethods) {
        logger.error("error no find proxy method: " + serviceId);
        throw new Exception("error no find proxy method: " + serviceId);
    }
    for (Method m : proxyObjectMethods) {
        if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
            proxyObjectMethod = m;
        }
    }
    if (null == proxyObjectMethod) {
        logger.error("error no execute proxy method: " + serviceId);
        throw new Exception("error no execute proxy method: " + serviceId);
    }
    Object resultObj = null;
    try {
        resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
        this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
    } catch (InvocationTargetException e) {
        if (e.getMessage() != null) {
            throw new ServiceException(e.getMessage().toString());
        }
        if (e.getTargetException().getMessage() != null) {
            throw new ServiceException(e.getTargetException().getMessage().toString());
        }
        throw e;
    } catch (Exception e) {
        logger.error(e.getMessage().toString());
        throw e;
    }
    logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
    return resultObj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) GreenStepHessianProxyFactory(com.netsteadfast.greenstep.sys.GreenStepHessianProxyFactory) HessianProxyFactory(com.caucho.hessian.client.HessianProxyFactory) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) AuthorityException(com.netsteadfast.greenstep.base.exception.AuthorityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) GreenStepHessianProxyFactory(com.netsteadfast.greenstep.sys.GreenStepHessianProxyFactory)

Example 13 with ServiceException

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

the class SysUploadServiceImpl method updateTypeOnly.

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> updateTypeOnly(String oid, String type) throws ServiceException, Exception {
    if (StringUtils.isBlank(oid) || StringUtils.isBlank(type)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setValue(Boolean.FALSE);
    if (this.sysUploadDAO.updateTypeOnly(oid, type, this.getAccountId()) == 1) {
        result.setValue(Boolean.TRUE);
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    } else {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_FAIL));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with ServiceException

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

the class SysUploadServiceImpl method findForNoByteContent.

@Override
public DefaultResult<SysUploadVO> findForNoByteContent(String oid) throws ServiceException, Exception {
    if (StringUtils.isBlank(oid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    SysUploadVO upload = this.sysUploadDAO.findForNoByteContent(oid);
    DefaultResult<SysUploadVO> result = new DefaultResult<SysUploadVO>();
    if (upload != null && !StringUtils.isBlank(upload.getOid())) {
        result.setValue(upload);
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysUploadVO(com.netsteadfast.greenstep.vo.SysUploadVO) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult)

Example 15 with ServiceException

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

the class ClearTempDataJobImpl method executeInternal.

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    if (ContextLoader.getCurrentWebApplicationContext() == null) {
        log.warn("ApplicationContext no completed, AppContext.getApplicationContext() == null");
        return;
    }
    log.info("begin....");
    try {
        /**
			 * document reference:
			 * com.netsteadfast.greenstep.support.CleanTempUploadForContextInitAndDestroy.java
			 */
        this.loginForBackgroundProgram();
        List<SysVO> systems = ApplicationSiteUtils.getSystems();
        if (systems == null || systems.size() < 1) {
            return;
        }
        for (SysVO sys : systems) {
            UploadSupportUtils.cleanTempUpload(sys.getSysId());
        }
        /**
			 * document reference:
			 * com.netsteadfast.greenstep.bsc.support.CleanJasperReportTempDataForContextInitAndDestroy.java
			 * 
			 */
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
        Map<String, Object> paramMap = new HashMap<String, Object>();
        namedParameterJdbcTemplate.update("delete from bb_swot_report_mst", paramMap);
        namedParameterJdbcTemplate.update("delete from bb_swot_report_dtl", paramMap);
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            this.logoutForBackgroundProgram();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    log.info("end....");
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap) SysVO(com.netsteadfast.greenstep.vo.SysVO) JobExecutionException(org.quartz.JobExecutionException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

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