예제 #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
 @Test
 public void findRepostByCategories_Entity_複数_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1, cat2).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
예제 #3
0
 @Test
 public void findRepostByCategories_Entity_複数_投稿者_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1, cat2).contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
예제 #4
0
 @Test
 public void findRepostByCategories_Entity_複数_投稿者_降順_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories(cat1, cat2)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("cat-biz"));
 }
예제 #5
0
  @Override
  public Category deserialize(JsonElement json, Type type, JsonDeserializationContext context)
      throws JsonParseException {

    Category category = new Category();
    JsonObject object = json.getAsJsonObject();

    category.setNameDE(object.get("nameDE").getAsString());
    category.setNameEN(object.get("nameEN").getAsString());

    for (JsonElement jsonQuestion : object.get("questions").getAsJsonArray()) {
      Question question = context.deserialize(jsonQuestion, new TypeToken<Question>() {}.getType());
      category.addQuestion(question);
    }

    return category;
  }
예제 #6
0
 public static Result newTeam() {
   Form<Team> filledForm = teamForm.bindFromRequest();
   if (filledForm.hasErrors()) {
     System.out.println("Errors: " + filledForm.errors());
     return badRequest(
         views.html.index.render(
             Team.all(),
             teamForm,
             Category.all(),
             categoryForm,
             Interview.all(),
             interviewForm,
             Application.getLoggedinUser()));
   } else {
     filledForm.get().save();
     return redirect(routes.Application.index());
   }
 }
예제 #7
0
  @Override
  public void onStart(Application app) {

    Category food = null;
    Category travel = null;
    Category sport = null;
    Category other = null;
    Company admin = null;
    Company bitCamp = null;
    long ownedCoupinID1 = 0;
    long ownedCoupinID2 = 0;
    int quantity = 1;
    int status = Coupon.Status.ACTIVE;
    String picture = Play.application().configuration().getString("defaultProfilePicture");

    if (!Company.exists("Admin")) {
      bitCamp =
          new Company(
              "Admin",
              "*****@*****.**",
              HashHelper.createPassword("bitadmin"),
              new Date(),
              picture,
              adress,
              city,
              contact);
      bitCamp.status = Status.ACTIVE;
      bitCamp.save();
    }

    if (!Company.exists("BitCamp")) {
      bitCamp =
          new Company(
              "BitCamp",
              "*****@*****.**",
              HashHelper.createPassword("bitcamp"),
              new Date(),
              picture,
              adress,
              city,
              contact);
      bitCamp.status = Status.ACTIVE;
      bitCamp.save();
    }

    if (Category.exists("Food") == false) {
      food =
          new Category(
              "Food",
              "http://res.cloudinary.com/bitfiles/image/upload/v1430902947/staticImages/food.png");
      food.save();
    }
    if (Category.exists("Travel") == false) {
      travel =
          new Category(
              "Travel",
              "http://res.cloudinary.com/bitfiles/image/upload/v1430902953/staticImages/travel.png");
      travel.save();
    }
    if (Category.exists("Sport") == false) {
      sport =
          new Category(
              "Sport",
              "http://res.cloudinary.com/bitfiles/image/upload/v1430902950/staticImages/sport.png");
      sport.save();
    }

    if (Category.exists("Other") == false) {
      other = new Category("Other");
      other.save();
    }

    if (Coupon.checkByName(nameCoupon1) == false) {
      Coupon.createCoupon(
          nameCoupon1,
          80,
          new Date(),
          "http://res.cloudinary.com/bitfiles/image/upload/v1430853980/staticImages/cp1.jpg",
          travel,
          descriptionCoupon1,
          remarkCoupon1,
          5,
          25,
          new Date(),
          bitCamp,
          status);
    }
    if (Coupon.checkByName(nameCoupon2) == false) {

      ownedCoupinID1 =
          Coupon.createCoupon(
              nameCoupon2,
              40,
              new Date(),
              "http://res.cloudinary.com/bitfiles/image/upload/v1430853989/staticImages/cp2.jpg",
              other,
              descriptionCoupon2,
              remarkCoupon2,
              5,
              20,
              new Date(),
              bitCamp,
              status);
    }
    /* creating a coupon that is not expired */
    if (Coupon.checkByName(nameCoupon3) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "01/01/2051";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      ownedCoupinID2 =
          Coupon.createCoupon(
              nameCoupon3,
              20,
              date,
              "http://res.cloudinary.com/bitfiles/image/upload/v1430854001/staticImages/cp3.jpg",
              food,
              descriptionCoupon3,
              remarkCoupon3,
              2,
              5,
              new Date(),
              bitCamp,
              status);
    }

    if (Coupon.checkByName(nameCoupon4) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      Coupon.createCoupon(
          nameCoupon4,
          350,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854005/staticImages/cp4.jpg",
          travel,
          descriptionCoupon4,
          remarkCoupon4,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (Coupon.checkByName(nameCoupon5) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }

      Coupon.createCoupon(
          nameCoupon5,
          17,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854008/staticImages/cp5.jpg",
          food,
          descriptionCoupon5,
          remarkCoupon5,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (Coupon.checkByName(nameCoupon6) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      Coupon.createCoupon(
          nameCoupon6,
          34,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854011/staticImages/cp6.jpg",
          travel,
          descriptionCoupon6,
          remarkCoupon6,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (Coupon.checkByName(nameCoupon7) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      Coupon.createCoupon(
          nameCoupon7,
          219,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854013/staticImages/cp7.jpg",
          travel,
          descriptionCoupon7,
          remarkCoupon7,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (Coupon.checkByName(nameCoupon8) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      Coupon.createCoupon(
          nameCoupon8,
          25,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854016/staticImages/cp8.jpg",
          sport,
          descriptionCoupon8,
          remarkCoupon8,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (Coupon.checkByName(nameCoupon9) == false) {
      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = "05/05/2020";
      Date date = null;
      try {
        date = df.parse(dateString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      Coupon.createCoupon(
          nameCoupon9,
          239,
          date,
          "http://res.cloudinary.com/bitfiles/image/upload/v1430854019/staticImages/cp9.jpg",
          travel,
          descriptionCoupon9,
          remarkCoupon9,
          5,
          30,
          new Date(),
          bitCamp,
          status);
    }

    if (User.check("*****@*****.**") == false) {
      User.createUser(
          "Admin",
          "",
          new Date(),
          "",
          "",
          "",
          "*****@*****.**",
          HashHelper.createPassword("bitadmin"),
          true,
          picture);
      EmailVerification setVerified = new EmailVerification(1, true);
      setVerified.save();
    }

    if (User.check("*****@*****.**") == false) {
      User user =
          new User(
              "Jesenko",
              "Gavric",
              new Date(),
              "",
              "",
              "",
              "*****@*****.**",
              HashHelper.createPassword("johndoe"),
              false,
              picture);

      user.save();
      EmailVerification setVerified = new EmailVerification(2, true);
      setVerified.save();
      Coupon c1 = Coupon.find(ownedCoupinID1);
      Coupon c2 = Coupon.find(ownedCoupinID2);
      TransactionCP.createTransaction(
          "AH-324ASDas", "bitSale", c1.price, quantity, c1.price, "TOKEN01010", user, c1);
      c1.maxOrder = c1.maxOrder - quantity;
      c1.statistic.bought(quantity);
      c1.save();
      TransactionCP.createTransaction(
          "AH-324ASsadD", "bitSale", c2.price, quantity, c2.price, "TOKEN2222", user, c2);
      c2.maxOrder = c2.maxOrder - quantity;
      c2.statistic.bought(quantity);
      c2.save();
    }

    if (User.check("*****@*****.**") == false) {
      User.createUser(
          "Vedad",
          "Zornic",
          new Date(),
          "",
          "",
          "",
          "*****@*****.**",
          HashHelper.createPassword("johndoe"),
          false,
          picture);
      EmailVerification setVerified = new EmailVerification(3, true);
      setVerified.save();
      Subscriber sb = new Subscriber(User.findByEmail("*****@*****.**"));
      sb.save();
    }

    if (FAQ.checkByQuestion("Želim kupiti današnju ponudu. Kako da to učinim?") == false) {
      FAQ.createFAQ(
          "Želim kupiti današnju ponudu. Kako da to učinim?",
          "Morate biti "
              + "registrovani i ulogovani na stranicu. Ukoliko još nemate nalog,"
              + " registracija je besplatna i traje manje od 30 sekundi, a također se "
              + "možete uvezati sa Vašim Facebook nalogom. Kada se ulogujete kliknite na"
              + " dugme Kupi i pratite jednostavne korake.");
    }

    if (FAQ.checkByQuestion("Na koji način plaćam ponudu i je li sigurno?") == false) {
      FAQ.createFAQ(
          "Na koji način plaćam ponudu i je li sigurno?",
          "Plaćanje možete obaviti na"
              + " jedan od sljedećih načina:"
              + "1.	Putem eKredita – eKredit možete uplatiti u banci ili pošti na naš transkcijski "
              + "račun, a on će Vam biti dodijeljen sljedeći radni dan ili najkasnije 48 sati nakon"
              + " uplate. Kada Vaš eKredit bude prikazan na Vašem profilu možete obaviti željenu kupovinu. "
              + "Više informacija možete pronaći na ovom linku nakon prijave na Vaš profil."
              + "2.	Putem kartice – Plaćanje je zbog sigurnosti, jednostavnije realizacije i brzine "
              + "obrade zahtjeva limitirano na kreditne i debitne MasterCard, Maestro i VISA kartice. "
              + "Plaćanje je potpuno sigurno, a više o tome možete pročitati na - sigurnost plaćanja."
              + "3.	Dio plaćate eKreditom, a dio karticom – Prilikom kupovine potrebno je da unesete iznos "
              + "eKredita koji želite da Vam se odbije i dalje idete na „Nastavi kupovinu“. Unesete sve"
              + " potrebne podatke i na taj način će Vam se jedan dio odbiti u vidu eKredita a ostatak"
              + " vrijednosti će biti rezervisan na Vašoj kartici."
              + "4. Gotovinska uplata kupona ili ekredita - uplatu možete izvršiti na eKupon prodajnim mjestima u"
              + " BBI tržnom centru i Grand centru na Ilidži. "
              + "5. Kupovina poklon bona na ime i prezime osobe koju želite bez obzira da li je registrovan korisnik ili ne.");
    }

    if (FAQ.checkByQuestion("Šta se dešava ako ponuda dana ne dosegne minimalan broj kupaca?")
        == false) {
      FAQ.createFAQ(
          "Šta se dešava ako ponuda dana ne dosegne minimalan broj kupaca?",
          "Da bi ponuda "
              + "uspjela mora dostići minimalan broj kupaca koji se određuje u dogovoru s partnerima."
              + "U slučaju da se ne kupi dovoljan broj kupona, ponuda propada i ništa Vam se ne naplaćuje. "
              + "Da izbjegnete ovakve situacije, pozovite što više osoba da se uključe na ponudu na "
              + "kojoj ste učestvovali.");
    }
    // Creating 10 testing posts.
    if (Post.all().size() < 1) {
      for (int i = 0; i < 10; i++) {
        Post.createPost(
            "Man must explore, and this is exploration at its greatest",
            "Problems look mighty small from 150 miles up",
            post_content,
            "http://res.cloudinary.com/bitfiles/image/upload/v1430859169/staticImages/explore.jpg",
            new Date(),
            User.find(true),
            "no,tag");
      }
    }
  }
예제 #8
0
파일: Ads.java 프로젝트: habib123/SEBA
  public static void list(
      String search, int category, Integer size, Integer page, int firstPage, int lastPage) {
    List<Ad> ads = null;

    List<Category> cats = Category.find("categorytype_id=?1", "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));
    }

    int pagesCount = 0;

    page = page != null ? page : 1;
    if (search.trim().length() == 0) {
      Long l = null;
      if (category == 0) {

        ads = Ad.find("order by createDate desc").fetch(page, size);
        l = Ad.count();
      } else {

        ads = Ad.find(" category_id=?1 order by createDate desc", category).fetch(page, size);
        l = Ad.count(" category_id=?1 ", category);
      }

      Long l2 = (l / 10);
      if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1);
      pagesCount = Integer.valueOf(l2.intValue());

    } else {
      search = search.toLowerCase();
      Long l = null;
      if (category == 0) {
        ads =
            Ad.find(
                    "(lower(headline) like ?1 OR lower(description) like ?2)",
                    "%" + search + "%",
                    "%" + search + "%")
                .fetch(page, size);
        l =
            Ad.count(
                "(lower(headline) like ?1 OR lower(description) like ?2)",
                "%" + search + "%",
                "%" + search + "%");
      } else {
        ads =
            Ad.find(
                    " category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)",
                    category,
                    "%" + search + "%",
                    "%" + search + "%")
                .fetch(page, size);
        l =
            Ad.count(
                "category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)",
                category,
                "%" + search + "%",
                "%" + search + "%");
      }

      Long l2 = (l / 10);
      if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1);
      pagesCount = Integer.valueOf(l2.intValue());
    }

    if ((lastPage - page) <= 2) {
      firstPage = page - 2;
      lastPage = page + 7;
      if (lastPage > pagesCount) lastPage = pagesCount;

    } else if ((page - firstPage) <= 2) {
      firstPage = page - 7;
      lastPage = page + 2;
      if (firstPage < 1) {
        firstPage = 1;
        lastPage = 10;
      }
    }

    if (lastPage > pagesCount) lastPage = pagesCount;

    render(ads, search, size, page, pagesCount, firstPage, lastPage, cats, fonts);
  }