Search in sources :

Example 11 with ConfigurationException

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

the class ProjectManager method getPlanOfProject.

/**
 * @param planId
 * @param projectId
 * @return
 */
public ConfigBean getPlanOfProject(ID planId, ID projectId) {
    if (projectId == null) {
        Object[] o = Application.getQueryFactory().uniqueNoFilter(planId, "projectId");
        projectId = o != null ? (ID) o[0] : null;
    }
    for (ConfigBean e : getPlansOfProject(projectId)) {
        if (e.getID("id").equals(planId))
            return e;
    }
    throw new ConfigurationException(Language.L("无效任务面板 (%s)", planId));
}
Also used : ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 12 with ConfigurationException

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

the class SMSender method sendSMS.

/**
 * @param to
 * @param content
 * @param specAccount
 * @return <tt>null</tt> if failed or SENDID
 * @throws ConfigurationException If sms-account unset
 */
public static String sendSMS(String to, String content, String[] specAccount) throws ConfigurationException {
    if (specAccount == null || specAccount.length < 3 || StringUtils.isBlank(specAccount[0]) || StringUtils.isBlank(specAccount[1]) || StringUtils.isBlank(specAccount[2])) {
        throw new ConfigurationException(Language.L("短信账户未配置或配置错误"));
    }
    Map<String, Object> params = new HashMap<>();
    params.put("appid", specAccount[0]);
    params.put("signature", specAccount[1]);
    params.put("to", to);
    // Auto append the SMS-Sign
    if (!content.startsWith("【")) {
        content = "【" + specAccount[2] + "】" + content;
    }
    params.put("content", content);
    HeavyStopWatcher.createWatcher("Subsms Send", to);
    JSONObject rJson;
    try {
        String r = OkHttpUtils.post("https://api-v4.mysubmail.com/sms/send.json", params);
        rJson = JSON.parseObject(r);
    } catch (Exception ex) {
        log.error("Subsms failed to send : " + to + " > " + content, ex);
        return null;
    } finally {
        HeavyStopWatcher.clean();
    }
    if (STATUS_OK.equalsIgnoreCase(rJson.getString("status"))) {
        String sendId = rJson.getString("send_id");
        createLog(to, content, TYPE_SMS, sendId, null);
        return sendId;
    } else {
        log.error("SMS failed to send : " + to + " > " + content + "\nError : " + rJson);
        createLog(to, content, TYPE_SMS, null, rJson.getString("msg"));
        return null;
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) EmailException(org.apache.commons.mail.EmailException)

Example 13 with ConfigurationException

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

the class ReportTemplateController method preview.

@GetMapping("/report-templates/preview")
public void preview(@IdParam ID reportId, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Object[] report = Application.createQueryNoFilter("select belongEntity from DataReportConfig where configId = ?").setParameter(1, reportId).unique();
    Entity entity = MetadataHelper.getEntity((String) report[0]);
    String sql = String.format("select %s from %s order by modifiedOn desc", entity.getPrimaryField().getName(), entity.getName());
    Object[] random = Application.createQueryNoFilter(sql).unique();
    if (random == null) {
        response.sendError(400, Language.L("未找到可供预览的记录"));
        return;
    }
    File file;
    try {
        File template = DataReportManager.instance.getTemplateFile(entity, reportId);
        file = new EasyExcelGenerator(template, (ID) random[0]).generate();
    } catch (ConfigurationException ex) {
        response.sendError(400, Language.L("未找到可供预览的记录"));
        return;
    }
    FileDownloader.setDownloadHeaders(request, response, file.getName());
    FileDownloader.writeLocalFile(file, response);
}
Also used : Entity(cn.devezhao.persist4j.Entity) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) File(java.io.File) EasyExcelGenerator(com.rebuild.core.service.datareport.EasyExcelGenerator) 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