/**
   * @BeforeClass
   *
   * @throws Exception
   */
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    TestCommon.setUpBeforeClass();
    DBUserPool.get().setUser(loginedUser.getUserId());

    LOG.info("テストユーザ1でKnowledge登録");
    KnowledgesEntity knowledge = new KnowledgesEntity();
    knowledge.setTitle("テスト1");
    knowledge.setContent("テスト");
    knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PUBLIC); // 公開
    knowledge1 = KnowledgeLogic.get().insert(knowledge, null, null, null, null, null, loginedUser);

    LOG.info("テストユーザ1でKnowledge登録");
    knowledge = new KnowledgesEntity();
    knowledge.setTitle("テスト2");
    knowledge.setContent("テスト2");
    knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PRIVATE); // 非公開
    knowledge2 = KnowledgeLogic.get().insert(knowledge, null, null, null, null, null, loginedUser);

    LOG.info("テストユーザ1でKnowledge登録");
    knowledge = new KnowledgesEntity();
    knowledge.setTitle("テスト3");
    knowledge.setContent("テスト3");
    knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PROTECT); // 非公開
    List<LabelValue> targets = new ArrayList<>();
    LabelValue labelValue = new LabelValue();
    labelValue.setLabel(TargetLogic.ID_PREFIX_USER + loginedUser2.getUserId());
    labelValue.setValue(TargetLogic.ID_PREFIX_USER + loginedUser2.getUserId());
    targets.add(labelValue);
    knowledge3 =
        KnowledgeLogic.get().insert(knowledge, null, null, targets, null, null, loginedUser);

    LOG.info("テストユーザ1でKnowledge登録");
    knowledge = new KnowledgesEntity();
    knowledge.setTitle("テスト4");
    knowledge.setContent("テスト4");
    knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PROTECT); // 非公開
    targets = new ArrayList<>();
    labelValue = new LabelValue();
    labelValue.setLabel(TargetLogic.ID_PREFIX_GROUP + group.getGroupId());
    labelValue.setValue(TargetLogic.ID_PREFIX_GROUP + group.getGroupId());
    targets.add(labelValue);
    knowledge4 =
        KnowledgeLogic.get().insert(knowledge, null, null, targets, null, null, loginedUser);
  }
Exemple #2
0
  private void addDoc(IndexWriter writer, IndexingValue indexingValue) throws Exception {
    Document doc = new Document();
    // type
    Field typeField = new IntField(FIELD_LABEL_TYPE, indexingValue.getType(), Field.Store.YES);
    doc.add(typeField);
    // id
    Field idField = new StringField(FIELD_LABEL_ID, indexingValue.getId(), Field.Store.YES);
    doc.add(idField);
    // タイトル
    doc.add(new TextField(FIELD_LABEL_TITLE, indexingValue.getTitle(), Field.Store.YES));
    // 内容
    doc.add(new TextField(FIELD_LABEL_CONTENTS, indexingValue.getContents(), Field.Store.YES));

    // タグ
    Field tagField = new TextField(FIELD_LABEL_TAGS, indexingValue.getTags(), Field.Store.YES);
    doc.add(tagField);
    // アクセスできるユーザ
    Field userField =
        new TextField(FIELD_LABEL_USERS, indexingValue.getUsers().toString(), Field.Store.YES);
    doc.add(userField);
    // アクセスできるグループ
    Field groupField =
        new TextField(FIELD_LABEL_GROUPS, indexingValue.getGroups().toString(), Field.Store.YES);
    doc.add(groupField);

    // 登録者
    Field creatorField =
        new StringField(FIELD_LABEL_CREATE_USER, indexingValue.getCreator(), Field.Store.YES);
    doc.add(creatorField);

    // 時刻
    Field timeField = new LongField(FIELD_LABEL_TIME, indexingValue.getTime(), Field.Store.YES);
    doc.add(timeField);

    if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {
      log.debug("adding " + indexingValue.getId());
      writer.addDocument(doc);
    } else {
      log.debug("updating " + indexingValue.getId());
      writer.updateDocument(new Term(FIELD_LABEL_ID, indexingValue.getId()), doc);
    }
  }
Exemple #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");
  }
Exemple #4
0
 private String getIndexPath() {
   AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
   log.debug("lucene index: " + appConfig.getIndexPath());
   return appConfig.getIndexPath();
 }