public static boolean flushCleanup(Bucket bucket, long start) {
    for (long i = 0; i <= 999999999; i++) {
      String id = new String("__flush_marker_" + i);
      JsonObject content = JsonObject.empty().put("data", "temp");
      JsonDocument doc = JsonDocument.create(id, content);
      bucket.upsert(doc);

      bucket.remove(id);
    }

    return true;
  }
  @Test
  public void testConstructorWithPreExistingDocument() {
    JsonDocument preExisting =
        JsonDocument.create(uuid, JsonObject.create().put("test", 123).put("foo", "bar"));
    bucket.upsert(preExisting);

    Map<String, Object> map = new CouchbaseMap<Object>(uuid, bucket);

    assertEquals(2, map.size());
    assertTrue(map.containsKey("foo"));
    assertTrue(map.containsValue(123));
  }
Esempio n. 3
0
  /** 裁判文书 抓取word,HTML修改court桶 */
  public static boolean updateJsonData(
      List<ArchivesVO> list, Bucket bucket, AdministrationUtils util) throws Exception {
    if (null == list || list.size() <= 0) {
      return false;
    }
    //		util.initData(); // 查询行政区
    String[] array = null;
    JsonDocument doc = null;
    JsonObject obj2 = null;
    com.google.gson.JsonObject json = null;
    Gson gson = new Gson();
    ArchivesVO archs = null;
    try {
      for (ArchivesVO arch : list) {
        SUM++;
        // 查询数据
        doc = JsonDocument.create(arch.getUuid()); // 获取ID
        obj2 = bucket.get(doc) == null ? null : bucket.get(doc).content();
        if (obj2 == null) {
          logger.info("匹配不到UUID:" + arch.getUuid());
          continue;
        }
        archs = new ArchivesVO();
        json = gson.fromJson(obj2.toString(), com.google.gson.JsonObject.class);
        archs = gson.fromJson(json, ArchivesVO.class);

        if (null != arch.getTitle() && !"".equals(arch.getTitle())) {
          archs.setTitle(arch.getTitle());
        }
        if (null != obj2.get("title") && !"".equals(obj2.get("title"))) {
          archs.setTitle(obj2.get("title").toString()); // 标题
        }
        if (null != arch.getCaseNum() && !"".equals(arch.getCaseNum())) {
          archs.setCaseNum(arch.getCaseNum());
        }
        if (null != obj2.get("caseNum") && !"".equals(obj2.get("caseNum"))) {
          archs.setCaseNum(obj2.get("caseNum").toString()); // 案号
        }
        if (null != arch.getCourtName() && !"".equals(arch.getCourtName())) {
          archs.setCourtName(arch.getCourtName());
        }
        if (null != obj2.get("courtName") && !"".equals(obj2.get("courtName"))) {
          archs.setCourtName(obj2.get("courtName").toString()); // 法院名
        }
        if (null != arch.getCatalog() && !"".equals(arch.getCatalog())) {
          archs.setCatalog(arch.getCatalog());
        }
        if (null != obj2.get("catalog") && !"".equals(obj2.get("catalog"))) {
          archs.setCatalog(obj2.get("catalog").toString()); // 分类
        }
        if (null != arch.getApproval() && !"".equals(arch.getApproval())) {
          archs.setApproval(arch.getApproval());
        }
        if (null != obj2.get("approval") && !"".equals(obj2.get("approval"))) {
          archs.setApproval(obj2.get("approval").toString()); // 审批结果
        }
        if (null != arch.getCaseCause() && !"".equals(arch.getCaseCause())) {
          archs.setCaseCause(arch.getCaseCause());
        }
        if (null != obj2.get("caseCause") && !"".equals(obj2.get("caseCause"))) {
          archs.setCaseCause(obj2.get("caseCause").toString()); // 案由
        }
        if (null != arch.getPlaintiff() && !"".equals(arch.getPlaintiff())) {
          archs.setPlaintiff(arch.getPlaintiff());
        }
        if (null != obj2.get("plaintiff") && !"".equals(obj2.get("plaintiff"))) {
          archs.setPlaintiff(obj2.get("plaintiff").toString()); // 原告
        }

        if (null != arch.getDefendant() && !"".equals(arch.getDefendant())) {
          archs.setDefendant(arch.getDefendant());
        }
        if (null != obj2.get("defendant") && !"".equals(obj2.get("defendant"))) {
          archs.setDefendant(obj2.get("defendant").toString()); // 被告
        }

        if (null != arch.getApprovalDate() && !"".equals(arch.getApprovalDate())) {
          archs.setApprovalDate(arch.getApprovalDate());
        }
        if (null != obj2.get("approvalDate") && !"".equals(obj2.get("approvalDate"))) {
          archs.setApprovalDate(obj2.get("approvalDate").toString()); // 审结日期
        }

        if (null != arch.getSummary() && !"".equals(arch.getSummary())) {
          archs.setSummary(arch.getSummary());
        }
        if (null != obj2.get("summary") && !"".equals(obj2.get("summary"))) {
          archs.setSummary(obj2.get("summary").toString()); // 摘要
        }

        if (null != obj2.get("detailLink") && !"".equals(obj2.get("detailLink"))) {
          archs.setDetailLink(obj2.get("detailLink").toString()); // url
        }

        if (null != obj2.get("publishDate") && !"".equals(obj2.get("publishDate"))) {
          archs.setPublishDate(getReplaceAllDate(obj2.get("publishDate").toString())); // 发布日期
        }

        if (null != obj2.get("province") && !"".equals(obj2.get("province"))) {
          archs.setProvince(obj2.get("province").toString()); // 省
        }
        if (null != obj2.get("city") && !"".equals(obj2.get("city"))) {
          archs.setCity(obj2.get("city").toString()); // 市
        }
        if (null != obj2.get("area") && !"".equals(obj2.get("area"))) {
          archs.setArea(obj2.get("area").toString()); // 县
        }
        if (null != archs.getCourtName() && !"".equals(archs.getCourtName())) {
          array = util.utils(arch.getCourtName());
        }
        if (null != obj2.get("courtName") && !"".equals(obj2.get("courtName"))) {
          array = util.utils(obj2.get("courtName").toString());
        }
        if (null != array) {
          if (null != array[0] && !"".equals(array[0])) {
            archs.setProvince(array[0]);
          }
          if (null != array[1] && !"".equals(array[1])) {
            archs.setCity(array[1]);
          }
          if (null != array[2] && !"".equals(array[2])) {
            archs.setArea(array[2]);
          }
        }

        if (null != obj2.get("collectDate") && !"".equals(obj2.get("collectDate"))) {
          archs.setCollectDate(getReplaceAllDate(obj2.get("collectDate").toString())); // 采集时间
        }
        if (null != obj2.get("suitDate") && !"".equals(obj2.get("suitDate"))) {
          archs.setSuitDate(obj2.get("suitDate").toString()); // 起诉日期
        }
        String jsonss = gson.toJson(archs);
        doc = JsonDocument.create(arch.getUuid(), JsonObject.fromJson(jsonss));
        logger.info("更新条数:" + SUM + "---省:" + array[0] + "---市:" + array[1] + "---县/区:" + array[2]);
        bucket.upsert(doc);
      }
    } catch (Exception e) {
      logger.error(e.getMessage());
      return false;
    } finally {
      array = null;
      gson = null;
      json = null;
      archs = null;
      obj2 = null;
      doc = null;
    }
    return true;
  }