Esempio n. 1
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;
    }
Esempio n. 2
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()));
  }
Esempio n. 3
0
    public PersonForm(
        String id,
        IModel<Person> model,
        final EducationLevelFacade educationFacade,
        final PersonFacade personFacade,
        final FeedbackPanel feedback)
        throws IOException {
      super(id, new CompoundPropertyModel<Person>(model));

      EmailTextField email = new EmailTextField("username");
      email.setLabel(ResourceUtils.getModel("label.email"));
      email.setRequired(true);
      FormComponentLabel emailLabel = new FormComponentLabel("emailLb", email);
      add(email, emailLabel);

      final PersonFormPanel<Person> panelPerson =
          new PersonFormPanel<Person>("panelPerson", model, educationFacade);
      add(panelPerson);

      AjaxButton submit =
          new AjaxButton("submit", ResourceUtils.getModel("button.save"), this) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
              target.add(feedback);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
              Person user = panelPerson.getModelObject();
              user.setUsername(PersonForm.this.getModelObject().getUsername());
              user.setEmail(user.getUsername().toLowerCase());
              boolean isEdit = user.getPersonId() > 0;

              if (validation(user, personFacade, isEdit)) {
                if (isEdit) {
                  personFacade.update(user);
                } else {
                  user.setAuthority(Util.ROLE_READER);
                  personFacade.create(user);
                }
                setResponsePage(ListPersonPage.class);
              }
              target.add(feedback);
            }
          };
      add(submit);
    }
Esempio n. 4
0
  public SearchResultPanel(String id, StringValue searchString, ResultCategory category) {
    super(id);
    IDataProvider<FullTextResult> fullTextResults =
        new SearchResultDataProvider(searchString, category);
    long foundResults = fullTextResults.size();
    if (foundResults == 0) {
      isModelEmpty = true;
    }
    if (foundResults > ITEMS_PER_PAGE) {
      foundResultsPerMultiplePages = true;
    }

    add(
        new Label(
            "numberOfResults",
            ResourceUtils.getString(
                "text.search.numberOfResultsFound", new Model<Serializable>(foundResults))) {
          @Override
          public boolean isVisible() {
            return !isModelEmpty; // visible if any documents are found
          }
        });

    add(
        new Label("noResultsFound", ResourceUtils.getString("text.search.noResults")) {
          @Override
          public boolean isVisible() {
            return isModelEmpty; // visible if no documents are found
          }
        });

    add(new SearchFacets("categories", searchString, category));

    SearchResultList searchResultList =
        new SearchResultList("results", fullTextResults, ITEMS_PER_PAGE);
    add(searchResultList);
    add(
        new PagingNavigator("navigator", searchResultList) {
          @Override
          public boolean isVisible() {
            return foundResultsPerMultiplePages;
          }
        });
  }
Esempio n. 5
0
    @Override
    public void populateItem(Item<FullTextResult> item) {
      item.setModel(new CompoundPropertyModel<FullTextResult>(item.getModel()));

      String title = item.getModelObject().getTitle();
      if (title.isEmpty()) {
        title = ResourceUtils.getString("text.search.results.title.empty");
      }

      final String source = item.getModelObject().getSource();
      String sourceString = "";
      if (source.equals(IndexingUtils.SOURCE_LINKEDIN)) {
        sourceString = ResourceUtils.getString("text.search.source.linkedin");
      } else {
        sourceString = ResourceUtils.getString("text.search.source.database");
      }

      item.add(new Label("title", title).setEscapeModelStrings(false));
      item.add(new Label("type"));
      item.add(
          new Label("source", sourceString) {
            @Override
            public boolean isVisible() {
              return source.equals(IndexingUtils.SOURCE_LINKEDIN);
            }
          });
      item.add(
          new ListView<String>("textFragments") {
            @Override
            protected void populateItem(ListItem<String> item) {
              item.add(
                  new Label("textFragment", item.getModelObject()).setEscapeModelStrings(false));
            }
          });
      item.add(
          new DateLabel(
              "timestamp", new PatternDateConverter(StringUtils.DATE_TIME_FORMAT_PATTER, true)));
      BookmarkablePageLink link =
          new BookmarkablePageLink<Void>(
              "link",
              item.getModelObject().getTargetPage(),
              PageParametersUtils.getDefaultPageParameters(item.getModelObject().getId()));
      item.add(link);
    }
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 MetadataFormPage(final PageParameters parameters) {

    setPageTitle(ResourceUtils.getModel("pageTitle.metadata.new"));
    add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

    StringValue value = parameters.get(DEFAULT_PARAM_ID);
    if (value.isEmpty() || value.isNull()) {
      throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
    }

    int experimentId = value.toInt();
    Experiment exp = expFacade.getExperimentForDetail(experimentId);
    add(
        new MetadataForm(
            "metadata-form",
            new Model<Section>(exp.getElasticExperiment().getMetadata()),
            experimentId));
    getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
  }
Esempio n. 8
0
 public BasePage() {
   add(new Label("pageTitle", ResourceUtils.getModel("title.app")));
 }
  private void setupComponents() {

    setPageTitle(ResourceUtils.getModel("pageTitle.weatherDefinitionsList"));

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

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupPlaceholderTag(true);

    final ListModelWithResearchGroupCriteria<Weather> model =
        new ListModelWithResearchGroupCriteria<Weather>() {

          private static final long serialVersionUID = 1L;

          @Override
          protected List<Weather> loadList(ResearchGroup group) {
            if (group == null || group.getResearchGroupId() == CoreConstants.DEFAULT_ITEM_ID)
              return facade.getDefaultRecords();
            else {
              return facade.getRecordsByGroup(group.getResearchGroupId());
            }
          }
        };

    List<ResearchGroup> groups;
    final boolean isAdmin = security.isAdmin();
    final boolean isExperimenter = security.userIsExperimenter();
    if (isAdmin) {
      ResearchGroup defaultGroup =
          new ResearchGroup(
              CoreConstants.DEFAULT_ITEM_ID,
              EEGDataBaseSession.get().getLoggedUser(),
              ResourceUtils.getString("label.defaultWeather"),
              "-");
      groups = researchGroupFacade.getAllRecords();
      groups.add(0, defaultGroup);
    } else
      groups =
          researchGroupFacade.getResearchGroupsWhereMember(
              EEGDataBaseSession.get().getLoggedUser());

    PropertyListView<Weather> weathers =
        new PropertyListView<Weather>("weathers", model) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(final ListItem<Weather> item) {
            item.add(new Label("weatherId"));
            item.add(new Label("title"));
            item.add(new Label("description"));

            PageParameters parameters =
                PageParametersUtils.getDefaultPageParameters(item.getModelObject().getWeatherId())
                    .add(
                        PageParametersUtils.GROUP_PARAM,
                        (model.getCriteriaModel().getObject() == null)
                            ? CoreConstants.DEFAULT_ITEM_ID
                            : model.getCriteriaModel().getObject().getResearchGroupId());

            item.add(new BookmarkablePageLink<Void>("edit", WeatherFormPage.class, parameters));
            item.add(
                new AjaxLink<Void>("delete") {

                  private static final long serialVersionUID = 1L;

                  @Override
                  public void onClick(AjaxRequestTarget target) {

                    int id = item.getModelObject().getWeatherId();
                    ResearchGroup group = model.getCriteriaModel().getObject();

                    if (facade.canDelete(id)) {
                      if (group != null) {
                        int groupId = group.getResearchGroupId();

                        if (groupId
                            == CoreConstants
                                .DEFAULT_ITEM_ID) { // delete default weather if it's from default
                          // group
                          if (!facade.hasGroupRel(
                              id)) { // delete only if it doesn't have group relationship
                            facade.delete(item.getModelObject());
                            setResponsePage(ListWeatherDefinitiosPage.class);
                          } else {
                            getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                          }
                        } else {
                          WeatherGroupRel h = facade.getGroupRel(id, groupId);
                          if (!facade.isDefault(id)) { // delete only non default weather
                            facade.delete(item.getModelObject());
                          }
                          facade.deleteGroupRel(h);
                          setResponsePage(ListWeatherDefinitiosPage.class);
                        }
                      }

                    } else {
                      getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                    }

                    target.add(container);
                    target.add(getFeedback());
                  }

                  @Override
                  protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);

                    AjaxCallListener ajaxCallListener = new AjaxCallListener();
                    ajaxCallListener.onPrecondition(
                        "return confirm('Are you sure you want to delete item?');");
                    attributes.getAjaxCallListeners().add(ajaxCallListener);
                  }
                }.setVisibilityAllowed(isAdmin || isExperimenter));
          }
        };
    container.add(weathers);

    AjaxLink<Void> link =
        new AjaxLink<Void>("addWeatherLink") {

          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            int researchGroupId =
                (model.getCriteriaModel().getObject() == null)
                    ? CoreConstants.DEFAULT_ITEM_ID
                    : model.getCriteriaModel().getObject().getResearchGroupId();
            setResponsePage(
                WeatherFormPage.class,
                PageParametersUtils.getPageParameters(
                    PageParametersUtils.GROUP_PARAM, researchGroupId));
          }
        };
    link.setVisibilityAllowed(isAdmin || isExperimenter);

    add(
        new ResearchGroupSelectForm(
            "form",
            model.getCriteriaModel(),
            new ListModel<ResearchGroup>(groups),
            container,
            isAdmin));
    add(link, container);
  }