/** {@inheritDoc} */
  public boolean canEditNoteItem(Assignment a) {
    String userId = "";
    User u = m_userDirectoryService.getCurrentUser();
    if (u != null) {
      userId = u.getId();
    }

    if (a != null) {
      AssignmentNoteItem note = getNoteItem(a.getId());
      if (note != null) {
        if (note.getCreatorId().equals(userId)) {
          // being creator can edit
          return true;
        } else if (note.getShareWith() == AssignmentConstants.NOTE_READ_AND_WRITE_BY_OTHER
            && m_assignmentService.allowGradeSubmission(a.getReference())) {
          return true;
        }
      } else {
        return true;
      }
    } else {
      return true;
    }

    return false;
  }
  /** {@inheritDoc} */
  public boolean canReadNoteItem(Assignment a, String context) {
    if (a != null) {
      AssignmentNoteItem note = getNoteItem(a.getId());
      if (note != null) {
        User u = m_userDirectoryService.getCurrentUser();
        String noteCreatorId = note.getCreatorId();
        if (noteCreatorId.equals(u.getId())) {
          return true;
        } else if (m_assignmentService.allowGradeSubmission(a.getReference())) {
          // check whether the instructor type can view the note
          int share = note.getShareWith();
          if (share == AssignmentConstants.NOTE_READ_BY_OTHER
              || share == AssignmentConstants.NOTE_READ_AND_WRITE_BY_OTHER) {
            return true;
          }
        }
      }
    } else {
      if (m_assignmentService.allowAddAssignment(context)) {
        return true;
      }
    }

    return false;
  }
 /** {@inheritDoc}} */
 public boolean saveNoteItem(AssignmentNoteItem nItem) {
   try {
     getHibernateTemplate().saveOrUpdate(nItem);
     return true;
   } catch (DataAccessException e) {
     e.printStackTrace();
     Log.warn(
         this
             + ".saveNoteItem() Hibernate could not save private note for assignment "
             + nItem.getAssignmentId());
     return false;
   }
 }
  /** {@inheritDoc}} */
  public boolean removeNoteItem(AssignmentNoteItem mItem) {

    try {
      getHibernateTemplate().delete(mItem);
      return true;
    } catch (DataAccessException e) {
      e.printStackTrace();
      Log.warn(
          this
              + ".removeNoteItem() Hibernate could not delete NoteItem for assignment "
              + mItem.getAssignmentId());
      return false;
    }
  }