コード例 #1
0
ファイル: Feed.java プロジェクト: virgilio/mupi-dev
  @Restrict(Mupi.USER_ROLE)
  public static Result selectFeed(Long i, Long l) {
    final models.Profile p = Mupi.getLocalUser(session()).profile;

    return renderFeedContent(
        0,
        Publication.findByInterestLocation(i, l, 0, 10, "created desc"),
        Promotion.findByInterestLocation(i, l, 0, 5, "date, time"),
        models.Interest.find.byId(i),
        models.Location.find.byId(l));
  }
コード例 #2
0
ファイル: Feed.java プロジェクト: virgilio/mupi-dev
  public static Result feed() {
    final User user = Mupi.getLocalUser(session());
    if (user == null || user.profile == null) {
      session("ref", request().getHeader(HttpHeaders.REFERER));
      return ok(
          index.render(
              MyUsernamePasswordAuthProvider.LOGIN_FORM,
              MyUsernamePasswordAuthProvider.SIGNUP_FORM));
    } else if (session("ref") != null && !session().get("ref").equalsIgnoreCase("null")) {
      String url = session("ref");
      session().remove("ref");
      return redirect(url);
    } else if (user.getProfile().getInterests().isEmpty()) {
      return redirect(routes.Interest.interestManager());
    } else if (user.getProfile().getStatus() == MupiParams.FIRST_LOGIN) {
      return redirect(routes.Profile.profile());
    } else {
      Long interest = getLocalInterest();
      Long location = getLocalLocation();

      models.Interest i;
      if (interest == null) i = null;
      else i = models.Interest.find.byId(interest);
      models.Location l;
      if (location == null) l = null;
      else l = models.Location.find.byId(location);

      return ok(
          views.html.feed.render(
              user,
              user.getProfile().getInterests(),
              user.getProfile().getLocations(),
              i,
              l,
              Publication.findByInterests(
                  models.Interest.getIds(user.getProfile().getInterests()), 0l),
              Promotion.findByInterests(
                  models.Interest.getIds(user.getProfile().getInterests()), 0l),
              form(models.Promotion.class),
              PROMOTE_MEETUP_FORM,
              HOST_MEETUP_FORM,
              MyUsernamePasswordAuthProvider.LOGIN_FORM,
              MyUsernamePasswordAuthProvider.SIGNUP_FORM));
    }
  }
コード例 #3
0
ファイル: Feed.java プロジェクト: virgilio/mupi-dev
  @Restrict(Mupi.USER_ROLE)
  public static Result nextPromotions(Long fromId) {
    final models.Profile p = Mupi.getLocalUser(session()).profile;
    Long i = MupiSession.getLocalInterest();
    Long l = MupiSession.getLocalLocation();
    List<models.Promotion> proms =
        Promotion.findByInterestLocation(i, l, 0, 5, "date, time", fromId).getList();

    Integer status = 0;
    if (proms.isEmpty()) status = 2;

    return AjaxResponse.build(
        status,
        promList
            .render(
                proms,
                MyUsernamePasswordAuthProvider.LOGIN_FORM,
                MyUsernamePasswordAuthProvider.SIGNUP_FORM)
            .body());
  }
コード例 #4
0
ファイル: Feed.java プロジェクト: virgilio/mupi-dev
  @Dynamic("editor")
  public static Result promote() {
    models.User u = Mupi.getLocalUser(session());
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture = body.getFile("picture");
    String picturePath = BLANK_EVT;

    DynamicForm bindedForm = form().bindFromRequest();
    Long i = getInterest(bindedForm.get("interest"));
    Long l = getLocation(bindedForm.get("location"));
    models.Interest iObj = null;
    models.Location lObj = null;
    if (i != null) iObj = models.Interest.find.byId(i);
    if (l != null) lObj = models.Location.find.byId(l);

    final Form<models.Promotion> filledForm = form(models.Promotion.class).bindFromRequest();
    final models.Profile p = Mupi.getLocalUser(session()).profile;

    try {
      if (picture != null) {
        String fileName = picture.getFilename();
        File file = picture.getFile();
        int index = (fileName.toLowerCase()).lastIndexOf('.');
        String extension = "png";

        if (index > 0 && index < fileName.length() - 1) {
          extension = fileName.substring(index + 1).toLowerCase();
        }

        String hashTime = getMD5(System.currentTimeMillis());
        String hashCommunity = getMD5(iObj.toString() + lObj.toString());

        File destinationFile =
            new File(
                MupiParams.EVENT_ROOT
                    + MupiParams.PIC_ROOT
                    + "//"
                    + hashCommunity
                    + "//"
                    + hashTime
                    + fileName);
        FileUtils.copyFile(file, destinationFile);
        picturePath = "/" + hashCommunity + "/" + hashTime + fileName;

        File medium =
            new File(
                MupiParams.EVENT_ROOT
                    + MupiParams.PIC_MEDIUM
                    + "//"
                    + hashCommunity
                    + "//"
                    + hashTime
                    + fileName);
        medium.mkdirs();

        BufferedImage bi = ImageHandler.createSmallInterest(destinationFile);
        bi = ImageHandler.createMediumPromotion(destinationFile);
        ImageIO.write(bi, extension, medium);
      } else {
        picturePath = BLANK_EVT;
      }

      String safeDesc = Jsoup.clean(filledForm.get().getDescription(), Whitelist.simpleText());

      Promotion pr =
          models.Promotion.create(
              p,
              lObj,
              iObj,
              filledForm.get().getTitle(),
              filledForm.get().getAddress(),
              filledForm.get().getDate(),
              filledForm.get().getTime(),
              safeDesc,
              filledForm.get().getLink(),
              picturePath,
              PubType.EVENT,
              new Integer(0),
              new Integer(0),
              new Double(0.0));

      flash(Mupi.FLASH_MESSAGE_KEY, Messages.get("mupi.promotion.created"));

      List<UserEmail> l_ue = models.Profile.emailsFromPublication(pr.getPublication());
      for (UserEmail ue : l_ue) {
        if (u.getEmail().equalsIgnoreCase(ue.getEmail()))
          System.out.println("Commenter: " + ue.getEmail());
        else System.out.println(ue.getEmail());
      }

      return redirect(routes.Feed.feed());
    } catch (Exception e) {
      flash(
          Mupi.FLASH_ERROR_KEY,
          "Erro ao divulgar evento, por favor contate-nos para que possamos resolver este problema.");
      // System.out.println(e.getMessage());
      e.printStackTrace();
      return redirect(routes.Feed.feed());
    }
  }