@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");
  }
示例#2
0
  public static void putDisplayName(String displayName) throws JEDuplicateException {
    final String UNIQUE_KEY_DISPLAY_NAME = "UniqueKeyDisplayName";
    final User user = getUser();
    final Key key = Datastore.createKey(JEUser.class, user.getEmail());
    if (Datastore.putUniqueValue(UNIQUE_KEY_DISPLAY_NAME, displayName) == false) {
      throw new JEDuplicateException("the display name is already used");
    }
    Transaction tx = Datastore.beginTransaction();
    try {
      JEUser jeUser = Datastore.getOrNull(tx, JEUser.class, key);
      final long now = new Date().getTime();
      if (jeUser == null) {
        jeUser = new JEUser();
        jeUser.setKey(key);
        jeUser.setCreatedAt(now);
      }
      jeUser.setDisplayName(displayName);
      jeUser.setUpdatedAt(now);
      Datastore.put(tx, jeUser);

      // TODO: Run TQ to update past's memos.

      Datastore.commit(tx);

    } catch (Exception e) {
      Datastore.rollback(tx);
      Datastore.deleteUniqueValue(UNIQUE_KEY_DISPLAY_NAME, displayName);
    }
  }
示例#3
0
 /**
  * スコアの登録.
  *
  * @param input スコア情報
  */
 public void register(Map<String, Object> input) {
   Score score = new Score();
   BeanUtil.copy(input, score);
   Transaction tx = Datastore.beginTransaction();
   Datastore.put(score);
   tx.commit();
 }
  @Override
  public void setUp() throws Exception {
    super.setUp();
    account = new Account();
    account.setKey(Datastore.createKey(Account.class, 1));
    Datastore.put(account);

    discussions = new ArrayList<Submission>();
    for (int i = 0; i < 10; i++) {
      Submission submission = new Submission();
      submission.setTitle("title" + i);
      submission.setDescription("description" + i);
      submission.setAuthor(Datastore.createKey(Account.class, i + 1));
      submission.setAuthorName("author" + i);
      discussions.add(submission);
    }
    Datastore.put(discussions);
  }
 @PUT
 @Path("{id}")
 @Consumes({MediaType.APPLICATION_JSON})
 public void update(@PathParam("id") Long id, Shop shop) {
   log.info("put:" + id + " " + shop.getName());
   Key key = Datastore.createKey(ShopModel.class, id);
   ShopModel shopModel = Datastore.get(ShopModel.class, key);
   shopModel.setName(shop.getName());
   Datastore.put(shopModel);
 }
 @POST
 @Consumes({MediaType.APPLICATION_JSON})
 public Shop createShop(Shop shop) {
   log.info("post:" + shop.getName());
   ShopModel shopModel = new ShopModel();
   shopModel.setConversionRatio(shop.getConversionRatio());
   shopModel.setName(shop.getName());
   Datastore.put(shopModel);
   return shop;
 }
  @Override
  public Navigation run() throws Exception {

    Employee employee = new Employee();
    employee.setKey(Datastore.createKey(Employee.class, 9999));
    employee.setName("ŽÐ’{Žl˜Y");
    employee.setDeptId(1L);
    Key key = Datastore.put(employee);
    requestScope("key", key);

    return forward("create2.jsp");
  }
 /**
  * Adds an Event todo in the Datastore
  *
  * @param et the event todo added
  * @return whether transaction is successful
  */
 public boolean addEventTodo(EventTodoModel et) {
   boolean ok = false;
   if (getEventTodoModelByTodoId(et.getEventID(), et.getTodoId()) == null) {
     Key key = Datastore.allocateId(parentKey, "EventTodoModel");
     Transaction trans = Datastore.beginTransaction();
     et.setKey(key);
     et.setId(key.getId());
     Datastore.put(et);
     trans.commit();
     ok = true;
   }
   return ok;
 }
  @Override
  protected Map<String, Object> handle() throws Exception {
    Map<String, Object> result = new HashMap<String, Object>();
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String category = request.getParameter("category");

    Joshi joshi = service.findJoshi(id);
    if (joshi != null) {
      Transaction tx = Datastore.beginTransaction();
      if (!Utils.isNull(name)) {
        joshi.setName(name);
      }
      if (!Utils.isNull(category)) {
        joshi.setCategory(category);
      }
      Datastore.put(joshi);
      tx.commit();
    } else {
      Transaction tx = Datastore.beginTransaction();
      joshi = new Joshi();
      Key key = Datastore.createKey(Joshi.class, id);
      joshi.setKey(key);
      joshi.setKawaii(0);
      if (!Utils.isNull(name)) {
        joshi.setName(name);
      }
      if (!Utils.isNull(category)) {
        joshi.setCategory(category);
      }
      Datastore.put(joshi);
      tx.commit();
    }

    result.put("result", "true");
    return result;
  }
示例#10
0
 /*
  * (non-Javadoc)
  *
  * @see yanitime4u.yanitime.logic.UserLogic#create(yanitime4u.yanitime.model.Users)
  */
 @Override
 public Users create(Users users) {
   AssertionUtil.assertNotNull(users);
   Transaction tx = Datastore.beginTransaction();
   try {
     Users register = new Users();
     BeanUtil.copy(users, register);
     Datastore.put(register);
     tx.commit();
     return register;
   } catch (ConcurrentModificationException e) {
     if (tx.isActive()) {
       tx.rollback();
     }
     throw e;
   }
 }
示例#11
0
  /*
   * (non-Javadoc)
   *
   * @see yanitime4u.yanitime.logic.UserLogic#update(com.google.appengine.api.datastore.Key,
   * java.lang.Long, java.util.Map)
   */
  @Override
  public Users update(Key key, Long version, Map<String, Object> input) {
    AssertionUtil.assertNotNull(key);
    AssertionUtil.assertNotNull(version);
    AssertionUtil.assertNotNull(input);

    Transaction tx = Datastore.beginTransaction();
    try {
      Users latest = Datastore.get(meta, key, version);
      BeanUtil.copy(input, latest);
      Datastore.put(tx, latest);
      tx.commit();
      return latest;
    } catch (ConcurrentModificationException e) {
      if (tx.isActive()) {
        tx.rollback();
      }
      throw e;
    }
  }
  /**
   * Updates an Event todo in the Datastore
   *
   * @param et the Event todo to be updated
   * @return whether the transaction is successful
   */
  public boolean updateEventTodo(EventTodoModel et) {
    boolean ok = true;

    try {
      EventTodoModel etm = getEventTodoModelById(et.getId());

      if (etm != null) {
        Transaction trans = Datastore.beginTransaction();
        etm.setEventTitle(et.getEventTitle());
        etm.setTodoDescription(et.getTodoDescription());
        etm.setTodoFinished_quantity(et.getTodoFinished_quantity());
        etm.setTodoTitle(et.getTodoTitle());
        Datastore.put(etm);
        trans.commit();
      }
    } catch (Exception e) {
      ok = false;
    }
    return ok;
  }
  @Override
  public Navigation run() throws Exception {
    // 24時間前以降に更新されているスキルを取得する
    Date h24ago = new Date(new Date().getTime() - day);
    List<SkillAssertion> assertions =
        Datastore.query(m).filter(m.updatedAt.greaterThanOrEqual(h24ago)).asList();

    // ユーザーごとに集計
    HashMap<Profile, List<SkillAssertion>> notifMap = new HashMap<Profile, List<SkillAssertion>>();
    for (SkillAssertion assertion : assertions) {
      SkillA skill = assertion.getSkill().getModel();
      if (!notifMap.containsKey(skill.getHolder().getModel().getUserEmail())) {
        List<SkillAssertion> list = new ArrayList<SkillAssertion>();
        list.add(assertion);
        notifMap.put(skill.getHolder().getModel(), list);
      } else {
        List<SkillAssertion> list = notifMap.get(skill.getHolder().getModel());
        list.add(assertion);
      }
    }

    // キューを作成
    List<MailQueue> queues = new ArrayList<MailQueue>();
    for (Profile profile : notifMap.keySet()) {
      if (profile.getAllowFromMailNotifier() == null
          || profile.getAllowFromMailNotifier() == false) {
        continue;
      }
      StringBuilder body = new StringBuilder();
      body.append(String.format("%s(%s)さんの今日のスキルレポートです。\n\n", profile.getName(), profile.getId()));
      List<SkillAssertion> updatedSkills = notifMap.get(profile);
      for (SkillAssertion assertion : updatedSkills) {
        SkillA skill = assertion.getSkill().getModel();
        body.append(
            String.format(
                "■ %s (%dポイント) <- %s (%s)\n",
                skill.getName(), skill.getPoint(), assertion.getUrl(), assertion.getDescription()));
        body.append(String.format("%d人がやるね!と言っています.\n", assertion.getAgrees().size()));
        List<Profile> agrees = Datastore.get(pm, assertion.getAgrees());
        for (Profile p : agrees) {
          body.append(String.format("- %s(%s) \n", p.getName(), p.getId()));
        }
        body.append("\n\n");
      }
      body.append("\n");
      body.append(
          String.format("http://skillmaps.appspot.com/index.html#!user:%s", profile.getId()));
      body.append("\n\n");
      body.append("--\n");
      body.append("skillmaps\n");
      body.append("http://skillmaps.appspot.com/\n\n");
      body.append("--\n");
      body.append("お知らせを止めたい場合はこちらからお願いします\n");
      body.append("http://skillmaps.appspot.com/#!myPage:\n\n");
      body.append("--\n");
      body.append(
          "何かありましたら[email protected]もしくはhttp://twitter.com/yusuke_kokubo/ までお知らせください\n");

      MailQueue q = new MailQueue();
      q.setSubject(
          String.format("[skillmaps]%s(%s)さんのスキルレポート", profile.getName(), profile.getId()));
      q.setTextBody(body.toString());
      q.setTo(profile.getUserEmail());
      q.setSender("*****@*****.**");
      q.setBcc("*****@*****.**");
      queues.add(q);
    }
    Datastore.put(queues);
    QueueFactory.getDefaultQueue().add(Builder.withUrl("/sys/mailSend"));

    return null;
  }
示例#14
0
  @Before
  public void CreateDate() {

    Member m = null;
    Practice p = null;
    Attendance a = null;

    m = new Member();
    m.setId("test1");
    m.setFirstName("taro");
    m.setLastName("test");
    m.setBirthDay(DateUtil.toDate("2010-10-01", DateUtil.ISO_DATE_PATTERN));
    m.setMailAddress("*****@*****.**");
    m.setTelNo("0120-333-906");
    Datastore.put(m);

    m = new Member();
    m.setId("test2");
    m.setFirstName("ziro");
    m.setLastName("test");
    Datastore.put(m);

    m = new Member();
    m.setId("test3");
    m.setFirstName("savuroh");
    m.setLastName("test");
    Datastore.put(m);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-10-01T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-10-01T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setPracticePlace("test praza");
    p.setGatheringPoint("front of test praza");
    p.setRecital("It's recital.");
    practiceSvc.regist(p);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-10-11T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-10-11T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-10-11T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    practiceSvc.regist(p);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-12-01T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-12-01T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    practiceSvc.regist(p);

    a = new Attendance();
    a.setAttendance(1);
    a.setFinished(false);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    a.getMemberRef().setModel(m);
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.getPracticeRef().setModel(p);
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(1);
    a.setFinished(false);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test2");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test2");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-11T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);
  }