Search in sources :

Example 1 with ConfigurationException

use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.

the class DataReportManager method getTemplateFile.

/**
 * @param entity
 * @param reportId
 * @return
 */
public File getTemplateFile(Entity entity, ID reportId) {
    String template = null;
    for (ConfigBean e : getReportsRaw(entity)) {
        if (e.getID("id").equals(reportId)) {
            template = e.getString("template");
            break;
        }
    }
    if (template == null) {
        throw new ConfigurationException("No template of report found : " + reportId);
    }
    File file = RebuildConfiguration.getFileOfData(template);
    if (!file.exists()) {
        throw new ConfigurationException("File of template not extsts : " + file);
    }
    return file;
}
Also used : ConfigurationException(com.rebuild.core.configuration.ConfigurationException) ConfigBean(com.rebuild.core.configuration.ConfigBean) File(java.io.File)

Example 2 with ConfigurationException

use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.

the class TransformConfigController method pageEditor.

@GetMapping("transform/{id}")
public ModelAndView pageEditor(@PathVariable String id, HttpServletResponse response) throws IOException {
    ModelAndView mv = createModelAndView("/admin/robot/transform-editor");
    ID configId = ID.isId(id) ? ID.valueOf(id) : null;
    if (configId == null) {
        response.sendError(404);
        return null;
    }
    ConfigBean config;
    try {
        config = TransformManager.instance.getTransformConfig(configId, null);
    } catch (ConfigurationException notExists) {
        response.sendError(404);
        return null;
    }
    mv.getModelMap().put("configId", configId);
    mv.getModelMap().put("config", config.getJSON("config"));
    Entity sourceEntity = MetadataHelper.getEntity(config.getString("source"));
    Entity targetEntity = MetadataHelper.getEntity(config.getString("target"));
    // 主实体
    mv.getModelMap().put("sourceEntity", buildEntity(sourceEntity, true));
    mv.getModelMap().put("targetEntity", buildEntity(targetEntity, false));
    // 明细(两个实体均有明细才返回)
    if (sourceEntity.getDetailEntity() != null && targetEntity.getDetailEntity() != null) {
        mv.getModelMap().put("sourceDetailEntity", buildEntity(sourceEntity.getDetailEntity(), true));
        mv.getModelMap().put("targetDetailEntity", buildEntity(targetEntity.getDetailEntity(), false));
    }
    mv.getModelMap().put("name", config.getString("name"));
    return mv;
}
Also used : Entity(cn.devezhao.persist4j.Entity) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) ModelAndView(org.springframework.web.servlet.ModelAndView) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with ConfigurationException

use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.

the class ApprovalProcessor method getWorkedSteps.

/**
 * 获取已执行流程列表
 *
 * @return returns [ [S,S], [S], [SSS], [S] ]
 */
public JSONArray getWorkedSteps() {
    final ApprovalStatus status = ApprovalHelper.getApprovalStatus(this.record);
    this.approval = status.getApprovalId();
    Object[][] array = Application.createQueryNoFilter("select approver,state,remark,approvedTime,createdOn,createdBy,node,prevNode from RobotApprovalStep" + " where recordId = ? and isWaiting = 'F' and isCanceled = 'F' order by createdOn").setParameter(1, this.record).array();
    if (array.length == 0) {
        return JSONUtils.EMPTY_ARRAY;
    }
    Object[] firstStep = null;
    Map<String, List<Object[]>> stepGroupMap = new HashMap<>();
    for (Object[] o : array) {
        String prevNode = (String) o[7];
        if (firstStep == null && FlowNode.NODE_ROOT.equals(prevNode)) {
            firstStep = o;
        }
        List<Object[]> stepGroup = stepGroupMap.computeIfAbsent(prevNode, k -> new ArrayList<>());
        stepGroup.add(o);
    }
    if (firstStep == null) {
        throw new ConfigurationException(Language.L("无效审批记录 (%s)", this.record));
    }
    JSONArray steps = new JSONArray();
    JSONObject submitter = JSONUtils.toJSONObject(new String[] { "submitter", "submitterName", "createdOn", "approvalId", "approvalName", "approvalState" }, new Object[] { firstStep[5], UserHelper.getName((ID) firstStep[5]), CalendarUtils.getUTCDateTimeFormat().format(firstStep[4]), status.getApprovalId(), status.getApprovalName(), status.getCurrentState().getState() });
    steps.add(submitter);
    String next = FlowNode.NODE_ROOT;
    while (next != null) {
        List<Object[]> group = stepGroupMap.get(next);
        if (group == null) {
            break;
        }
        next = (String) group.get(0)[6];
        // 按审批时间排序
        group.sort((o1, o2) -> {
            Date t1 = (Date) (o1[3] == null ? o1[4] : o1[3]);
            Date t2 = (Date) (o2[3] == null ? o2[4] : o2[3]);
            return t1.compareTo(t2);
        });
        String signMode = null;
        try {
            signMode = getFlowParser().getNode(next).getSignMode();
        } catch (ApprovalException | ConfigurationException ignored) {
        }
        JSONArray s = new JSONArray();
        for (Object[] o : group) {
            s.add(formatStep(o, signMode));
        }
        steps.add(s);
    }
    return steps;
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID)

Example 4 with ConfigurationException

use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.

the class SMSender method sendMail.

/**
 * @param to
 * @param subject
 * @param content
 * @param useTemplate
 * @param specAccount
 * @return <tt>null</tt> if failed or SENDID
 * @throws ConfigurationException If mail-account unset
 */
public static String sendMail(String to, String subject, String content, boolean useTemplate, String[] specAccount) throws ConfigurationException {
    if (specAccount == null || specAccount.length < 5 || StringUtils.isBlank(specAccount[0]) || StringUtils.isBlank(specAccount[1]) || StringUtils.isBlank(specAccount[2]) || StringUtils.isBlank(specAccount[3])) {
        throw new ConfigurationException(Language.L("邮件账户未配置或配置错误"));
    }
    // 使用邮件模板
    if (useTemplate) {
        Element mailbody = getMailTemplate();
        Objects.requireNonNull(mailbody.selectFirst(".rb-title")).text(subject);
        Objects.requireNonNull(mailbody.selectFirst(".rb-content")).html(content);
        String htmlContent = mailbody.html();
        // 处理公共变量
        htmlContent = htmlContent.replace("%TO%", to);
        htmlContent = htmlContent.replace("%TIME%", CalendarUtils.getUTCDateTimeFormat().format(CalendarUtils.now()));
        htmlContent = htmlContent.replace("%APPNAME%", RebuildConfiguration.get(ConfigurationItem.AppName));
        String pageFooter = RebuildConfiguration.get(ConfigurationItem.PageFooter);
        if (StringUtils.isNotBlank(pageFooter)) {
            pageFooter = MarkdownUtils.render(pageFooter);
            htmlContent = htmlContent.replace("%PAGE_FOOTER%", pageFooter);
        } else {
            htmlContent = htmlContent.replace("%PAGE_FOOTER%", "");
        }
        content = htmlContent;
    }
    final String logContent = "【" + subject + "】" + content;
    // Use SMTP
    if (specAccount.length >= 6 && StringUtils.isNotBlank(specAccount[5])) {
        try {
            String emailId = sendMailViaSmtp(to, subject, content, specAccount);
            createLog(to, logContent, TYPE_EMAIL, emailId, null);
            return emailId;
        } catch (EmailException ex) {
            log.error("SMTP failed to send : " + to + " > " + subject, ex);
            return null;
        }
    }
    Map<String, Object> params = new HashMap<>();
    params.put("appid", specAccount[0]);
    params.put("signature", specAccount[1]);
    params.put("to", to);
    if (StringUtils.isNotBlank(specAccount[4]))
        params.put("cc", specAccount[4]);
    params.put("from", specAccount[2]);
    params.put("from_name", specAccount[3]);
    params.put("subject", subject);
    if (useTemplate) {
        params.put("html", content);
    } else {
        params.put("text", content);
    }
    params.put("asynchronous", "true");
    params.put("headers", JSONUtils.toJSONObject("X-User-Agent", OkHttpUtils.RB_UA));
    JSONObject rJson;
    try {
        String r = OkHttpUtils.post("https://api-v4.mysubmail.com/mail/send.json", params);
        rJson = JSON.parseObject(r);
    } catch (Exception ex) {
        log.error("Submail failed to send : " + to + " > " + subject, ex);
        return null;
    }
    JSONArray returns = rJson.getJSONArray("return");
    if (STATUS_OK.equalsIgnoreCase(rJson.getString("status")) && !returns.isEmpty()) {
        String sendId = ((JSONObject) returns.get(0)).getString("send_id");
        createLog(to, logContent, TYPE_EMAIL, sendId, null);
        return sendId;
    } else {
        log.error("Mail failed to send : " + to + " > " + subject + "\nError : " + rJson);
        createLog(to, logContent, TYPE_EMAIL, null, rJson.getString("msg"));
        return null;
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) EmailException(org.apache.commons.mail.EmailException) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) EmailException(org.apache.commons.mail.EmailException)

Example 5 with ConfigurationException

use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.

the class ProjectController method getPlans.

@GetMapping("{projectId}/details")
public RespBody getPlans(@PathVariable String projectId, HttpServletRequest request) throws IOException {
    final ID user = getRequestUser(request);
    JSONObject details;
    try {
        ConfigBean p = ProjectManager.instance.getProject(ID.valueOf(projectId), user);
        details = JSONUtils.toJSONObject(new String[] { "projectName", "isMember", "projectStatus" }, new Object[] { p.getString("projectName"), p.get("members", Set.class).contains(user), p.getInteger("status") });
    } catch (ConfigurationException ex) {
        return RespBody.error(ex.getLocalizedMessage(), 403);
    }
    ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(ID.valueOf(projectId));
    JSONArray array = new JSONArray();
    for (ConfigBean cb : plans) {
        array.add(cb.toJSON());
    }
    details.put("projectPlans", array);
    return RespBody.ok(details);
}
Also used : Set(java.util.Set) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ConfigurationException (com.rebuild.core.configuration.ConfigurationException)13 JSONObject (com.alibaba.fastjson.JSONObject)9 ID (cn.devezhao.persist4j.engine.ID)8 JSONArray (com.alibaba.fastjson.JSONArray)5 ConfigBean (com.rebuild.core.configuration.ConfigBean)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Entity (cn.devezhao.persist4j.Entity)4 File (java.io.File)3 EasyExcelGenerator (com.rebuild.core.service.datareport.EasyExcelGenerator)2 HashMap (java.util.HashMap)2 EmailException (org.apache.commons.mail.EmailException)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 AccessDeniedException (cn.devezhao.bizz.security.AccessDeniedException)1 Field (cn.devezhao.persist4j.Field)1 Record (cn.devezhao.persist4j.Record)1 EasyField (com.rebuild.core.metadata.easymeta.EasyField)1 EasyExcelListGenerator (com.rebuild.core.service.datareport.EasyExcelListGenerator)1 Set (java.util.Set)1 Element (org.jsoup.nodes.Element)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1