Search in sources :

Example 1 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class ManualJobServiceImpl method execute.

@WebMethod
@POST
@Path("/executeJob/{uploadOid}")
@Override
public String execute(@WebParam(name = "uploadOid") @PathParam("uploadOid") String uploadOid) throws Exception {
    SysExprJobLogVO result = null;
    Subject subject = null;
    ObjectMapper objectMapper = new ObjectMapper();
    String exceptionMessage = "";
    try {
        Map<String, Object> dataMap = SystemExpressionJobUtils.getDecUploadOid(uploadOid);
        if (dataMap == null || StringUtils.isBlank((String) dataMap.get("accountId")) || StringUtils.isBlank((String) dataMap.get("sysExprJobOid"))) {
            log.error("no data accountId / sysExprJobOid");
            result = new SysExprJobLogVO();
            result.setFaultMsg("no data accountId / sysExprJobOid");
            return objectMapper.writeValueAsString(result);
        }
        String accountId = (String) dataMap.get("accountId");
        String sysExprJobOid = (String) dataMap.get("sysExprJobOid");
        ShiroLoginSupport loginSupport = new ShiroLoginSupport();
        subject = loginSupport.forceCreateLoginSubject(accountId);
        result = SystemExpressionJobUtils.executeJobForManual(sysExprJobOid);
    } catch (ServiceException se) {
        se.printStackTrace();
        exceptionMessage = se.getMessage().toString();
    } catch (Exception e) {
        e.printStackTrace();
        if (e.getMessage() == null) {
            exceptionMessage = e.toString();
        } else {
            exceptionMessage = e.getMessage().toString();
        }
    } finally {
        if (result == null) {
            result = new SysExprJobLogVO();
        }
        if (subject != null) {
            subject.logout();
        }
        if (!StringUtils.isBlank(exceptionMessage) && StringUtils.isBlank(result.getFaultMsg())) {
            result.setFaultMsg(exceptionMessage);
        }
    }
    return objectMapper.writeValueAsString(result);
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) Subject(org.apache.shiro.subject.Subject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ShiroLoginSupport(com.netsteadfast.greenstep.sys.ShiroLoginSupport) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class SystemExpressionJobUtils method getExpressionJobs.

public static List<ExpressionJobObj> getExpressionJobs() throws ServiceException, Exception {
    int year = Integer.parseInt(SimpleUtils.getStrYMD(SimpleUtils.IS_YEAR));
    int month = Integer.parseInt(SimpleUtils.getStrYMD(SimpleUtils.IS_MONTH));
    String dayOfWeek = String.valueOf(SimpleUtils.getDayOfWeek(year, month));
    String hour = String.valueOf(LocalDateTime.now().getHourOfDay());
    String minute = String.valueOf(LocalDateTime.now().getMinuteOfHour());
    List<ExpressionJobObj> jobObjList = new ArrayList<ExpressionJobObj>();
    @SuppressWarnings("unchecked") ISysExprJobService<SysExprJobVO, TbSysExprJob, String> sysExprJobService = (ISysExprJobService<SysExprJobVO, TbSysExprJob, String>) AppContext.getBean("core.service.SysExprJobService");
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("system", Constants.getSystem());
    paramMap.put("active", YesNo.YES);
    List<SysExprJobVO> exprJobList = sysExprJobService.findListVOByParams(paramMap);
    if (null == exprJobList || exprJobList.size() < 1) {
        return jobObjList;
    }
    @SuppressWarnings("unchecked") ISysExpressionService<SysExpressionVO, TbSysExpression, String> sysExpressionService = (ISysExpressionService<SysExpressionVO, TbSysExpression, String>) AppContext.getBean("core.service.SysExpressionService");
    for (SysExprJobVO exprJob : exprJobList) {
        if (ExpressionJobConstants.RUNSTATUS_PROCESS_NOW.equals(exprJob.getRunStatus())) {
            log.warn("[Expression-Job] Please check it, process now, Id: " + exprJob.getExprId() + " , name: " + exprJob.getName());
            continue;
        }
        if (!isRunTime(exprJob, dayOfWeek, hour, minute)) {
            continue;
        }
        ExpressionJobObj jobObj = new ExpressionJobObj();
        jobObj.setSysExprJob(exprJob);
        jobObj.setSysExprJobLog(new SysExprJobLogVO());
        SysExpressionVO expr = new SysExpressionVO();
        expr.setExprId(exprJob.getExprId());
        DefaultResult<SysExpressionVO> exprResult = sysExpressionService.findByUK(expr);
        if (exprResult.getValue() == null) {
            log.error("[Expression-Job] Id: " + exprJob.getExprId() + " , data not found.");
            log.error(exprResult.getSystemMessage().getValue());
            continue;
        }
        expr = exprResult.getValue();
        jobObj.setSysExpression(expr);
        jobObjList.add(jobObj);
    }
    return jobObjList;
}
Also used : SysExprJobVO(com.netsteadfast.greenstep.vo.SysExprJobVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) ISysExpressionService(com.netsteadfast.greenstep.service.ISysExpressionService) TbSysExprJob(com.netsteadfast.greenstep.po.hbm.TbSysExprJob) TbSysExpression(com.netsteadfast.greenstep.po.hbm.TbSysExpression) ISysExprJobService(com.netsteadfast.greenstep.service.ISysExprJobService) ExpressionJobObj(com.netsteadfast.greenstep.model.ExpressionJobObj) SysExpressionVO(com.netsteadfast.greenstep.vo.SysExpressionVO)

Example 3 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class ExpressionJobExecuteCallable method call.

@Override
public ExpressionJobObj call() throws Exception {
    Date beginDatetime = new Date();
    String faultMsg = "";
    String runStatus = "";
    String logStatus = "";
    @SuppressWarnings("unchecked") ISysExprJobService<SysExprJobVO, TbSysExprJob, String> sysExprJobService = (ISysExprJobService<SysExprJobVO, TbSysExprJob, String>) AppContext.getBean("core.service.SysExprJobService");
    @SuppressWarnings("unchecked") ISysExprJobLogService<SysExprJobLogVO, TbSysExprJobLog, String> sysExprJobLogService = (ISysExprJobLogService<SysExprJobLogVO, TbSysExprJobLog, String>) AppContext.getBean("core.service.SysExprJobLogService");
    try {
        logger.info("[Expression-Job] (Start) ID: " + this.jobObj.getSysExprJob().getId() + " , NAME: " + this.jobObj.getSysExprJob().getName());
        if (StringUtils.isBlank(jobObj.getSysExpression().getContent())) {
            faultMsg = "No expression content!";
            runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
            logStatus = ExpressionJobConstants.LOGSTATUS_NO_EXECUTE;
            return this.jobObj;
        }
        if (YesNo.YES.equals(this.jobObj.getSysExprJob().getCheckFault()) && ExpressionJobConstants.RUNSTATUS_FAULT.equals(this.jobObj.getSysExprJob().getRunStatus())) {
            faultMsg = "Before proccess fault, cannot execute expression job!";
            runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
            logStatus = ExpressionJobConstants.LOGSTATUS_NO_EXECUTE;
            return this.jobObj;
        }
        this.jobObj.getSysExprJob().setRunStatus(ExpressionJobConstants.RUNSTATUS_PROCESS_NOW);
        sysExprJobService.updateObject(this.jobObj.getSysExprJob());
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("jobObj", this.jobObj);
        ScriptExpressionUtils.execute(jobObj.getSysExpression().getType(), jobObj.getSysExpression().getContent(), paramMap, paramMap);
        runStatus = ExpressionJobConstants.RUNSTATUS_SUCCESS;
        logStatus = ExpressionJobConstants.LOGSTATUS_SUCCESS;
    } catch (ServiceException se) {
        faultMsg = se.getMessage().toString();
        runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
        logStatus = ExpressionJobConstants.LOGSTATUS_FAULT;
        logger.error(se.getMessage().toString());
    } catch (Exception e) {
        faultMsg = e.getMessage().toString();
        if (e.getMessage() == null) {
            faultMsg = e.toString();
        } else {
            faultMsg = e.getMessage().toString();
        }
        runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
        logStatus = ExpressionJobConstants.LOGSTATUS_FAULT;
        logger.error(faultMsg);
    } finally {
        if (faultMsg.length() > 2000) {
            faultMsg = faultMsg.substring(0, 2000);
        }
        jobObj.getSysExprJob().setRunStatus(runStatus);
        jobObj.getSysExprJobLog().setFaultMsg(faultMsg);
        jobObj.getSysExprJobLog().setLogStatus(logStatus);
        jobObj.getSysExprJobLog().setId(jobObj.getSysExprJob().getId());
        jobObj.getSysExprJobLog().setBeginDatetime(beginDatetime);
        jobObj.getSysExprJobLog().setEndDatetime(new Date());
        sysExprJobService.updateObject(this.jobObj.getSysExprJob());
        DefaultResult<SysExprJobLogVO> jobLogResult = sysExprJobLogService.saveObject(jobObj.getSysExprJobLog());
        if (jobLogResult.getValue() != null) {
            jobObj.setSysExprJobLog(jobLogResult.getValue());
        }
        this.sendMail();
        logger.info("[Expression-Job] (End) ID: " + this.jobObj.getSysExprJob().getId() + " , NAME: " + this.jobObj.getSysExprJob().getName());
    }
    return this.jobObj;
}
Also used : ISysExprJobLogService(com.netsteadfast.greenstep.service.ISysExprJobLogService) SysExprJobVO(com.netsteadfast.greenstep.vo.SysExprJobVO) HashMap(java.util.HashMap) Date(java.util.Date) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TbSysExprJob(com.netsteadfast.greenstep.po.hbm.TbSysExprJob) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TbSysExprJobLog(com.netsteadfast.greenstep.po.hbm.TbSysExprJobLog) ISysExprJobService(com.netsteadfast.greenstep.service.ISysExprJobService)

Example 4 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class SystemExpressionJobSaveOrUpdateAction method manualExecute.

private void manualExecute() throws ControllerException, AuthorityException, ServiceException, Exception {
    String exprJobOid = this.getFields().get("oid");
    String accountId = super.getAccountId();
    SysExprJobVO exprJob = new SysExprJobVO();
    exprJob.setOid(exprJobOid);
    DefaultResult<SysExprJobVO> result = this.sysExprJobService.findObjectByOid(exprJob);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    exprJob = result.getValue();
    if (Constants.getMainSystem().equals(exprJob.getSystem())) {
        // 是自己 CORE系統, 所以不用觸發遠端的服務
        SystemExpressionJobUtils.executeJobForManual(exprJobOid);
        return;
    }
    /*
		SysExprJobLogVO jobLog = SystemExpressionJobUtils.executeJobForManualFromRestServiceUrl(
				exprJob, accountId, this.getHttpServletRequest());
		*/
    SysExprJobLogVO jobLog = SystemExpressionJobUtils.executeJobForManualWebClient(exprJob, accountId, this.getHttpServletRequest());
    if (null != jobLog && !StringUtils.isBlank(jobLog.getFaultMsg())) {
        throw new ServiceException(jobLog.getFaultMsg());
    }
}
Also used : SysExprJobVO(com.netsteadfast.greenstep.vo.SysExprJobVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO)

Example 5 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class SystemExpressionJobUtils method getExpressionJobForManualMode.

public static ExpressionJobObj getExpressionJobForManualMode(String expressionJobOid) throws ServiceException, Exception {
    if (StringUtils.isBlank(expressionJobOid)) {
        throw new Exception("error, expressionJobId is blank!");
    }
    @SuppressWarnings("unchecked") ISysExprJobService<SysExprJobVO, TbSysExprJob, String> sysExprJobService = (ISysExprJobService<SysExprJobVO, TbSysExprJob, String>) AppContext.getBean("core.service.SysExprJobService");
    @SuppressWarnings("unchecked") ISysExpressionService<SysExpressionVO, TbSysExpression, String> sysExpressionService = (ISysExpressionService<SysExpressionVO, TbSysExpression, String>) AppContext.getBean("core.service.SysExpressionService");
    SysExprJobVO exprJob = new SysExprJobVO();
    exprJob.setOid(expressionJobOid);
    DefaultResult<SysExprJobVO> exprJobResult = sysExprJobService.findObjectByOid(exprJob);
    if (exprJobResult.getValue() == null) {
        throw new ServiceException(exprJobResult.getSystemMessage().getValue());
    }
    exprJob = exprJobResult.getValue();
    SysExpressionVO expr = new SysExpressionVO();
    expr.setExprId(exprJob.getExprId());
    DefaultResult<SysExpressionVO> exprResult = sysExpressionService.findByUK(expr);
    if (exprResult.getValue() == null) {
        throw new ServiceException(exprResult.getSystemMessage().getValue());
    }
    expr = exprResult.getValue();
    ExpressionJobObj jobObj = new ExpressionJobObj();
    jobObj.setSysExprJob(exprJob);
    jobObj.setSysExprJobLog(new SysExprJobLogVO());
    jobObj.setSysExpression(expr);
    return jobObj;
}
Also used : SysExprJobVO(com.netsteadfast.greenstep.vo.SysExprJobVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) ISysExpressionService(com.netsteadfast.greenstep.service.ISysExpressionService) TbSysExprJob(com.netsteadfast.greenstep.po.hbm.TbSysExprJob) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TbSysExpression(com.netsteadfast.greenstep.po.hbm.TbSysExpression) ISysExprJobService(com.netsteadfast.greenstep.service.ISysExprJobService) ExpressionJobObj(com.netsteadfast.greenstep.model.ExpressionJobObj) SysExpressionVO(com.netsteadfast.greenstep.vo.SysExpressionVO)

Aggregations

SysExprJobLogVO (com.netsteadfast.greenstep.vo.SysExprJobLogVO)7 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)6 SysExprJobVO (com.netsteadfast.greenstep.vo.SysExprJobVO)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 TbSysExprJob (com.netsteadfast.greenstep.po.hbm.TbSysExprJob)3 ISysExprJobService (com.netsteadfast.greenstep.service.ISysExprJobService)3 IOException (java.io.IOException)3 ExpressionJobObj (com.netsteadfast.greenstep.model.ExpressionJobObj)2 TbSysExpression (com.netsteadfast.greenstep.po.hbm.TbSysExpression)2 ISysExpressionService (com.netsteadfast.greenstep.service.ISysExpressionService)2 SysExpressionVO (com.netsteadfast.greenstep.vo.SysExpressionVO)2 HashMap (java.util.HashMap)2 TbSysExprJobLog (com.netsteadfast.greenstep.po.hbm.TbSysExprJobLog)1 ISysExprJobLogService (com.netsteadfast.greenstep.service.ISysExprJobLogService)1 ShiroLoginSupport (com.netsteadfast.greenstep.sys.ShiroLoginSupport)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 WebMethod (javax.jws.WebMethod)1