Exemplo n.º 1
0
  @Restrict(Mupi.USER_ROLE)
  public static Result comment(String body, Long id) {
    final User u = Mupi.getLocalUser(session());
    final models.Profile p = u.profile;
    final models.Publication pub = models.Publication.find.byId(id);

    String safeBody =
        Jsoup.clean(
            textWithLinks(body.replaceAll("(\r\n|\n)", " <br/> ")),
            Whitelist.none().addTags("br", "a").addAttributes("a", "href", "target"));

    if (pub != null) PubComment.create(pub, p, safeBody);
    List<UserEmail> l_ue = models.Profile.emailsFromPublication(pub);
    for (UserEmail ue : l_ue) {
      if (u.getEmail().equalsIgnoreCase(ue.getEmail()))
        System.out.println("Commenter: " + ue.getEmail());
      else System.out.println(ue.getEmail());
    }
    return selectFeed(getLocalInterest(), getLocalLocation());
  }
Exemplo n.º 2
0
  @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());
    }
  }