@Override
  public Navigation run() throws Exception {

    Validators v = new Validators(request);
    v.add("id", v.longType());
    v.add("salary", v.required(), v.integerType());
    if (!v.validate()) {
      System.out.println("validation error: " + errors);
      return null;
    }

    long id = asLong("id");
    int salary = asInteger("salary");

    Key key = Datastore.createKey(Employee.class, id);
    Transaction tx = Datastore.beginTransaction();
    try {
      Employee e = Datastore.get(tx, Employee.class, key);
      e.setSalary(salary);
      Datastore.put(tx, e);
      tx.commit();
    } finally {
      if (tx.isActive()) {
        tx.rollback();
      }
    }

    return forward("updateSalary.jsp");
  }
Esempio n. 2
0
  /*
   * (non-Javadoc) {@inheritDoc}
   */
  @Override
  public Navigation run() throws Exception {
    Validators v = new Validators(request);
    v.add("startWeek", v.required(), v.integerType(), v.longRange(START_WEEK_MIN, START_WEEK_MAX));
    v.add("keyword", v.maxlength(KEYWORD_MAX_LENGTH));
    if (!v.validate()) {
      response.setStatus(UNAUTHORIZED);
      Errors errors = v.getErrors();
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < errors.size(); i++) {
        sb.append(errors.get(i) + "\n");
      }
      response.setContentType("text/plain;charset=UTF-8");
      response.getWriter().write(new String(sb));
    } else {
      response.setContentType("text/calendar;charset=UTF-8");
      response.setHeader("Content-Disposition", "filename=\"" + ICALENDAR_FILE_NAME + "\"");

      Integer startWeekNum = Integer.parseInt(request.getParameter("startWeek"));
      StartWeek startWeek = StartWeek.parse(startWeekNum);
      String keyword = request.getParameter("keyword");
      String memcacheKey = "startWeek=" + startWeekNum;
      if (keyword != null) {
        memcacheKey += "&keyword=" + URLEncoder.encode(keyword, "UTF-8");
      }
      Object cache = Memcache.get(memcacheKey);
      if (cache == null) {
        CalendarCondition condition = new CalendarCondition();
        if (keyword != null) {
          // 半角スペースで区切られているキーワードは分割して配列にする。
          condition.setKeywords(Arrays.asList(keyword.split(" ")));
        }
        condition.setStartDate(startWeek.toDate());

        Calendar calendar = calendarService.getCalendar(condition);
        response.getWriter().write(calendar.toString());

        // MemcacheにiCalendarの内容をキャッシュする。
        Memcache.put(memcacheKey, calendar.toString());
      } else {
        // キャッシュがある場合はキャッシュの内容を返す。
        response.getWriter().write((String) cache);
      }
    }
    response.flushBuffer();

    return null;
  }
Esempio n. 3
0
  @Override
  public Navigation run() throws Exception {
    Validators validators = new Validators(request);
    EventMeta meta = EventMeta.get();

    validators.add("project", validators.required());
    validators.add(meta.presentation, validators.required());

    if (!validators.validate()) {
      return reportValidationErrors(validators.getErrors());
    }

    Map<String, Object> map = new RequestMap(request);
    map.put("project", asKey("project"));

    eventManager.create(map);
    return forward("../admin.jsp");
  }
Esempio n. 4
0
 /**
  * validate設定.
  *
  * @return validate
  */
 protected Validators validate() {
   Validators v = new Validators(request);
   v.add("dummy", v.required(), v.integerType());
   v.add("arg2", v.integerType(), v.longRange(3, 5));
   return v;
 }
Esempio n. 5
0
 /**
  * 画面入力チェックを行ないます。
  *
  * @return チェック結果
  */
 protected boolean validate() {
   Validators v = new Validators(request);
   v.add(meta.id, v.required());
   return v.validate();
 }