Examples of SimpleMessageException


Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public List<PermissibleObject> getTopRated(int maxResults, int minNumVotes, String classType) throws SimpleMessageException {
    if (classType == null) {
      throw new SimpleMessageException("classType not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      List<PermissibleObject> mostRated = new ArrayList<PermissibleObject>();
      String simpleClassName = Class.forName(classType).getSimpleName();
      List<PermissibleObject> list = session.get()
          .createQuery("from " + simpleClassName + " where numRatingVotes >= " + minNumVotes + " order by averageRating desc").setMaxResults(maxResults)
          .setCacheable(true).list();
      for (PermissibleObject permissibleObject : list) {
        if (SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
          mostRated.add(permissibleObject);
        }
      }
      return mostRated;
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public List<PermissibleObject> getBottomRated(int maxResults, int minNumVotes, String classType) throws SimpleMessageException {
    if (classType == null) {
      throw new SimpleMessageException("classType not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      List<PermissibleObject> mostRated = new ArrayList<PermissibleObject>();
      String simpleClassName = Class.forName(classType).getSimpleName();
      List<PermissibleObject> list = session.get()
          .createQuery("from " + simpleClassName + " where numRatingVotes >= " + minNumVotes + " order by averageRating asc").setMaxResults(maxResults)
          .setCacheable(true).list();
      for (PermissibleObject permissibleObject : list) {
        if (SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
          mostRated.add(permissibleObject);
        }
      }
      return mostRated;
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public List<PermissibleObject> getMostLiked(int maxResults, int minNumVotes, String classType) throws SimpleMessageException {
    if (classType == null) {
      throw new SimpleMessageException("classType not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      List<PermissibleObject> mostRated = new ArrayList<PermissibleObject>();
      String simpleClassName = Class.forName(classType).getSimpleName();
      List<PermissibleObject> list = session.get().createQuery("from " + simpleClassName + " where numUpVotes >= " + minNumVotes + " order by numUpVotes desc")
          .setMaxResults(maxResults).setCacheable(true).list();
      for (PermissibleObject permissibleObject : list) {
        if (SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
          mostRated.add(permissibleObject);
        }
      }
      return mostRated;
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public List<PermissibleObject> getMostDisliked(int maxResults, int minNumVotes, String classType) throws SimpleMessageException {
    if (classType == null) {
      throw new SimpleMessageException("classType not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      List<PermissibleObject> mostRated = new ArrayList<PermissibleObject>();
      String simpleClassName = Class.forName(classType).getSimpleName();
      List<PermissibleObject> list = session.get()
          .createQuery("from " + simpleClassName + " where numDownVotes >= " + minNumVotes + " order by numDownVotes desc").setMaxResults(maxResults)
          .setCacheable(true).list();
      for (PermissibleObject permissibleObject : list) {
        if (SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
          mostRated.add(permissibleObject);
        }
      }
      return mostRated;
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public List<PermissibleObject> getCreatedSince(int maxResults, long sinceDateMillis, String classType) throws SimpleMessageException {
    if (classType == null) {
      throw new SimpleMessageException("classType not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      List<PermissibleObject> mostRated = new ArrayList<PermissibleObject>();
      String simpleClassName = Class.forName(classType).getSimpleName();
      List<PermissibleObject> list = session.get()
          .createQuery("from " + simpleClassName + " where creationDate >= " + sinceDateMillis + " order by creationDate desc").setMaxResults(maxResults)
          .setCacheable(true).list();
      for (PermissibleObject permissibleObject : list) {
        if (SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
          mostRated.add(permissibleObject);
        }
      }
      return mostRated;
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    return voterGUID;
  }

  public PermissibleObject getNextUnratedPermissibleObject(String objectType) throws SimpleMessageException {
    if (StringUtils.isEmpty(objectType)) {
      throw new SimpleMessageException("Type not supplied.");
    }
    PermissibleObject object = null;
    User authUser = getAuthenticatedUser(session.get());
    object = RatingHelper.getNextUnratedPermissibleObject(session.get(), objectType, authUser, getVoterGUID());
    return object;
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    return object;
  }

  public UserAdvisory getUserAdvisory(PermissibleObject permissibleObject) throws SimpleMessageException {
    if (permissibleObject == null) {
      throw new SimpleMessageException("PermissibleObject not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      permissibleObject = (PermissibleObject) session.get().load(PermissibleObject.class, permissibleObject.getId());

      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to get advisory on this content.");
      }
      // find rating based on remote address if needed
      return AdvisoryHelper.getUserAdvisory(session.get(), permissibleObject, authUser, getVoterGUID());
    } catch (Throwable t) {
      Logger.log(t);
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public UserAdvisory setUserAdvisory(PermissibleObject permissibleObject, int advisory) throws SimpleMessageException {
    if (permissibleObject == null) {
      throw new SimpleMessageException("PermissibleObject not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    Transaction tx = session.get().beginTransaction();
    try {
      permissibleObject = (PermissibleObject) session.get().load(PermissibleObject.class, permissibleObject.getId());

      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to set advisory on this content.");
      }

      // check if rating already exists
      UserAdvisory userAdvisory = AdvisoryHelper.getUserAdvisory(session.get(), permissibleObject, authUser, getVoterGUID());
      if (userAdvisory != null) {
        throw new SimpleMessageException("Already voted.");
      }

      float totalAdvisory = (float) permissibleObject.getNumAdvisoryVotes() * permissibleObject.getAverageAdvisory();
      totalAdvisory += advisory;
      permissibleObject.setNumAdvisoryVotes(permissibleObject.getNumAdvisoryVotes() + 1);
      float newAvg = totalAdvisory / (float) permissibleObject.getNumAdvisoryVotes();
      permissibleObject.setAverageAdvisory(newAvg);
      session.get().save(permissibleObject);

      userAdvisory = new UserAdvisory();
      userAdvisory.setPermissibleObject(permissibleObject);
      userAdvisory.setRating(advisory);
      userAdvisory.setVoter(authUser);
      userAdvisory.setVoterGUID(getVoterGUID());

      session.get().save(userAdvisory);
      tx.commit();
      return userAdvisory;
    } catch (Throwable t) {
      Logger.log(t);
      try {
        tx.rollback();
      } catch (Throwable tt) {
      }
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public Boolean submitComment(Comment comment) throws SimpleMessageException {
    if (comment == null) {
      throw new SimpleMessageException("Comment not supplied.");
    }
    if (comment.getParent() == null) {
      throw new SimpleMessageException("PermissibleObject not supplied with comment.");
    }
    User authUser = getAuthenticatedUser(session.get());
    Transaction tx = session.get().beginTransaction();
    try {
      PermissibleObject parentPermissibleObject = (PermissibleObject) session.get().load(PermissibleObject.class, comment.getParent().getId());
      parentPermissibleObject.setNumComments(parentPermissibleObject.getNumComments() + 1);
      comment.setParent(parentPermissibleObject);
      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, comment.getParent(), PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to make comments on this content.");
      }
      if (!comment.getParent().isAllowComments()) {
        throw new SimpleMessageException("Comments are not allowed on this content.");
      }
      // the comment is approved if we are not moderating or if the commenter is the file owner
      comment.setApproved(!comment.getParent().isModerateComments() || comment.getParent().getOwner().equals(authUser));
      comment.setAuthorIP(getThreadLocalRequest().getRemoteAddr());
      session.get().save(comment);
      session.get().save(parentPermissibleObject);
      tx.commit();
      return true;
    } catch (Throwable t) {
      Logger.log(t);
      try {
        tx.rollback();
      } catch (Throwable tt) {
      }
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here

Examples of org.damour.base.client.exceptions.SimpleMessageException

    }
  }

  public Boolean approveComment(Comment comment) throws SimpleMessageException {
    if (comment == null) {
      throw new SimpleMessageException("Comment not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    if (authUser == null) {
      throw new SimpleMessageException(".");
    }
    Transaction tx = session.get().beginTransaction();
    try {
      comment = ((Comment) session.get().load(Comment.class, comment.getId()));
      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, comment.getParent(), PERM.WRITE)) {
        throw new SimpleMessageException("User is not authorized to approve comments for this content.");
      }
      comment.setApproved(true);
      session.get().save(comment);
      tx.commit();
      return true;
    } catch (Throwable t) {
      Logger.log(t);
      try {
        tx.rollback();
      } catch (Throwable tt) {
      }
      throw new SimpleMessageException(t.getMessage());
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.