public ContributionCommentSuccessPage(PageParameters parameters) {
    super(parameters);

    contributionId = parameters.getInt("contribution");

    boolean success =
        HibernateUtils.wrapTransaction(
            getHibernateSession(),
            new HibernateTask() {
              public boolean run(Session session) {
                contribution =
                    (Contribution)
                        session
                            .createQuery("select c from Contribution as c where c.id = :id")
                            .setInteger("id", contributionId)
                            .uniqueResult();
                return true;
              }
            });

    if (!success) {
      logger.info("unknown contribution of id " + contributionId);
      throw new RestartResponseAtInterceptPageException(NotFoundPage.class);
    }

    initializeLocation(getNavMenu().getLocationByKey("teacherIdeas"));

    add(
        new LocalizedText(
            "comment-header",
            "contribution.comment.success",
            new Object[] {HtmlUtils.encode(contribution.getTitle())}));

    add(
        new LocalizedText(
            "comment-success",
            "contribution.comment.successRedirection",
            new Object[] {
              ContributionPage.getLinker(contributionId).getHref(getPageContext(), getPhetCycle()),
              REDIRECTION_DELAY_SECONDS
            }));

    Label redirector = new Label("redirector", "");
    redirector.add(
        new AttributeModifier(
            "content",
            true,
            new Model<String>(
                REDIRECTION_DELAY_SECONDS
                    + ";url="
                    + ContributionPage.getLinker(contributionId)
                        .getRawUrl(getPageContext(), getPhetCycle()))));
    add(redirector);

    setTitle(
        StringUtils.messageFormat(
            PhetLocalizer.get().getString("contribution.comment.success", this),
            new Object[] {HtmlUtils.encode(contribution.getTitle())}));
  }
  public FarmingGraphPage(PageParameters parameters) throws Exception {
    final int farmStrategyID = parameters.getInt("farmStrategyID");
    farmStrategy = farmStrategyBO.getById(FarmStrategyId.farmStrategyId(farmStrategyID));
    add(new Label("strategyName", farmStrategy.getStrategyName()));
    add(
        ArmoryImage.createArmoryImage(
            (AuctioneerWebApp) getApplication(), "icon", farmStrategy.getIconItem()));
    setPageTitle("Farming - " + farmStrategy.getStrategyName());

    final PropertyModel<List<FarmStrategyLoot>> materialListModel =
        new PropertyModel<List<FarmStrategyLoot>>(this, "farmStrategy.loot");

    ListView<FarmStrategyLoot> listView =
        new ListView<FarmStrategyLoot>("lootList", materialListModel) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<FarmStrategyLoot> item) {

            final FarmStrategyLoot loot = item.getModelObject();
            PageParameters params = new PageParameters();
            params.add("itemID", String.valueOf(loot.getItem().getArmoryId().toInt()));
            final Link<String> lootLine =
                new BookmarkablePageLink<String>("lootLine", PriceWatchGraphPage.class, params);

            lootLine.add(new WowheadTooltip(loot.getItem().getArmoryId()));
            lootLine.add(
                ArmoryImage.createArmoryImage(
                    (AuctioneerWebApp) getApplication(), "icon", loot.getItem()));
            final String name = loot.getItemCount() + " x " + loot.getItem().getItemName();
            lootLine.add(new Label("name", name));
            item.add(lootLine);
          }
        };
    listView.setReuseItems(true);
    listView.setOutputMarkupId(true);
    add(listView);

    add(new Label("minProfit", goldToString(farmStrategy.getTotalSafeProfit())));
    add(new Label("medianProfit", goldToString(farmStrategy.getTotalProfit())));
  }
Example #3
0
  protected List<ProjectModel> getProjects(PageParameters params) {
    if (params == null) {
      return getProjectModels();
    }

    boolean hasParameter = false;
    String regex = WicketUtils.getRegEx(params);
    String team = WicketUtils.getTeam(params);
    int daysBack = params.getInt("db", 0);
    int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);

    List<ProjectModel> availableModels = getProjectModels();
    Set<ProjectModel> models = new HashSet<ProjectModel>();

    if (!StringUtils.isEmpty(regex)) {
      // filter the projects by the regex
      hasParameter = true;
      Pattern pattern = Pattern.compile(regex);
      for (ProjectModel model : availableModels) {
        if (pattern.matcher(model.name).find()) {
          models.add(model);
        }
      }
    }

    if (!StringUtils.isEmpty(team)) {
      // filter the projects by the specified teams
      hasParameter = true;
      List<String> teams = StringUtils.getStringsFromValue(team, ",");

      // need TeamModels first
      List<TeamModel> teamModels = new ArrayList<TeamModel>();
      for (String name : teams) {
        TeamModel teamModel = app().users().getTeamModel(name);
        if (teamModel != null) {
          teamModels.add(teamModel);
        }
      }

      // brute-force our way through finding the matching models
      for (ProjectModel projectModel : availableModels) {
        for (String repositoryName : projectModel.repositories) {
          for (TeamModel teamModel : teamModels) {
            if (teamModel.hasRepositoryPermission(repositoryName)) {
              models.add(projectModel);
            }
          }
        }
      }
    }

    if (!hasParameter) {
      models.addAll(availableModels);
    }

    // time-filter the list
    if (daysBack > 0) {
      if (maxDaysBack > 0 && daysBack > maxDaysBack) {
        daysBack = maxDaysBack;
      }
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);
      cal.add(Calendar.DATE, -1 * daysBack);
      Date threshold = cal.getTime();
      Set<ProjectModel> timeFiltered = new HashSet<ProjectModel>();
      for (ProjectModel model : models) {
        if (model.lastChange.after(threshold)) {
          timeFiltered.add(model);
        }
      }
      models = timeFiltered;
    }

    List<ProjectModel> list = new ArrayList<ProjectModel>(models);
    Collections.sort(list);
    return list;
  }