Esempio n. 1
0
  @Override
  public List<Article> getArticlesForUser(Person person, int limit) {
    String query;
    List articles = Collections.EMPTY_LIST;

    if (person.getAuthority().equals("ROLE_ADMIN")) {
      // We can simply load the newest articles
      query =
          "select DISTINCT a from Article a left join fetch a.articleComments order by a.time desc";
      articles = getSession().createQuery(query).setMaxResults(limit).list();
    } else {
      // We need to load only articles which can be viewed by the logged user.
      // That is, we need to load only public articles or articles from the groups the logged user
      // is member of.
      query =
          "select DISTINCT a from Article a left join fetch a.articleComments where "
              + "a.researchGroup.researchGroupId is null or "
              + "a.researchGroup.researchGroupId in "
              + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId) "
              + "order by a.time desc";
      articles =
          getSession()
              .createQuery(query)
              .setParameter("personId", person.getPersonId())
              .setMaxResults(limit)
              .list();
    }

    return articles;
  }
  @Override
  public int getFormsCount(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.countDistinct("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
  @Override
  @SuppressWarnings("unchecked")
  public List<String> getFormNames(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.property("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return getHibernateTemplate().findByCriteria(criteria);
  }
  @Override
  @SuppressWarnings("unchecked")
  public List<FormLayout> getLayouts(Person owner, String formName, FormLayoutType templateType) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));
    if (formName != null) criteria.add(Restrictions.eq("formName", formName));
    if (templateType != null) criteria.add(Restrictions.eq("type", templateType));

    return getHibernateTemplate().findByCriteria(criteria);
  }
  @Override
  public int getLayoutsCount(Person owner, String formName, FormLayoutType templateType) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.rowCount());
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));
    if (formName != null) criteria.add(Restrictions.eq("formName", formName));
    if (templateType != null) criteria.add(Restrictions.eq("type", templateType));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
Esempio n. 6
0
  public PersonFormPage(PageParameters parameters) throws IOException {

    StringValue paramId = parameters.get(DEFAULT_PARAM_ID);

    if (paramId.isNull() || paramId.isEmpty())
      throw new RestartResponseAtInterceptPageException(ListPersonPage.class);

    setPageTitle(ResourceUtils.getModel("pageTitle.editPerson"));
    add(new Label("title", ResourceUtils.getModel("pageTitle.editPerson")));

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));

    Person person = facade.getPersonForDetail(paramId.toInt());

    if (!securityFacade.userCanEditPerson(person.getPersonId()))
      throw new RestartResponseAtInterceptPageException(
          PersonDetailPage.class,
          PageParametersUtils.getDefaultPageParameters(person.getPersonId()));

    add(new PersonForm("form", new Model<Person>(person), educationFacade, facade, getFeedback()));
  }
Esempio n. 7
0
 public Map getInfoForAccountOverview(Person loggedPerson) {
   String hqlSelect =
       "select new map(p.username as username, p.givenname as givenname, p.surname as surname, p.authority as authority) from Person p where p.personId = :personId";
   Map info;
   List list =
       getHibernateTemplate().findByNamedParam(hqlSelect, "personId", loggedPerson.getPersonId());
   if (list.size() == 1) {
     info = (Map) list.get(0);
   } else {
     info = new HashMap<String, String>();
   }
   return info;
 }
Esempio n. 8
0
 @Override
 public int getArticleCountForPerson(Person person) {
   if (person.getAuthority().equals("ROLE_ADMIN")) {
     return ((Long) getSession().createQuery("select count(*) from Article").uniqueResult())
         .intValue();
   }
   String query =
       "select count(*) from Article a where a.person.personId = :personId or "
           + "a.researchGroup.researchGroupId is null or "
           + "a.researchGroup.researchGroupId in "
           + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId)";
   return ((Long)
           getSession()
               .createQuery(query)
               .setParameter("personId", person.getPersonId())
               .uniqueResult())
       .intValue();
 }
Esempio n. 9
0
  /**
   * Gets article detail information for article detail page. Check the correct permission of the
   * user to view requested article.
   *
   * @param id Id of the requested article
   * @param loggedPerson User whose permission is checked - should be logged user
   * @return If the user is permitted to view the article specified by id the Article object is
   *     returned. Otherwise, null is returned.
   */
  @Override
  public Article getArticleDetail(int id, Person loggedPerson) {

    if (loggedPerson.getAuthority().equals("ROLE_ADMIN")) {
      String query =
          "from Article a left join fetch a.subscribers left join fetch a.articleComments "
              + "where a.articleId = :id";
      return (Article) getSession().createQuery(query).setParameter("id", id).uniqueResult();
    } else {
      String query =
          "from Article a left join fetch a.subscribers left join fetch a.articleComments "
              + "where a.articleId = :id and ("
              + "a.researchGroup.researchGroupId is null or "
              + "a.researchGroup.researchGroupId in "
              + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId))";
      return (Article)
          getSession()
              .createQuery(query)
              .setParameter("id", id)
              .setParameter("personId", loggedPerson.getPersonId())
              .uniqueResult();
    }
  }