Beispiel #1
0
  /**
   * 更新
   *
   * @return
   * @throws InvalidParamException
   * @throws IOException
   * @throws JSONException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  @Post
  @Auth(roles = "admin")
  public Boundary update()
      throws InstantiationException, IllegalAccessException, JSONException, IOException,
          InvalidParamException {
    List<ValidateError> errors = new ArrayList<ValidateError>();
    TemplateMastersEntity template = loadParams(errors);
    if (!errors.isEmpty()) {
      return sendValidateError(errors);
    }

    // 保存
    try {
      template = TemplateLogic.get().updateTemplate(template, getLoginedUser());
    } catch (InvalidParamException e) {
      // エラーメッセージ送信
      return send(e.getMessageResult());
    }
    // メッセージ送信
    return sendMsg(
        MessageStatus.Success,
        HttpStatus.SC_OK,
        String.valueOf(template.getTypeId()),
        "message.success.update");
  }
  @Override
  public boolean doMigrate() throws Exception {
    InitializeDao initializeDao = InitializeDao.get();
    String[] sqlpaths = {"/org/support/project/knowledge/deploy/v0_6_0pre4/migrate.sql"};
    initializeDao.initializeDatabase(sqlpaths);

    TemplateMastersEntity template = new TemplateMastersEntity();
    template.setTypeName("Weekly Report");
    template.setTypeIcon("fa-file-text-o");
    template.setDescription("プロジェクト毎の週報です");

    List<TemplateItemsEntity> items = new ArrayList<TemplateItemsEntity>();
    TemplateItemsEntity status = new TemplateItemsEntity();
    status.setItemName("Status");
    status.setItemType(TemplateLogic.ITEM_TYPE_RADIO);
    status.setDescription("状態");
    items.add(status);

    List<ItemChoicesEntity> choices = new ArrayList<>();
    ItemChoicesEntity status_good = new ItemChoicesEntity();
    status_good.setChoiceLabel("Good");
    status_good.setChoiceValue("1");
    choices.add(status_good);

    ItemChoicesEntity status_normal = new ItemChoicesEntity();
    status_normal.setChoiceLabel("Normal");
    status_normal.setChoiceValue("0");
    choices.add(status_normal);

    ItemChoicesEntity status_bad = new ItemChoicesEntity();
    status_bad.setChoiceLabel("Bad");
    status_bad.setChoiceValue("-1");
    choices.add(status_bad);

    status.setChoices(choices);

    TemplateItemsEntity problem = new TemplateItemsEntity();
    problem.setItemName("Problem");
    problem.setItemType(TemplateLogic.ITEM_TYPE_TEXT);
    problem.setDescription("問題点");
    items.add(problem);

    template.setItems(items);

    TemplateLogic.get().addTemplate(template, new LoginedUser());

    return true;
  }
Beispiel #3
0
  /**
   * 更新画面を表示する
   *
   * @return
   * @throws InvalidParamException
   */
  @Get
  @Auth(roles = "admin")
  public Boundary view_edit() throws InvalidParamException {
    Integer id = super.getPathInteger();
    TemplateMastersEntity entity = TemplateLogic.get().loadTemplate(id);
    if (entity == null) {
      sendError(404, null);
    }
    setAttributeOnProperty(entity);
    setAttribute("items", entity.getItems());

    boolean editable = true;
    if (KnowledgeLogic.TEMPLATE_TYPE_KNOWLEDGE == id
        || KnowledgeLogic.TEMPLATE_TYPE_BOOKMARK == id) {
      editable = false;
    }
    setAttribute("editable", editable);
    return forward("view_edit.jsp");
  }
Beispiel #4
0
  /**
   * 登録 画面遷移すると再度画面を作るのが面倒なので、Ajaxアクセスとする
   *
   * @return
   * @throws InvalidParamException
   * @throws IOException
   * @throws JSONException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  @Post
  @Auth(roles = "admin")
  public Boundary create()
      throws InstantiationException, IllegalAccessException, JSONException, IOException,
          InvalidParamException {
    List<ValidateError> errors = new ArrayList<ValidateError>();
    TemplateMastersEntity template = loadParams(errors);
    if (!errors.isEmpty()) {
      return sendValidateError(errors);
    }
    template.setTypeId(null); // 自動採番する
    // 保存
    template = TemplateLogic.get().addTemplate(template, getLoginedUser());

    // メッセージ送信
    return sendMsg(
        MessageStatus.Success,
        HttpStatus.SC_OK,
        String.valueOf(template.getTypeId()),
        "message.success.insert");
  }
Beispiel #5
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;
  }