Search in sources :

Example 66 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class BriefingCreatorImpl method createAttachment.

/**
 * 创建附件
 *
 * @param json
 * @param fileType
 * @return
 * @throws Exception
 */
private String createAttachment(JSONObject json, String fileType) throws Exception {
    String title = json.getString("title");
    String issue = json.getString("issue");
    String filename = title + issue + System.currentTimeMillis() + "." + fileType;
    File file = new File(filepath, filename);
    Map<String, Object> dataMap = new HashMap<String, Object>();
    String outLine = json.getString("outline");
    if (!StringUtils.isEmpty(outLine)) {
        // 过滤html标签,只保留文本
        outLine = Jsoup.clean(outLine, Whitelist.none());
        json.put("outline", outLine);
    }
    dataMap.put("briefing", json);
    FreemarkerUtil.processTemplateIntoFile(dataMap, file, "briefing_" + fileType + ".ftl");
    return filename.replace(filepath, "");
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) JSONObject(net.sf.json.JSONObject) File(java.io.File)

Example 67 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class BriefingCreatorImpl method saveBriefingToMongo.

/**
 * 报存专报到mongodb
 *
 * @param briefing
 * @return
 */
public Boolean saveBriefingToMongo(JSONObject briefing) {
    try {
        DBObject dbObject = (DBObject) JSON.parse(briefing.toString());
        Date endDate = new Date();
        if (briefing.get("dateCreated") != null) {
            endDate.setTime((Long) briefing.get("dateCreated"));
        }
        dbObject.put("dateCreated", endDate);
        dbObject.put("dateModified", endDate);
        Long userId = briefing.getLong("userId");
        User currentUser = userManager.findById(userId);
        dbObject.put("author", currentUser.getFullName() == null ? currentUser.getUsername() : currentUser.getFullName());
        JSONObject json = JSONObject.fromObject(dbObject);
        String attachment_doc = null;
        attachment_doc = createAttachment(json, "doc");
        String attachment_html = createAttachment(json, "html");
        if (attachment_doc != null && attachment_html != null) {
            dbObject.put("attachment", new String[] { attachment_doc, attachment_html });
        }
        MongoDBUtil.insertDocument(Constants.Mongo.COLLECTION_BRIEFING, dbObject);
    } catch (Exception e) {
        e.printStackTrace();
        String message = "生成报告失败";
        LogUtil.logger.error(message);
        return false;
    }
    String message = "生成报告成功@";
    LogUtil.logger.info(message);
    return true;
}
Also used : User(com.topcom.cms.domain.User) JSONObject(net.sf.json.JSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BusinessException(com.topcom.cms.exception.BusinessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 68 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class BriefingCreatorImpl method createSpecial.

@Override
public Future createSpecial(CustomSubject customSubject) throws ExecutionException, InterruptedException {
    FutureTask<Boolean> task = new FutureTask<>(() -> {
        LogUtil.logger.info("----------------专报分析开始:" + customSubject.getId() + "---------------------");
        String id = customSubject.getId().toString();
        String mustWord = customSubject.getMustWord();
        String shouldWord = customSubject.getShouldWord();
        String mustNotWord = customSubject.getMustNotWord();
        Long startTime = customSubject.getStartDate().getTime();
        Long endTime = customSubject.getEndDate().getTime();
        String subjectName = customSubject.getName();
        String briefingString = requestBriefingString(Briefing.BriefingType.SPECIAL, mustWord, shouldWord, mustNotWord, startTime, endTime, subjectName);
        JSONObject jsonObject = JSONObject.fromObject(briefingString);
        jsonObject.put("subjectId", Long.valueOf(id));
        jsonObject.put("userId", customSubject.getUserId());
        boolean status = saveBriefingToMongo(jsonObject);
        // 更新状态
        subjectManager.updateState(customSubject.getId(), CustomSubject.State.COMPLETED);
        LogUtil.logger.info("----------------专报分析完成:" + customSubject.getId() + "---------------------");
        return status;
    });
    executorService.submit(task);
    return task;
}
Also used : JSONObject(net.sf.json.JSONObject)

Example 69 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class DataXUtil method main.

public static void main(String[] args) throws Exception {
    Map map = new HashMap();
    Map json = new HashMap();
    json.put("a", "123");
    json.put("b", "1234");
    JSONObject jsonObject = JSONObject.fromObject(json);
    DataXUtil.runJob(jsonObject, json);
}
Also used : JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class ESEntityHandleThread method saveJson.

private void saveJson(String yuqing, String article, List<JSONObject> jsonObjects) {
    Client client = elasticsearchTemplate.getClient();
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (int i = 0; i < jsonObjects.size(); i++) {
        JSONObject jsonObject = jsonObjects.get(i);
        IndexRequestBuilder indexRequestBuilder = client.prepareIndex(yuqing, article).setSource(jsonObject.toString()).setId(jsonObject.get("id").toString());
        bulkRequestBuilder.add(indexRequestBuilder);
    }
    bulkRequestBuilder.execute().actionGet();
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) JSONObject(net.sf.json.JSONObject) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) Client(org.elasticsearch.client.Client)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11