Ejemplo 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;
  }
Ejemplo n.º 2
0
  @Test(groups = "web")
  public void testListDefaultGroupsValidationUser() throws IOException {
    tester.clickLinkWithText(getProperty("action.logout"));
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_USER);
      person.setConfirmed(true);
      personDao.create(person);
    }
    tester.setTextField("userName", "*****@*****.**");
    tester.setTextField("password", "stebjan");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent(getProperty("action.logout"));

    tester.clickLinkWithText(getProperty("menuItem.lists"));
    tester.assertTextPresent(getProperty("pageTitle.listOfDefinitions"));
    tester.assertLinkPresentWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.clickLinkWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default hardware");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForPeople"));
    tester.assertSelectOptionNotPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForExperiments"));
    tester.assertSelectOptionNotPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.fileMetadataDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default metadata parameters");

    tester.clickLinkWithText(getProperty("menuItem.weatherDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default weather");

    tester.clickLinkWithText(getProperty("action.logout"));
  }
Ejemplo n.º 3
0
  public PersonFormPage() throws IOException {

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

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));
    Person person = new Person();
    person.setDateOfBirth(new Timestamp(new Date().getTime()));

    add(new PersonForm("form", new Model<Person>(person), educationFacade, facade, getFeedback()));
  }
Ejemplo n.º 4
0
    private boolean validation(Person user, PersonFacade facade, boolean editation) {

      boolean validate = true;

      // if its editation we can't check if email exist
      if (!editation && facade.usernameExists(user.getEmail())) {
        error(ResourceUtils.getString("inUse.email"));
        validate = false;
      }

      if (user.getDateOfBirth() != null
          && user.getDateOfBirth().getTime() >= System.currentTimeMillis()) {
        error(ResourceUtils.getString("invalid.dateOfBirth"));
        validate = false;
      }

      if (user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty()) {
        try {
          if (user.getPhoneNumber().charAt(0) == '+') {
            Long.parseLong(user.getPhoneNumber().substring(1));
          } else {
            Long.parseLong(user.getPhoneNumber());
          }

        } catch (NumberFormatException ex) {
          error(ResourceUtils.getString("invalid.phoneNumber"));
          validate = false;
        }
      }

      return validate;
    }
Ejemplo n.º 5
0
  @BeforeMethod(groups = "web")
  public void setUp() {
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_USER);
      person.setConfirmed(true);
      personDao.create(person);
    }
    tester = new WebTester();
    tester.setScriptingEnabled(false);

    //   tester.setBaseUrl("http://eeg2.kiv.zcu.cz:8080");
    tester.setBaseUrl(url);
    tester.beginAt("/home-page");
  }
Ejemplo n.º 6
0
  @BeforeMethod(groups = "web")
  public void setUp() throws IOException {
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_USER);
      person.setConfirmed(true);
      personDao.create(person);
    }

    tester = new WebTester();
    tester.setBaseUrl(url);
    tester.beginAt("/home-page");
    tester.setTextField("userName", "*****@*****.**");
    tester.setTextField("password", "stebjan");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent(getProperty("action.logout"));
  }
Ejemplo n.º 7
0
  @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));
  }
Ejemplo n.º 8
0
  @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);
  }
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
0
  @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);
  }
Ejemplo n.º 11
0
  @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));
  }
Ejemplo n.º 12
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()));
  }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
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();
    }
  }
Ejemplo n.º 15
0
 @Override
 public void update(Person newInstance) {
   newInstance.setUsername(newInstance.getUsername().toLowerCase());
   getHibernateTemplate().update(newInstance);
 }
Ejemplo n.º 16
0
 @Override
 public Integer create(Person newInstance) {
   newInstance.setUsername(newInstance.getUsername().toLowerCase());
   return (Integer) getHibernateTemplate().save(newInstance);
 }