コード例 #1
0
  /** {@inheritDoc} */
  public boolean canViewAllPurposeItem(Assignment a) {
    boolean rv = false;

    if (a != null) {
      AssignmentAllPurposeItem aItem = getAllPurposeItem(a.getId());
      if (aItem != null) {
        if (!aItem.getHide()) {
          Time now = TimeService.newTime();
          Date releaseDate = aItem.getReleaseDate();
          Date retractDate = aItem.getRetractDate();

          if (releaseDate == null && retractDate == null) {
            // no time limitation on showing the item
            rv = true;
          } else if (releaseDate != null && retractDate == null) {
            // has relase date but not retract date
            rv = now.getTime() > releaseDate.getTime();
          } else if (releaseDate == null && retractDate != null) {
            // has retract date but not release date
            rv = now.getTime() < retractDate.getTime();
          } else if (now != null) {
            // both releaseDate and retract date are not null
            // has both release and retract dates
            rv = now.getTime() > releaseDate.getTime() && now.getTime() < retractDate.getTime();
          }
        } else {
          rv = false;
        }
      }

      if (rv) {
        // reset rv
        rv = false;

        // need to check role/user permission only if the above time test returns true
        List<String> access = getAccessListForAllPurposeItem(aItem);
        User u = m_userDirectoryService.getCurrentUser();
        if (u != null) {
          if (access.contains(u.getId())) rv = true;
          else {
            try {
              String role =
                  m_authzGroupService.getUserRole(
                      u.getId(), m_siteService.siteReference(a.getContext()));
              if (access.contains(role)) rv = true;
            } catch (Exception e) {
              Log.warn(
                  this
                      + ".callViewAllPurposeItem() Hibernate cannot access user role for user id= "
                      + u.getId());
              return rv;
            }
          }
        }
      }
    }

    return rv;
  }
コード例 #2
0
 /** {@inheritDoc} */
 public boolean cleanAllPurposeItemAccess(AssignmentAllPurposeItem mItem) {
   boolean rv = false;
   Set<AssignmentAllPurposeItemAccess> accessSet = mItem.getAccessSet();
   if (accessSet != null) {
     for (Iterator<AssignmentAllPurposeItemAccess> iAccessSet = accessSet.iterator();
         iAccessSet.hasNext(); ) {
       AssignmentAllPurposeItemAccess access = iAccessSet.next();
       rv = removeAllPurposeItemAccess(access);
     }
   }
   return rv;
 }
コード例 #3
0
 /** {@inheritDoc}} */
 public boolean saveAllPurposeItem(AssignmentAllPurposeItem nItem) {
   try {
     getHibernateTemplate().saveOrUpdate(nItem);
     return true;
   } catch (DataAccessException e) {
     e.printStackTrace();
     Log.warn(
         this
             + ".saveAllPurposeItem() Hibernate could not save private AllPurpose for assignment "
             + nItem.getAssignmentId());
     return false;
   }
 }
コード例 #4
0
  /** {@inheritDoc}} */
  public boolean removeAllPurposeItem(AssignmentAllPurposeItem mItem) {

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