Example #1
0
  @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;
  }
Example #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;
  }