コード例 #1
1
ファイル: Ads.java プロジェクト: habib123/SEBA
  public static void viewAd(String id) {

    Ad ad = Ad.findById(Long.parseLong(id));
    List<Category> cats = Category.find("categorytype_id=?1 order by id", "1").fetch();

    EntityManager entityManager = play.db.jpa.JPA.em();
    List<BigInteger> bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by maxCount")
            .getResultList();
    int min = bCounts.get(0).intValue();
    int max = bCounts.get(bCounts.size() - 1).intValue();
    bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by category_id ")
            .getResultList();
    List<String> fonts = new ArrayList<String>();
    for (int i = 0; i < bCounts.size(); i++) {
      BigInteger count = bCounts.get(i);
      int x = Ads.getFontSize(count.intValue(), min, max);
      fonts.add(String.valueOf(x));
    }

    render(ad, fonts, min, max, cats);
  }
コード例 #2
0
 public StockPrice[] getStocks() {
   List<Stock> stocks = Stock.findAll();
   StockPrice[] prices = new StockPrice[stocks.size()];
   for (int i = 0; i < stocks.size(); i++) {
     prices[i] = stocks.get(i).asStockPrice();
   }
   return prices;
 }
コード例 #3
0
ファイル: Streams.java プロジェクト: janpascal/tweet-play2
  private static void startStream(List<String> terms) throws TwitterException {
    if (twitter != null) {
      twitter.cleanUp();
    }
    if (esClient != null) {
      esClient.close();
      esClient = null;
    }

    play.Configuration pconf = Play.application().configuration();
    String elasticSearchCluster = pconf.getString("tweet.elasticsearch.cluster.name");
    if (elasticSearchCluster != null) {
      Logger.info("Configuring ElasticSearch...");
      Settings settings =
          ImmutableSettings.settingsBuilder().put("cluster.name", elasticSearchCluster).build();

      esClient =
          new TransportClient(settings)
              .addTransportAddress(
                  new InetSocketTransportAddress(
                      pconf.getString("tweet.elasticsearch.transport.host"),
                      pconf.getInt("tweet.elasticsearch.transport.port")));
    } else {
      esClient = null;
    }

    twitter4j.conf.Configuration tconf = Application.getTwitterConfiguration();
    TwitterStreamFactory tf = new TwitterStreamFactory(tconf);
    twitter = tf.getInstance();
    StatusListener l =
        new TweetListener(
            terms,
            esClient,
            pconf.getString("tweet.elasticsearch.index"),
            pconf.getString("tweet.elasticsearch.type"));
    twitter.addListener(l);

    String[] tracks = new String[terms.size()];
    StringBuffer termsString = new StringBuffer();
    for (int i = 0; i < terms.size(); i++) {
      tracks[i] = terms.get(i);
      if (i != 0) termsString.append(",");
      termsString.append(terms.get(i));
    }
    FilterQuery q = new FilterQuery().track(tracks);
    twitter.filter(q);
    Logger.info("Starting listening for tweets using terms " + termsString.toString() + "...");
  }
コード例 #4
0
ファイル: BasicTest.java プロジェクト: Tri125/Yade
  @Test
  public void postComments() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    Post bobPost = new Post(bob, "My first post", "Hello world").save();

    // Post a first comment
    new Comment(bobPost, "Jeff", "Nice Post").save();
    new Comment(bobPost, "Tom", "I knew that !").save();

    // Retrieve all comments
    List<Comment> bobPostComments = Comment.find("byPost", bobPost).fetch();

    // Tests
    assertEquals(2, bobPostComments.size());

    Comment firstComment = bobPostComments.get(0);
    assertNotNull(firstComment);
    assertEquals("Jeff", firstComment.author);
    assertEquals("Nice Post", firstComment.content);
    assertNotNull(firstComment.postedAt);

    Comment secondComment = bobPostComments.get(1);
    assertNotNull(secondComment);
    assertEquals("Tom", secondComment.author);
    assertEquals("I knew that !", secondComment.content);
    assertNotNull(secondComment.postedAt);
  }
コード例 #5
0
 @Test
 public void findRepostByTags_String_単数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags("tag-goro-red").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
コード例 #6
0
 // -------------------------------------+
 @Test
 public void findRepostByAccounts_Entity_単数_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByAccounts(acnt1).fetch();
   assertThat(lst.size(), is(17));
   // DBからの取得リストの並び保証なし
 }
コード例 #7
0
 // -------------------------------------+
 @Test
 public void findRepostByTweets_Entity_単数_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1).fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
コード例 #8
0
 // -------------------------------------+
 @Test
 public void findRepostByCategories_Entity_単数_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
コード例 #9
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1).fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
コード例 #10
0
 // -------------------------------------+
 @Test
 public void findRepostByTags_Entity_単数_00() {
   Tag tag1 = Tag.findBySerialCode("tag-goro-red").first();
   List<RepostBase> lst = RepostBase.findRepostByTags(tag1).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
コード例 #11
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
コード例 #12
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
コード例 #13
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1").contributor(acnt).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
コード例 #14
0
 // -------------------------------------+
 @Test
 public void findRepostByCategories_Entity_単数_投稿者_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
コード例 #15
0
 // -------------------------------------+
 @Test
 public void findRepostByTweets_Entity_単数_投稿者_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
コード例 #16
0
 @Test
 public void findRepostByAccounts_String_複数_降順_00() {
   List<RepostBase> lst =
       RepostBase.findRepostByAccounts("usr-goro", "usr-jiro")
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(24));
   assertThat(lst.get(0).contributor.loginUser.screenName, is("goro_san"));
 }
コード例 #17
0
ファイル: Verifies.java プロジェクト: treejames/lovewebsite
 public static void index() {
   List<Verify> verifies = Verify.findAll();
   if (verifies.size() > 0) {
     render(verifies);
   } else {
     String message = "There is no upload need to be verified.";
     render(verifies, message);
   }
 }
コード例 #18
0
 @Test
 public void findRepostByTags_Entity_複数_投稿者_00() {
   Tag tag1 = Tag.findBySerialCode("tag-goro-red").first();
   Tag tag2 = Tag.findBySerialCode("tag-jiro-hello").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags(tag1, tag2).contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
コード例 #19
0
 // -------------------------------------+
 @Test
 public void findRepostByAccounts_Entity_単数_降順_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByAccounts(acnt1)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(17));
   assertThat(lst.get(0).contributor.loginUser.screenName, is("goro_san"));
 }
コード例 #20
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("cat-biz"));
 }
コード例 #21
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(5));
   assertThat(lst.get(0).getItem().serialCode, is("twt-jiro1"));
 }
コード例 #22
0
 @Test
 public void findRepostByTags_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTags("tag-goro-red", "tag-jiro-hello")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("tag-goro-red"));
 }
コード例 #23
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_降順_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByUsers(usr1)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(2));
   assertThat(lst.get(0).getItem().serialCode, is("usr-goro"));
 }
コード例 #24
0
ファイル: Streams.java プロジェクト: janpascal/tweet-play2
 public TweetListener(List<String> terms, Client esClient, String esIndex, String esType) {
   this.terms = terms;
   this.esClient = esClient;
   StringBuilder query = new StringBuilder();
   for (int i = 0; i < terms.size(); i++) {
     if (i > 0) query.append("|");
     // query.append("(").append(Pattern.quote(terms.get(i))).append(")");
     // query.append("(").append(terms.get(i)).append(")");
     query.append(terms.get(i));
   }
   Logger.info("Query match pattern: " + query.toString());
   this.matchPattern = Pattern.compile(query.toString(), Pattern.CASE_INSENSITIVE);
   Logger.info("Query match pattern: " + matchPattern.toString());
 }
コード例 #25
0
ファイル: AllPost2.java プロジェクト: viet-nguyen/Japid
  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // ------
    ; // line 1
    p("\n"); // line 3
    p("\n" + "\n"); // line 5
    if (allPost.size() > 0) { // line 8
      p("	<p></p>\n" + "	"); // line 8
      for (Post p : allPost) { // line 10
        p("	    "); // line 10
        final Display _Display1 = new Display(getOut());
        _Display1.setActionRunners(getActionRunners()).setOut(getOut());
        _Display1.render( // line 11
            new Display.DoBody<String>() { // line 11
              public void render(final String title) { // line 11
                // line 11
                p("			<p>The real title is: "); // line 11
                p(title); // line 12
                p(";</p>\n" + "	    "); // line 12
              }

              StringBuilder oriBuffer;

              @Override
              public void setBuffer(StringBuilder sb) {
                oriBuffer = getOut();
                setOut(sb);
              }

              @Override
              public void resetBuffer() {
                setOut(oriBuffer);
              }
            },
            named("post", p),
            named("as", "home")); // line 11
        p("	"); // line 13
      } // line 14
    } else { // line 15
      p("	<p>There is no post at this moment</p>\n"); // line 15
    } // line 17
    p("\n"); // line 17
    final Tag2 _Tag22 = new Tag2(getOut());
    _Tag22.setActionRunners(getActionRunners()).setOut(getOut());
    _Tag22.render(named("msg", blogTitle), named("age", 1000)); // line 19// line 19
    p("\n" + "<p>end of it</p>"); // line 19

    endDoLayout(sourceTemplate);
  }
コード例 #26
0
 public static void ajaxDeleteDocument(Long documentId) {
   // If it is not the root document we are going to delete
   if (documentId != 0L) {
     Document document = Document.findById(documentId);
     List<Document> children =
         Document.find("select p from Document p where p.parentId=?", document.id).fetch();
     // If target document contains children documents
     // then remove all children, don't leave scala documents
     int i = 0;
     for (i = 0; i < children.size(); i++) {
       children.get(i).delete();
     }
     document.delete();
   }
 }
コード例 #27
0
ファイル: Streams.java プロジェクト: janpascal/tweet-play2
 private static StreamConfig getConfig() {
   List<StreamConfig> configs = StreamConfig.find.findList();
   if (configs.size() > 1) {
     Logger.error("Multiple stream configurations present!");
   }
   StreamConfig config;
   if (configs.isEmpty()) {
     String[] tracks = new String[3];
     tracks[0] = "nl-alert";
     tracks[1] = "nlalert";
     tracks[2] = "\"nl alert\"";
     config = new StreamConfig(tracks);
     config.save();
   } else {
     config = configs.get(0);
   }
   return config;
 }
コード例 #28
0
ファイル: BasicTest.java プロジェクト: Tri125/Yade
  @Test
  public void createPost() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    new Post(bob, "My first post", "Hello world").save();

    // Test that the post has been created
    assertEquals(1, Post.count());

    // Retrieve all posts created by Bob
    List<Post> bobPosts = Post.find("byAuthor", bob).fetch();

    // Test
    assertEquals(1, bobPosts.size());
    Post firstPost = bobPosts.get(0);
    assertNotNull(firstPost);
    assertEquals(bob, firstPost.author);
    assertEquals("My first post", firstPost.title);
    assertEquals("Hello world", firstPost.content);
    assertNotNull(firstPost.postedAt);
  }
コード例 #29
0
 @Test
 public void findRepostByUsers_String_単数_00() {
   List<RepostBase> lst = RepostBase.findRepostByUsers("usr-goro").fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
コード例 #30
0
 // =============================================*
 // 問題なし
 @Test
 public void findRepostByUsers_例外_00() {
   List<RepostBase> lst = RepostBase.findRepostByUsers((Object) null).fetch();
   assertThat(lst.size(), is(10));
 }