@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");
  }
 @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);
 }
 @GET
 @Path("{id}")
 @Produces("application/x-javascript")
 public JSONWithPadding get(
     @PathParam("id") Long id, @QueryParam("jsoncallback") @DefaultValue("fn") String callback) {
   log.info("get:" + id);
   Key key = Datastore.createKey(ShopModel.class, id);
   ShopModel shopModel = Datastore.get(ShopModel.class, key);
   Shop shop = new Shop(shopModel);
   return new JSONWithPadding(shop, callback);
 }
Beispiel #4
0
  /*
   * (non-Javadoc)
   *
   * @see yanitime4u.yanitime.logic.UserLogic#delete(com.google.appengine.api.datastore.Key,
   * java.lang.Long)
   */
  @Override
  public void delete(Key key, Long version) {
    AssertionUtil.assertNotNull(key);
    AssertionUtil.assertNotNull(version);

    Transaction tx = Datastore.beginTransaction();
    try {
      Users latest = Datastore.get(meta, key, version);
      Datastore.delete(latest.getKey());
      tx.commit();
    } catch (ConcurrentModificationException e) {
      if (tx.isActive()) {
        tx.rollback();
      }
      throw e;
    }
  }
Beispiel #5
0
  public static List<Note> findNotes(String[] keys) {
    NoteMeta n = new NoteMeta();
    List<Note> notes = new ArrayList<Note>(keys.length);
    List<Key> keyList = new ArrayList<Key>(keys.length);
    for (String key : keys) {
      Key mkey = KeyFactory.stringToKey(key);
      keyList.add(mkey);
    }

    try {
      notes = Datastore.get(n, keyList);
    } catch (EntityNotFoundRuntimeException e) {
      log.warning("some entity is not found in findNotes. index is broken?");
      return null;
    }
    return notes;
  }
Beispiel #6
0
  public Object[] getIndexes(UserInfo user) {
    Map<Object, Object> map = Memcache.getAll(user.getIndexes());

    if (map.size() < user.getIndexes().size()) {
      // some indexes are out of Memcache.
      List<Index> idxList = Datastore.get(i, user.getIndexes());

      for (Index idx : idxList) {
        if (!map.containsValue(idx)) {
          Memcache.put(idx.getKey(), idx); // put to Memcache
        }
      }

      return idxList.toArray();
    } else {
      return map.values().toArray();
    }
  }
Beispiel #7
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;
    }
  }
  public List<EveryDayGameRankingVo> rankingGame(int maxNum) {

    List<EveryDayGameRanking> asList =
        Datastore.query(EveryDayGameRanking.class)
            .sort(EveryDayGameRankingMeta.get().deltaPoint.desc)
            .asList();
    int size = asList.size();
    if (size < maxNum) maxNum = size;
    List<EveryDayGameRankingVo> g = new ArrayList<EveryDayGameRankingVo>();
    for (EveryDayGameRanking edg : asList) {
      GameData gameData = Datastore.get(GameData.class, edg.getKey().getParent());
      contentCut(gameData);
      if (g.size() < maxNum) {

        EveryDayGameRankingVo setEdgvo = null;
        Set<Tag> fixTags = gameData.getFixTags();
        int deltaPoit = edg.getDeltaPoint();
        Boolean check = false;
        if (fixTags.size() != 0) {
          for (Tag tag : fixTags) {
            if (tag.getName().equals("チュートリアル")) {
              check = true;
            }
          }
          if (!check) {
            setEdgvo = setEdgvo(gameData, deltaPoit);
            g.add(setEdgvo);
          }
        } else {
          setEdgvo = setEdgvo(gameData, deltaPoit);
          g.add(setEdgvo);
        }
      } else break;
    }
    return g;
  }
Beispiel #9
0
 /*
  * (non-Javadoc)
  *
  * @see yanitime4u.yanitime.logic.UserLogic#findByKey(java.lang.Long)
  */
 @Override
 public Users findByKey(Long id) {
   AssertionUtil.assertNotNull(id);
   Key key = Datastore.createKey(Users.class, id);
   return Datastore.get(meta, key);
 }
  public Game getGameApi(Key key) {

    return Datastore.get(Game.class, key);
  }
 public GameData getGameData(Long id) {
   return Datastore.get(GameData.class, Datastore.createKey(GameData.class, id));
 }
  public GameData load(long id) {

    return Datastore.get(GameData.class, Datastore.createKey(GameData.class, id));
  }
  @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;
  }
  /** @inheritDoc */
  @Override
  public ContactEntry loadContactDetails(String contactId) {

    Key key = ContactEntry.createKey(contactId);
    return Datastore.get(ContactEntry.CONTACT, key);
  }