示例#1
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");
  }
示例#2
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;
  }