Exemplo n.º 1
0
  @Override
  public LikeComposite create(LikeComposite newLike) {
    // TODO Auto-generated method stub
    String username = (String) getThreadLocalRequest().getSession().getAttribute("loggedUser");
    if (username == null) return null;
    if (username.equals("")) return null;
    newLike.setUser(username);

    Interaction like = new Interaction(newLike);
    java.util.Date today = new java.util.Date();
    like.setTimestamp(today);

    TermSuggestionComposite tsVO = newLike.getTermSuggestion();

    Iterator<InteractionComposite> interactionIterator = tsVO.getInteractions().iterator();
    while (interactionIterator.hasNext()) {
      InteractionComposite interactionVO = interactionIterator.next();
      String interactionType = interactionVO.getClass().getName();
      if (interactionType.compareToIgnoreCase("dilmaj.shared.LikeComposite") == 0) {
        String un = interactionVO.getUser();
        if (username.equals(un)) return null;
      }
    }

    like.setTermSuggestionID(tsVO.getId());

    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      pm.makePersistent(like);

      String query = "select from " + TermSuggestion.class.getName() + " where id==" + tsVO.getId();

      List<TermSuggestion> allTermSuggestions = (List<TermSuggestion>) pm.newQuery(query).execute();

      if (allTermSuggestions == null) return null;

      if (allTermSuggestions.size() != 1) return null;

      TermSuggestion ts = allTermSuggestions.get(0);
      ts.addInteractionID(like.getId());
      newLike.setId(like.getId());
      newLike.setTimestamp(like.getTimestamp());
      pm.makePersistent(ts);
      // tsVO.a
    } finally {
      pm.close();
    }

    String fullURL = getThreadLocalRequest().getRequestURL().toString();
    String request = getThreadLocalRequest().getRequestURI();
    int index = fullURL.indexOf(request);
    String baseURL = fullURL.substring(0, index);
    String termURL = baseURL + "?termId=" + tsVO.getTerm().getId();
    String suggestionURL = baseURL + "?termSuggestionId=" + tsVO.getId();

    // sending notification email
    String tsOwner = tsVO.getSuggestion().getUser();
    String message =
        newLike.getUser()
            + " likes your suggestion <a href=\""
            + suggestionURL
            + "\">"
            + tsVO.getSuggestion().getCaption()
            + "</a> for the term  <a href=\""
            + termURL
            + "\">"
            + tsVO.getTerm().getCaption()
            + "</a>.";
    DilmajUserServiceImpl.sendMail(tsOwner, message);

    // live log
    // message=newComment.getUser()+" left a comment on "+tsOwner+"'s suggestion
    // "+tsVO.getSuggestion().getCaption()+" for the term "+tsVO.getTerm().getCaption()+".";
    MessageComposite messageVO = new MessageComposite(message);
    // messageVO.setDateTime(new Date());
    SessionServiceImpl.addMessage(messageVO);

    return newLike;
  }
Exemplo n.º 2
0
  @Override
  public UseCaseComposite create(UseCaseComposite newUseCase) {
    String username = (String) getThreadLocalRequest().getSession().getAttribute("loggedUser");
    if (username == null) return null;
    if (username.equals("")) return null;
    newUseCase.setUser(username);

    Interaction useCase = new Interaction(newUseCase);
    java.util.Date today = new java.util.Date();
    useCase.setTimestamp(today);

    TermSuggestionComposite tsVO = newUseCase.getTermSuggestion();
    useCase.setTermSuggestionID(tsVO.getId());

    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      pm.makePersistent(useCase);

      String query = "select from " + TermSuggestion.class.getName() + " where id==" + tsVO.getId();

      List<TermSuggestion> allTermSuggestions = (List<TermSuggestion>) pm.newQuery(query).execute();

      if (allTermSuggestions == null) return null;

      if (allTermSuggestions.size() != 1) return null;

      TermSuggestion ts = allTermSuggestions.get(0);
      ts.addInteractionID(useCase.getId());
      newUseCase.setId(useCase.getId());
      newUseCase.setTimestamp(useCase.getTimestamp());
      pm.makePersistent(ts);
      // tsVO.a
    } finally {
      pm.close();
    }

    String fullURL = getThreadLocalRequest().getRequestURL().toString();
    String request = getThreadLocalRequest().getRequestURI();
    int index = fullURL.indexOf(request);
    String baseURL = fullURL.substring(0, index);
    String termURL = baseURL + "?termId=" + tsVO.getTerm().getId();
    String suggestionURL = baseURL + "?termSuggestionId=" + tsVO.getId();

    // sending notification email
    String tsOwner = tsVO.getSuggestion().getUser();
    String message =
        newUseCase.getUser()
            + " added a use case to your suggestion <a href=\""
            + suggestionURL
            + "\">"
            + tsVO.getSuggestion().getCaption()
            + "</a> for the term  <a href=\""
            + termURL
            + "\">"
            + tsVO.getTerm().getCaption()
            + "</a>.";
    DilmajUserServiceImpl.sendMail(tsOwner, message);

    // live log
    // message=newComment.getUser()+" left a comment on "+tsOwner+"'s suggestion
    // "+tsVO.getSuggestion().getCaption()+" for the term "+tsVO.getTerm().getCaption()+".";
    MessageComposite messageVO = new MessageComposite(message);
    // messageVO.setDateTime(new Date());
    SessionServiceImpl.addMessage(messageVO);

    return newUseCase;
  }