Exemplo n.º 1
0
 @Override
 public void deleteOnCreator(Integer creator) throws Exception {
   boolean create = true;
   File indexDir = new File(getIndexPath());
   if (!indexDir.exists()) {
     indexDir.mkdirs();
   } else {
     if (indexDir.list().length > 0) {
       create = false;
     }
   }
   Directory dir = FSDirectory.open(indexDir);
   IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_2, analyzer);
   if (create) {
     iwc.setOpenMode(OpenMode.CREATE);
   } else {
     iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
   }
   IndexWriter writer = null;
   try {
     writer = new IndexWriter(dir, iwc);
     writer.deleteDocuments(
         new Term(
             FIELD_LABEL_CREATE_USER,
             StringUtils.zeroPadding(creator, IndexingValue.ID_ZEROPADDING_DIGIT)));
     writer.commit();
   } finally {
     if (writer != null) {
       writer.close();
     }
   }
 }
Exemplo n.º 2
0
  @Post
  @Auth(roles = "admin")
  public Boundary save() throws Exception {
    List<ValidateError> errors = new ArrayList<>();
    errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

    String type = getParam("proxyAuthType");
    // 認証がONの場合のチェック
    if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
      if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
        ValidateError error = new ValidateError("errors.required", getResource("label.auth.id"));
        errors.add(error);
      }
      if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
        ValidateError error =
            new ValidateError("errors.required", getResource("label.auth.password"));
        errors.add(error);
      }
    }
    if (!errors.isEmpty()) {
      setResult(null, errors);
      return forward("config.jsp");
    }

    ProxyConfigsEntity entity = super.getParamOnProperty(ProxyConfigsEntity.class);
    ProxyConfigsDao dao = ProxyConfigsDao.get();

    if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
      // パスワード変更無し
      ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
      entity.setProxyAuthPassword(db.getProxyAuthPassword());
      entity.setProxyAuthSalt(db.getProxyAuthSalt());
    } else {
      // パスワードは暗号化する
      String salt = PasswordUtil.getSalt();
      entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
      entity.setProxyAuthSalt(salt);
    }

    entity = dao.save(entity);

    String successMsg = "message.success.save";
    setResult(successMsg, errors);
    return config();
  }
Exemplo n.º 3
0
  @Post
  @Auth(roles = "admin")
  public Boundary test() throws Exception {
    try {
      ProxyConfigsEntity entity;
      String testUrl = getParam("testUrl");
      Integer testType = getParam("testType", Integer.class);
      if (INT_FLAG.OFF.getValue() == testType.intValue()) {
        entity = new ProxyConfigsEntity();
      } else {
        List<ValidateError> errors = new ArrayList<>();
        errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

        String type = getParam("proxyAuthType");
        // 認証がONの場合のチェック
        if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
          if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.id"));
            errors.add(error);
          }
          if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.password"));
            errors.add(error);
          }
        }
        if (!errors.isEmpty()) {
          setResult(null, errors);
          return forward("config.jsp");
        }

        entity = super.getParamOnProperty(ProxyConfigsEntity.class);
        ProxyConfigsDao dao = ProxyConfigsDao.get();

        if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
          // パスワード変更無し
          ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
          entity.setProxyAuthPassword(db.getProxyAuthPassword());
          entity.setProxyAuthSalt(db.getProxyAuthSalt());
        } else {
          // パスワードは暗号化する
          String salt = PasswordUtil.getSalt();
          entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
          entity.setProxyAuthSalt(salt);
        }
      }

      // 確認用のURLで通信出来るか確認
      CrawlerLogic crawlerLogic = CrawlerLogic.get();
      String content = crawlerLogic.crawle(entity, testUrl);
      setAttribute("content", content);

      addMsgInfo("knowledge.proxy.test.done");

    } catch (Exception e) {
      LOG.warn("knowledge.proxy.test.fail", e);
      addMsgError("knowledge.proxy.test.fail");
      addMsgError(e.getClass().getSimpleName());
      if (StringUtils.isNotEmpty(e.getMessage())) {
        addMsgError(e.getMessage());
      }
    }
    return forward("config.jsp");
  }
Exemplo n.º 4
0
  /**
   * リクエスト情報にあるテンプレートの情報を取得する 同時にバリデーションエラーもチェックし、もしバリデーションエラーが発生する場合、 引数のerrorsのリストに追加していく
   *
   * @param errors
   * @return
   * @throws InvalidParamException
   * @throws IOException
   * @throws JSONException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  private TemplateMastersEntity loadParams(List<ValidateError> errors)
      throws InstantiationException, IllegalAccessException, JSONException, IOException,
          InvalidParamException {
    TemplateMastersEntity template = new TemplateMastersEntity();
    Map<String, String> values = getParams();
    errors.addAll(template.validate(values));
    if (!errors.isEmpty()) {
      return null;
    }
    template = getParamOnProperty(TemplateMastersEntity.class);

    String[] itemTypes = getParam("itemType", String[].class);
    if (itemTypes != null) {
      for (int i = 0; i < itemTypes.length; i++) {
        String itemType = itemTypes[i]; // text_1 や radio_3 といった形式
        if (itemType.indexOf("_") == -1) {
          errors.add(new ValidateError("errors.invalid", "Request Data"));
          return null;
        }
        String type = itemType.split("_")[0];
        String itemId = itemType.split("_")[1];
        if (!itemId.startsWith("item")) {
          errors.add(new ValidateError("errors.invalid", "Request Data"));
          return null;
        }
        String idx = itemId.substring(4);

        if (!StringUtils.isInteger(idx)) {
          errors.add(new ValidateError("errors.invalid", "Request Data"));
          return null;
        }
        int typeNum = TemplateLogic.get().convType(type);
        if (typeNum == -1) {
          errors.add(new ValidateError("errors.invalid", "Request Data"));
          return null;
        }

        String itemTitle = getParam("title_" + itemId);
        String itemDescription = getParam("description_" + itemId);

        TemplateItemsEntity itemsEntity = new TemplateItemsEntity();
        itemsEntity.setTypeId(-1); // バリデーションエラー対策
        itemsEntity.setItemNo(Integer.parseInt(idx));
        itemsEntity.setItemType(typeNum);
        itemsEntity.setItemName(itemTitle);
        itemsEntity.setDescription(itemDescription);

        errors.addAll(itemsEntity.validate());
        if (!errors.isEmpty()) {
          // エラーが発生した時点で抜ける
          return null;
        }
        template.getItems().add(itemsEntity);

        // 選択肢
        if (typeNum == TemplateLogic.ITEM_TYPE_RADIO
            || typeNum == TemplateLogic.ITEM_TYPE_CHECKBOX) {
          String[] choiceLabels = getParam("label_item" + idx, String[].class);
          String[] choiceValues = getParam("value_item" + idx, String[].class);
          if (choiceLabels.length != choiceValues.length) {
            errors.add(new ValidateError("errors.invalid", "Request Data"));
            return null;
          }
          for (int j = 0; j < choiceLabels.length; j++) {
            String label = choiceLabels[j];
            String value = choiceValues[j];
            ItemChoicesEntity choicesEntity = new ItemChoicesEntity();
            choicesEntity.setTypeId(-1);
            choicesEntity.setItemNo(-1);
            choicesEntity.setChoiceLabel(label);
            choicesEntity.setChoiceValue(value);
            errors.addAll(itemsEntity.validate());
            if (!errors.isEmpty()) {
              // エラーが発生した時点で抜ける
              return null;
            }
            itemsEntity.getChoices().add(choicesEntity);
          }
        }
      }
    }
    return template;
  }
Exemplo n.º 5
0
  private void start() throws Exception {
    super.dbInit();
    SystemConfigsEntity entity =
        SystemConfigsDao.get()
            .selectOnKey(SystemConfig.DATA_EXPORT, AppConfig.get().getSystemName());
    if (entity == null) {
      send("[Fail] create fail. please try again.");
      return;
    }
    // エクスポートデータを格納するディレクトリ
    AppConfig config = AppConfig.get();
    File base = new File(config.getTmpPath());
    File dir = new File(base, DATA_DIR);
    if (dir.exists()) {
      FileUtil.delete(dir);
    }
    dir.mkdirs();
    File attach = new File(dir, "attach");
    attach.mkdirs();
    File userdir = new File(dir, "user");
    userdir.mkdirs();

    // ナレッジデータを取得
    LoginedUser loginedUser =
        new LoginedUser() {
          @Override
          public boolean isAdmin() {
            return true;
          }
        };
    KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();
    CommentsDao commentsDao = CommentsDao.get();
    KnowledgeFilesDao knowledgeFilesDao = KnowledgeFilesDao.get();

    List<KnowledgesEntity> knowledges = knowledgeLogic.searchKnowledge("", loginedUser, 0, 100);
    for (KnowledgesEntity knowledgesEntity : knowledges) {
      File f =
          new File(
              dir,
              "knowledge-"
                  + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                  + ".xml");
      String xml = SerializeUtils.objectToXml(knowledgesEntity);
      FileUtil.write(f, xml);

      // ナレッジのコメントを取得
      List<CommentsEntity> comments =
          commentsDao.selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
      for (CommentsEntity commentsEntity : comments) {
        File c =
            new File(
                dir,
                "comment-"
                    + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                    + "-"
                    + StringUtils.zeroPadding(commentsEntity.getKnowledgeId(), 6)
                    + ".xml");
        xml = SerializeUtils.objectToXml(commentsEntity);
        FileUtil.write(c, xml);
      }
      List<KnowledgeFilesEntity> files =
          knowledgeFilesDao.selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
      for (KnowledgeFilesEntity knowledgeFilesEntity : files) {
        KnowledgeFilesEntity file = knowledgeFilesDao.selectOnKey(knowledgeFilesEntity.getFileNo());
        File a =
            new File(
                attach,
                "attach-"
                    + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                    + "-"
                    + StringUtils.zeroPadding(knowledgeFilesEntity.getFileNo(), 6)
                    + knowledgeFilesEntity.getFileName());
        OutputStream outputStream = new FileOutputStream(a);
        InputStream inputStream = file.getFileBinary();
        try {
          FileUtil.copy(inputStream, outputStream);
        } finally {
          inputStream.close();
          outputStream.close();
        }
      }
      send("[Export] knowledge-" + knowledgesEntity.getKnowledgeId());
    }

    // ユーザ情報を取得
    UsersDao usersDao = UsersDao.get();
    List<UsersEntity> users = usersDao.selectAll();
    for (UsersEntity usersEntity : users) {
      ExportUser user = new ExportUser();
      PropertyUtil.copyPropertyValue(usersEntity, user);
      File f = new File(userdir, "user-" + StringUtils.zeroPadding(user.getUserId(), 6) + ".xml");
      String xml = SerializeUtils.objectToXml(user);
      FileUtil.write(f, xml);
      send("[Export] user-" + user.getUserId());
    }

    // zip圧縮
    send("[Export] during the compression");
    String name = DATA_DIR + ".zip";
    File comp = new File(base, name);

    BufferedOutputStream output = null;
    ZipArchiveOutputStream os = null;
    try {
      output = new BufferedOutputStream(new FileOutputStream(comp));
      os = new ZipArchiveOutputStream(output);
      os.setEncoding("UTF-8");
      CompressLogic.get().addZip(os, dir, null);
    } finally {
      if (os != null) {
        os.close();
      }
      if (output != null) {
        output.close();
      }
    }
    send("[Export] complete!");
    // 圧縮の予約を削除
    SystemConfigsDao.get().physicalDelete(entity);
  }