示例#1
1
  public Long getEventsPlayedCount(Sport sport) {

    if (ObjectUtils.isBlank(sport)) {
      return null;
    }

    ObjectType seasonalAthleteType = ObjectType.getInstance(sport.getSeasonalAthleteClass());

    Query<SeasonalAthlete> seasonalAthleteQuery =
        Query.from(SeasonalAthlete.class)
            .where("typeId = ? && athlete = ?", seasonalAthleteType, this);
    return Query.from(Event.class).where("seasonalAthletes = ?", seasonalAthleteQuery).count();
  }
          public HandlerResult findHandlerResult(
              HttpServletRequest request, HttpServletResponse response) {
            String servletPath = request.getServletPath();
            String[] pathParts = servletPath.split("/");
            String sportPath = pathParts.length > 2 ? pathParts[2] : null;

            HandlerResult result = new HandlerResult();
            Template template = Query.from(Template.class).where("name ~= ?", "Ranking").first();
            Ranking ranking = null;
            String sportAttribute = null;
            Sport sport = null;
            SportGender gender = null;

            if ("football".equals(sportPath)) {
              sportAttribute = "FOOTBALL-BOYS";
              sport = Sport.FOOTBALL;
              gender = SportGender.BOYS;
            } else if ("gbasketball".equals(sportPath)) {
              sportAttribute = "BASKETBALL-GIRLS";
              sport = Sport.BASKETBALL;
              gender = SportGender.GIRLS;
            } else if ("bbasketball".equals(sportPath)) {
              sportAttribute = "BASKETBALL-BOYS";
              sport = Sport.BASKETBALL;
              gender = SportGender.BOYS;
            } else if ("baseball".equals(sportPath)) {
              sportAttribute = "BASEBALL-BOYS";
              sport = Sport.BASEBALL;
              gender = SportGender.BOYS;
            } else if ("softball".equals(sportPath)) {
              sportAttribute = "SOFTBALL-GIRLS";
              sport = Sport.SOFTBALL;
              gender = SportGender.GIRLS;
            } else {
              sportAttribute = "FOOTBALL-BOYS";
              sport = Sport.FOOTBALL;
              gender = SportGender.BOYS;
            }

            ranking =
                Query.from(Ranking.class).where("sport = ? && gender = ?", sport, gender).first();
            result.page = template;
            result.content = ranking;
            request.setAttribute(MASSEY_SPORT_REQUEST_ATTRIBUTE, sportAttribute);

            result.stopHandlerChain = true;

            return result;
          }
  @Override
  protected void doWriteHtml() throws IOException {
    ObjectType selectedType = search.getSelectedType();

    sortField = updateSort();
    showSiteLabel =
        Query.from(CmsTool.class).first().isDisplaySiteInSearchResult()
            && Query.from(Site.class).hasMoreThan(0);

    if (selectedType != null) {
      showTypeLabel = selectedType.as(ToolUi.class).findDisplayTypes().size() != 1;

      if (ObjectType.getInstance(ObjectType.class).equals(selectedType)) {
        List<ObjectType> types = new ArrayList<ObjectType>();
        Predicate predicate = search.toQuery(page.getSite()).getPredicate();

        for (ObjectType t : Database.Static.getDefault().getEnvironment().getTypes()) {
          if (t.is(predicate)) {
            types.add(t);
          }
        }

        result = new PaginatedResult<ObjectType>(search.getOffset(), search.getLimit(), types);
      }

    } else {
      showTypeLabel = search.findValidTypes().size() != 1;
    }

    if (result == null) {
      result = search.toQuery(page.getSite()).select(search.getOffset(), search.getLimit());
    }

    writePaginationHtml(result);
    writeQueryRestrictionsHtml();
    writeFieldsHtml();
    writeSortsHtml();
    writeLimitsHtml(result);

    page.writeStart("div", "class", "searchResult-list");
    if (result.hasPages()) {
      writeItemsHtml(result.getItems());

    } else {
      writeEmptyHtml();
    }
    page.writeEnd();
  }
示例#4
0
  public SeasonalAthlete getMostRecentSeasonalAthlete() {

    return Query.from(SeasonalAthlete.class)
        .where("athlete = ? && year <= ?", this, StatsUtils.determineSeason(new Date()))
        .sortDescending("year")
        .first();
  }
  /**
   * Returns SearchResultSelections that were created by the specified {@link ToolUser}.
   *
   * @param user the {@link ToolUser} for which SearchResultSelections should be returned.
   * @return {@link SearchResultSelection}s that were created by the specified {@link ToolUser}.
   */
  public static List<SearchResultSelection> findOwnSelections(ToolUser user) {

    if (user == null) {
      return null;
    }

    return Query.from(SearchResultSelection.class).where("entities = ?", user).selectAll();
  }
示例#6
0
  public List<SeasonalAthlete> findSeasonalAthletes(Sport sport) {

    if (ObjectUtils.isBlank(sport)) {
      return null;
    }

    ObjectType seasonalAthleteType = ObjectType.getInstance(sport.getSeasonalAthleteClass());

    return Query.from(SeasonalAthlete.class)
        .where("typeId = ? && athlete = ?", seasonalAthleteType, this)
        .selectAll();
  }
  /**
   * Generates a {@link Query} for the items contained within this {@link SearchResultSelection}.
   * The returned Query is {@code .fromAll()} and includes visibility-restricted items.
   *
   * @return a {@link Query} for the items contained within this {@link SearchResultSelection}.
   */
  public Query<Object> createItemsQuery() {

    Set<UUID> itemIds = new HashSet<>();

    for (SearchResultSelectionItem item :
        Query.from(SearchResultSelectionItem.class).where("selectionId = ?", getId()).selectAll()) {

      itemIds.add(item.getItemId());
    }

    return Query.fromAll().where("_id = ?", itemIds);
  }
示例#8
0
 /**
  * Finds a seasonal athlete of the given {@code type}, such as {@link BaseballAthlete}, for the
  * given {@code year}, and {@code team} or if not found, creates one.
  */
 public <T extends SeasonalAthlete> T findOrCreateSeasonalAthlete(
     Class<T> type, int year, SeasonalTeam team) {
   Database database = getState().getDatabase();
   T athlete =
       database.readFirst(
           Query.from(type).where("athlete = ? and year = ? and team = ?", this, year, team));
   if (athlete == null) {
     athlete = (T) database.getEnvironment().getType(type).createObject(null);
     athlete.setAthlete(this);
     athlete.setYear(year);
     athlete.setTeam(team);
   }
   return athlete;
 }
  /**
   * Removes the Object with itemId from this SearchResultSelection.
   *
   * @param itemId the id of the Object to be removed. Cannot be {@code null}.
   */
  public boolean removeItem(UUID itemId) {

    if (itemId == null) {
      throw new IllegalArgumentException("itemId cannot be null!");
    }

    SearchResultSelectionItem item =
        Query.from(SearchResultSelectionItem.class)
            .where("selectionId = ?", getId())
            .and("itemId = ?", itemId)
            .first();

    if (item == null) {
      return false;
    }

    item.delete();
    return true;
  }
  /**
   * Returns SearchResultSelections that are accessible to the specified {@link ToolUser},
   * optionally excluding selections that were created by the user.
   *
   * @param user the {@link ToolUser} for which SearchResultSelections should be returned.
   * @param excludeOwn excludes selections created by the specified {@link ToolUser} if true.
   * @return accessible {@link SearchResultSelection}s for the specified {@link ToolUser}.
   */
  public static List<SearchResultSelection> findAccessibleSelections(
      ToolUser user, boolean excludeOwn) {

    if (user == null) {
      return null;
    }

    Query<SearchResultSelection> query = Query.from(SearchResultSelection.class);

    if (user.getRole() == null) {
      query.where("entities != missing");
    } else {
      query.where("entities = ?", user.getRole());
    }

    if (excludeOwn) {
      query.and("entities != ?", user);
    } else {
      query.or("entities = ?", user);
    }

    return query.selectAll();
  }
  @Override
  public String getLabel() {
    String name = getName();
    StringBuilder label = new StringBuilder();

    if (ObjectUtils.isBlank(name)) {
      Date triggerDate = getTriggerDate();

      label.append(triggerDate != null ? triggerDate.toString() : getId().toString());

    } else {
      label.append(name);
    }

    long draftCount = Query.from(Draft.class).where("schedule = ?", this).count();

    if (draftCount > 1) {
      label.append(" (");
      label.append(draftCount);
      label.append(" items)");
    }

    return label.toString();
  }
示例#12
0
 private static List<Plugin> getAllPlugins(Database database) {
   return Query.from(Plugin.class).sortAscending("displayName").using(database).selectAll();
 }
示例#13
0
  public SeasonalAthlete getCurrentSeasonalAthlete() {

    return Query.from(SeasonalAthlete.class)
        .where("athlete = ? && year = ?", this, StatsUtils.determineSeason(new Date()))
        .first();
  }
示例#14
0
  @Override
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    boolean doFilterChain = true;
    Content content = null;

    if (servletRequest instanceof HttpServletRequest) {
      HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
      HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
      String servletPath = httpServletRequest.getServletPath();
      Page page = PageFilter.getPage(httpServletRequest);
      UrlKeyPageModification.AppPageKeys appPageKey = null;
      HandlerResult handlerResult = null;
      PageInfo pageInfo = new PageInfo();

      if (null == servletPath) {
      } else if (servletPath.startsWith("/school/")) {
        // use regular processing if the request yields a page
        // otherwise, if no page would be returned, use this code
        if (null == page) {
          String[] pathParts = servletPath.split("/");
          String keyInPath = pathParts.length > 2 ? pathParts[2] : null;
          String action = pathParts.length > 3 ? pathParts[3] : null;
          School school = null;

          if (!isBlank(keyInPath)) {
            if (!isBlank(keyInPath)) {
              Query<School> schoolQuery = School.findSchoolByKeyQuery(keyInPath.toLowerCase());
              school = getDisplayQuery(schoolQuery).first();
            }

            content = school;

            if (!isBlank(content)) {
              /*-- get the appPageKey based on the action --*/
              if (isBlank(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.School;
              } else if (FOLLOWERS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.SchoolFollowers;
              } else if (NEWS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.SchoolNews;
              } else if (MEDIA_PATH.equals(action)) {
                appPageKey = AppPageKeys.SchoolMedia;
                UrlKeyPageModification.AppPageKeys videoPageKey = AppPageKeys.SchoolVideo;
                UrlKeyPageModification.AppPageKeys galleryPageKey = AppPageKeys.SchoolGallery;

                String assetId = null;
                String galleryId = null;

                if (pathParts.length > 4) {
                  galleryId = pathParts[4];
                  servletRequest.setAttribute(DynamicMediaGallery.GALLERY_ID_ATTRIBUTE, galleryId);
                  appPageKey = galleryPageKey;

                  DynamicMediaGallery gallery =
                      Query.findUnique(DynamicMediaGallery.class, "id", galleryId);
                  if (!(gallery instanceof DateRangeGallery || gallery instanceof EventGallery)) {
                    page = null;
                    appPageKey = null;
                  }

                  if (null != gallery) {
                    servletRequest.setAttribute(GALLERY_ATTRIBUTE, gallery);
                  }

                  if (gallery instanceof VideoGallery) {
                    appPageKey = videoPageKey;
                  }

                  if (pathParts.length > 5) {
                    assetId = pathParts[5];

                    servletRequest.setAttribute(
                        DynamicMediaGallery.GALLERY_ASSET_ID_ATTRIBUTE, assetId);
                  }
                }
              } else if (SCORES_SCHEDULES_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.SchoolScoresSchedules;
              } else {
                // possible a team request
                String sportName = action;
                String levelName = pathParts.length > 4 ? pathParts[4] : null;
                String genderName = pathParts.length > 5 ? pathParts[5] : null;
                page = AppPageKeys.School.getPage();

                if ("All".equals(action) && "All".equals(levelName) && "All".equals(genderName)) {
                  page = AppPageKeys.School.getPage();
                } else if (!isBlank(sportName) && !isBlank(levelName) && !isBlank(genderName)) {
                  try {
                    Sport sport = Sport.valueOf(sportName.toUpperCase());
                    SportLevel level = SportLevel.valueOf(levelName.toUpperCase());
                    SportGender gender = SportGender.valueOf(genderName.toUpperCase());

                    Query<Team> teamQuery =
                        Query.from(Team.class)
                            .where(
                                "sport = ? && gender = ? && level = ? && school = ?",
                                sport,
                                gender,
                                level,
                                school);
                    getDisplayQuery(teamQuery);

                    Team team = teamQuery.first();

                    if (null != team) {
                      content = team;
                      page = AppPageKeys.Team.getPage();
                    }
                  } catch (Exception e) {
                    logger.debug("failed to get team from school request: " + servletPath, e);
                  }
                }
              }
            }
          }
        }
      } else if (servletPath.startsWith("/team/")) {
        // use regular processing if the request yields a page
        // otherwise, if no page would be returned, use this code
        if (null == page) {
          String[] pathParts = servletPath.split("/");
          String schoolNaturalKey = pathParts.length > 2 ? pathParts[2] : null;
          String teamDiscriminator = pathParts.length > 3 ? pathParts[3] : null;
          String action = pathParts.length > 4 ? pathParts[4] : null;
          Team team = null;
          String teamUrlNaturalKey = null;

          if (!isBlank(schoolNaturalKey) && !isBlank(teamDiscriminator)) {
            teamUrlNaturalKey = schoolNaturalKey + "/" + teamDiscriminator;

            Query<Team> teamQuery =
                Query.from(Team.class).where("naturalKey = ?", teamUrlNaturalKey.toLowerCase());

            getDisplayQuery(teamQuery);

            content = team = teamQuery.first();

            if (!isBlank(content)) {
              /*-- get the appPageKey based on the action --*/
              if (isBlank(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.Team;
              } else if (FOLLOWERS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.TeamFollowers;
              } else if (NEWS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.TeamNews;
              } else if (MEDIA_PATH.equals(action)) {
                appPageKey = AppPageKeys.TeamMedia;
                UrlKeyPageModification.AppPageKeys videoPageKey = AppPageKeys.TeamVideo;
                UrlKeyPageModification.AppPageKeys galleryPageKey = AppPageKeys.TeamGallery;

                String assetId = null;
                String galleryId = null;

                if (pathParts.length > 5) {
                  galleryId = pathParts[5];
                  servletRequest.setAttribute(DynamicMediaGallery.GALLERY_ID_ATTRIBUTE, galleryId);
                  appPageKey = galleryPageKey;

                  DynamicMediaGallery gallery =
                      Query.findUnique(DynamicMediaGallery.class, "id", galleryId);
                  if (!(gallery instanceof DateRangeGallery || gallery instanceof EventGallery)) {
                    page = null;
                    appPageKey = null;
                  }

                  if (null != gallery) {
                    servletRequest.setAttribute(GALLERY_ATTRIBUTE, gallery);
                  }

                  if (gallery instanceof VideoGallery) {
                    appPageKey = videoPageKey;
                  }

                  if (pathParts.length > 6) {
                    assetId = pathParts[6];

                    servletRequest.setAttribute(
                        DynamicMediaGallery.GALLERY_ASSET_ID_ATTRIBUTE, assetId);
                  }
                }
              } else if (SCORES_SCHEDULES_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.TeamScoresSchedules;
              } else if (STATS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.TeamStats;
              } else if ("roster".equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.TeamRoster;
              }
            }
          }
        }
      } else if (servletPath.startsWith("/athlete/")) {
        // use regular processing if the request yields a page
        // otherwise, if no page would be returned, use this code
        if (null == page) {
          String[] pathParts = servletPath.split("/");
          String schoolNaturalKey = pathParts.length > 2 ? pathParts[2] : null;
          String fullName = pathParts.length > 3 ? pathParts[3] : null;
          String id = pathParts.length > 4 ? pathParts[4] : null;
          String action = pathParts.length > 5 ? pathParts[5] : null;
          Athlete athlete = null;
          String athleteUrlNaturalKey = null;

          if (!isBlank(schoolNaturalKey) && !isBlank(fullName)) {
            athleteUrlNaturalKey = schoolNaturalKey + "/" + fullName;

            Query<Athlete> athleteQuery = Query.from(Athlete.class).where("id = ?", id);

            getDisplayQuery(athleteQuery);

            content = athlete = athleteQuery.first();
            if (!isBlank(content)) {
              /*-- get the appPageKey based on the action --*/
              if (isBlank(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.Athlete;
              } else if (FOLLOWERS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.AthleteFollowers;
              } else if (NEWS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.AthleteNews;
              } else if (MEDIA_PATH.equals(action)) {
                appPageKey = AppPageKeys.AthleteMedia;
                UrlKeyPageModification.AppPageKeys videoPageKey = AppPageKeys.AthleteVideo;
                UrlKeyPageModification.AppPageKeys galleryPageKey = AppPageKeys.AthleteGallery;

                String assetId = null;
                String galleryId = null;

                if (pathParts.length > 6) {
                  galleryId = pathParts[6];
                  servletRequest.setAttribute(DynamicMediaGallery.GALLERY_ID_ATTRIBUTE, galleryId);
                  appPageKey = galleryPageKey;

                  DynamicMediaGallery gallery =
                      Query.findUnique(DynamicMediaGallery.class, "id", galleryId);
                  if (!(gallery instanceof DateRangeGallery || gallery instanceof EventGallery)) {
                    page = null;
                    appPageKey = null;
                  }

                  if (null != gallery) {
                    servletRequest.setAttribute(GALLERY_ATTRIBUTE, gallery);
                  }

                  if (gallery instanceof VideoGallery) {
                    appPageKey = videoPageKey;
                  }

                  if (pathParts.length > 7) {
                    assetId = pathParts[7];

                    servletRequest.setAttribute(
                        DynamicMediaGallery.GALLERY_ASSET_ID_ATTRIBUTE, assetId);
                  }
                }
              } else if (SCORES_SCHEDULES_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.AthleteScoresSchedules;
              } else if (STATS_PATH.equals(action)) {
                appPageKey = UrlKeyPageModification.AppPageKeys.AthleteStats;
              }
            }
          }
        }
      } else if (servletPath.startsWith("/user/")) {
        // use regular processing if the request yields a page
        // otherwise, if no page would be returned, use this code
        if (null == page) {
          String[] pathParts = servletPath.split("/");
          String id = pathParts.length > 2 ? pathParts[2] : null;
          String action = pathParts.length > 3 ? pathParts[3] : null;
          User user = null;

          if (!isBlank(id)) {
            content = user = User.findUserByKey(id);

            /*-- get the appPageKey based on the action --*/
            if (isBlank(action) && content != null) {
              appPageKey = UrlKeyPageModification.AppPageKeys.User;
            } else if (FOLLOWERS_PATH.equals(action)) {
              appPageKey = UrlKeyPageModification.AppPageKeys.UserFollowers;
            } else if (NEWS_PATH.equals(action)) {
              appPageKey = UrlKeyPageModification.AppPageKeys.UserNews;
            } else if (SCORES_SCHEDULES_PATH.equals(action)) {
              appPageKey = AppPageKeys.UserScoresSchedules;
            } else if (STATS_PATH.equals(action)) {
              appPageKey = AppPageKeys.UserStats;
            } else if (MEDIA_PATH.equals(action)) {
              appPageKey = AppPageKeys.UserMedia;
              UrlKeyPageModification.AppPageKeys videoPageKey = AppPageKeys.UserVideo;
              UrlKeyPageModification.AppPageKeys galleryPageKey = AppPageKeys.UserGallery;

              String assetId = null;
              String galleryId = null;

              if (pathParts.length > 4) {
                galleryId = pathParts[4];
                servletRequest.setAttribute(DynamicMediaGallery.GALLERY_ID_ATTRIBUTE, galleryId);
                appPageKey = galleryPageKey;

                DynamicMediaGallery gallery =
                    Query.findUnique(DynamicMediaGallery.class, "id", galleryId);
                if (!(gallery instanceof DateRangeGallery || gallery instanceof EventGallery)) {
                  page = null;
                  appPageKey = null;
                }

                if (null != gallery) {
                  servletRequest.setAttribute(GALLERY_ATTRIBUTE, gallery);
                }

                if (gallery instanceof VideoGallery) {
                  appPageKey = videoPageKey;
                }

                if (pathParts.length > 5) {
                  assetId = pathParts[5];

                  servletRequest.setAttribute(
                      DynamicMediaGallery.GALLERY_ASSET_ID_ATTRIBUTE, assetId);
                }
              }
            } else if ("following".equals(action)) {
              appPageKey = UrlKeyPageModification.AppPageKeys.UserFollowing;
            } else if ("highlights".equals(action)) {
              appPageKey = UrlKeyPageModification.AppPageKeys.UserHighlights;
            }
          }
        }
      } else if (servletPath.startsWith("/game/")
          || servletPath.startsWith("/meet/")
          || servletPath.startsWith("/event/")) {
        // use regular processing if the request yields a page
        // otherwise, if no page would be returned, use this code
        if (null == page) {
          String[] pathParts = servletPath.split("/");
          String schoolNaturalKey = pathParts.length > 2 ? pathParts[2] : null;
          String teamDiscriminator = pathParts.length > 3 ? pathParts[3] : null;
          String eventKey = pathParts.length > 4 ? pathParts[4] : null;
          String action = pathParts.length > 5 ? pathParts[5] : null;
          Event event = null;

          if (!isBlank(eventKey)) {
            content = event = getDisplayQuery(Event.findEventByKeyQuery(eventKey)).first();

            String teamUrlNaturalKey = schoolNaturalKey + "/" + teamDiscriminator;
            Query<Team> teamQuery =
                Query.from(Team.class).where("naturalKey = ?", teamUrlNaturalKey.toLowerCase());

            getDisplayQuery(teamQuery);
            Team team = teamQuery.first();

            Query<School> schoolQuery =
                Query.from(School.class).where("naturalKey = ?", schoolNaturalKey.toLowerCase());

            getDisplayQuery(schoolQuery);
            School contextSchool = schoolQuery.first();

            httpServletRequest.setAttribute(HssUtils.SCHOOL_CONTEXT_ATTRIBUTE, contextSchool);

            if (content != null) {
              /*-- get the appPageKey based on the action --*/
              if (isBlank(action)) {

                if (event instanceof Game) {
                  appPageKey = UrlKeyPageModification.AppPageKeys.Game;

                } else if (event instanceof Meet) {
                  appPageKey = UrlKeyPageModification.AppPageKeys.Meet;
                }

                if (null != appPageKey) page = appPageKey.getPage();

                if (isBlank(page)) {
                  appPageKey = UrlKeyPageModification.AppPageKeys.Event;
                }
              } else if (MEDIA_PATH.equals(action)) {
                appPageKey = AppPageKeys.EventMedia;
                UrlKeyPageModification.AppPageKeys videoPageKey = AppPageKeys.EventVideo;
                UrlKeyPageModification.AppPageKeys galleryPageKey = AppPageKeys.EventGallery;

                String assetId = null;
                String galleryId = null;
                if (event instanceof Game) {
                  appPageKey = AppPageKeys.GameMedia;
                  galleryPageKey = UrlKeyPageModification.AppPageKeys.GameGallery;
                  videoPageKey = UrlKeyPageModification.AppPageKeys.GameVideo;
                } else if (event instanceof Meet) {
                  appPageKey = AppPageKeys.MeetMedia;
                  galleryPageKey = UrlKeyPageModification.AppPageKeys.MeetGallery;
                  videoPageKey = UrlKeyPageModification.AppPageKeys.MeetVideo;
                }

                if (pathParts.length > 6) {
                  galleryId = pathParts[6];
                  servletRequest.setAttribute(DynamicMediaGallery.GALLERY_ID_ATTRIBUTE, galleryId);
                  appPageKey = galleryPageKey;

                  if (null != appPageKey) {
                    page = appPageKey.getPage();
                  }

                  if (isBlank(page)) {
                    appPageKey = UrlKeyPageModification.AppPageKeys.EventGallery;
                  }

                  DynamicMediaGallery gallery =
                      Query.findUnique(DynamicMediaGallery.class, "id", galleryId);
                  if (!(gallery instanceof DateRangeGallery || gallery instanceof EventGallery)) {
                    page = null;
                    appPageKey = null;
                  }

                  if (null != gallery) {
                    servletRequest.setAttribute(GALLERY_ATTRIBUTE, gallery);
                  }

                  if (gallery instanceof VideoGallery) {
                    appPageKey = videoPageKey;
                  }

                  if (pathParts.length > 7) {
                    assetId = pathParts[7];

                    servletRequest.setAttribute(
                        DynamicMediaGallery.GALLERY_ASSET_ID_ATTRIBUTE, assetId);
                  }
                }
              }
            }
          }
        }
      }

      if (null == page) { // use a handler
        try {
          for (Handler handler : handlers) {
            if (null == handler) continue;

            if (handler.matches(httpServletRequest)) {
              handlerResult = handler.findHandlerResult(httpServletRequest, httpServletResponse);

              if (null == handlerResult) continue;

              if (null == page || null != handlerResult.page) page = handlerResult.page;

              content = handlerResult.content;

              if (null != handlerResult.pageInfo) pageInfo = handlerResult.pageInfo;

              if (handlerResult.stopHandlerChain) {
                doFilterChain = !handlerResult.stopFilterChain;
                break;
              }
            }
          }
        } catch (Exception e) {
          logger.debug("failed in Handler", e);
        }
      }

      if (null != appPageKey && page == null) {
        page = appPageKey.getPage();
      }

      if (null != page) {
        PageFilter.setPage(httpServletRequest, page);
        servletRequest.setAttribute(HssUtils.PAGE_ATTRIBUTE, page);

        if (null != content) {
          servletRequest.setAttribute(
              UrlKeyPageModification.ID_FROM_NATURAL_KEY_ATTR, content.getId().toString());
          PageFilter.setMainObject(httpServletRequest, content);
        }
      }

      if (true) {
        httpServletRequest.setAttribute(
            PAGE_INFO_ATTRIBUTE, pageInfo.updateFromRequest(httpServletRequest));
      }
    }

    if (doFilterChain) {
      filterChain.doFilter(servletRequest, servletResponse);
      return;
    }
  }
示例#15
0
          public HandlerResult findHandlerResult(
              HttpServletRequest request, HttpServletResponse response) {
            String servletPath = request.getServletPath();
            String[] pathParts = servletPath.split("/");
            String UsStateOrSportName = pathParts.length > 2 ? pathParts[2] : null;

            int sportPathIndex = 2;
            String sportName = pathParts.length > sportPathIndex ? pathParts[sportPathIndex] : null;
            int pathIndex = 2;

            String action = null;
            String usState = null;
            if ("state".equals(sportName)) {
              action = sportName;
              sportPathIndex++;
              usState = pathParts.length > sportPathIndex ? pathParts[sportPathIndex] : null;

              USState stateKey = null;
              if (!isBlank(usState)) {
                USState usStateEnum = null;
                try {
                  usStateEnum = USState.valueOf(usState.replaceAll(" ", "_").toUpperCase());
                } catch (Exception e) {
                  logger.debug("failed to get USState for " + usState, e);
                }
                if (isBlank(usStateEnum)) usStateEnum = USState.getEnumValueByString(usState);

                if (isBlank(usStateEnum)) usStateEnum = USState.getEnumValueByAbbreviation(usState);

                if (!isBlank(usStateEnum)) {
                  request.setAttribute(US_STATE_REQUEST_ATTRIBUTE, usStateEnum.getAbbreviation());
                }
              }

              sportPathIndex++;
              sportName = pathParts.length > sportPathIndex ? pathParts[sportPathIndex] : null;
            } else if ("playoffs".equals(sportName)) {
              action = sportName;
              sportPathIndex++;

              sportName = pathParts.length > sportPathIndex ? pathParts[sportPathIndex] : null;
            } else if ("ratings".equals(sportName)) {
              action = sportName;
              sportPathIndex++;

              sportName = pathParts.length > sportPathIndex ? pathParts[sportPathIndex] : null;
            }

            Sport sport = Sport.FOOTBALL;

            try {
              if (!isBlank(sportName)) sport = Sport.valueOf(sportName.toUpperCase());
            } catch (Exception e) {
              logger.debug("failed to get sport", e);
            }

            String levelName =
                pathParts.length > (sportPathIndex + 1) ? pathParts[(sportPathIndex + 1)] : null;
            String genderName =
                pathParts.length > (sportPathIndex + 2) ? pathParts[(sportPathIndex + 2)] : null;
            String seasonNumber =
                pathParts.length > (sportPathIndex + 3) ? pathParts[(sportPathIndex + 3)] : null;
            String schoolName =
                pathParts.length > (sportPathIndex + 4) ? pathParts[(sportPathIndex + 4)] : null;

            HandlerResult result = new HandlerResult();

            String sportAttribute = null;

            SportGender gender = SportGender.BOYS;
            if (!isBlank(genderName)) {
              gender = SportGender.valueOf(genderName.toUpperCase());
              sportAttribute = sportName.toUpperCase() + "-" + genderName.toUpperCase();
            }

            Content content = null;
            Page page = null;

            if (!isBlank(schoolName)) {
              School school = School.findSchoolByKey(schoolName);
              if (null != school) {

                Query<Team> teamQuery =
                    Query.from(Team.class)
                        .where(
                            "sport = ? && gender = ? && level = ? && school = ?",
                            sport,
                            gender,
                            SportLevel.VARSITY,
                            school);
                getDisplayQuery(teamQuery);

                Team team = teamQuery.first();
                if (null == team) {
                  content = school;
                  page = AppPageKeys.School.getPage();
                } else {
                  content = team;
                  page = AppPageKeys.Team.getPage();
                }
              }

            } else {
              Ranking ranking =
                  Query.from(Ranking.class).where("sport = ? && gender = ?", sport, gender).first();
              if (null == ranking) {
                ranking = Query.from(Ranking.class).first();
              }

              Template template = Query.from(Template.class).where("name ~= ?", "Ranking").first();

              content = ranking;
              page = template;
            }

            result.page = page;
            result.content = content;
            request.setAttribute(MASSEY_SPORT_REQUEST_ATTRIBUTE, sportAttribute);

            result.stopHandlerChain = true;

            return result;
          }
示例#16
0
 public static Athlete findAthleteByKey(String key) {
   return Query.from(Athlete.class)
       .where("id = ? || legacyId = ? || naturalKey = ?", key, key, key.toLowerCase())
       .first();
 }
示例#17
0
 public List<SeasonalAthlete> getAllSeasonalAthletes() {
   return Query.from(SeasonalAthlete.class).where("athlete = ?", this).selectAll();
 }
示例#18
0
  @Override
  protected void doService(ToolPageContext page) throws IOException, ServletException {
    ToolUser user = page.getUser();
    Collection<String> includeFields = Arrays.asList("returnToDashboardOnSave");
    Object object = Query.from(Object.class).where("_id = ?", page.param(UUID.class, "id")).first();
    State state = State.getInstance(object);
    ContentLock contentLock = null;

    if (object != null) {
      contentLock = ContentLock.Static.lock(object, null, user);
    }

    if (page.isFormPost()) {
      if (page.param(String.class, "action-edits") != null) {
        if (state != null) {
          Date newPublishDate = page.param(Date.class, "publishDate");

          if (newPublishDate != null) {
            Content.ObjectModification contentData = state.as(Content.ObjectModification.class);
            DateTimeZone timeZone = page.getUserDateTimeZone();
            newPublishDate =
                new Date(
                    DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
                        .withZone(timeZone)
                        .parseMillis(new DateTime(newPublishDate).toString("yyyy-MM-dd HH:mm:ss")));

            contentData.setPublishUser(page.getUser());
            contentData.setPublishDate(newPublishDate);
            state.save();
          }
        }

      } else if (page.param(String.class, "action-unlock") != null) {
        contentLock.delete();

        page.writeStart("script", "type", "text/javascript");
        page.writeRaw("window.location.reload();");
        page.writeEnd();

      } else if (page.param(String.class, "action-settings") != null) {
        try {
          page.include("/WEB-INF/objectPost.jsp", "object", user, "includeFields", includeFields);
          user.save();

        } catch (Exception error) {
          page.getErrors().add(error);
        }
      }
    }

    String returnUrl = page.param(String.class, "returnUrl");

    page.writeHeader();
    page.writeStart("style", "type", "text/css");
    page.writeCss(".cms-contentTools th", "width", "25%;");
    page.writeEnd();

    page.writeStart("div", "class", "widget cms-contentTools");
    page.writeStart("h1", "class", "icon icon-wrench");
    page.writeHtml("Tools");
    page.writeEnd();

    page.writeStart("div", "class", "tabbed");
    page.writeStart("div", "class", "fixedScrollable", "data-tab", "For Editors");
    if (object != null) {
      Content.ObjectModification contentData = state.as(Content.ObjectModification.class);
      Date publishDate = contentData.getPublishDate();
      ToolUser publishUser = contentData.getPublishUser();
      Date updateDate = contentData.getUpdateDate();
      ToolUser updateUser = contentData.getUpdateUser();

      page.writeStart("table", "class", "table-striped");
      page.writeStart("tbody");
      if (publishDate != null || publishUser != null) {
        page.writeStart("tr");
        page.writeStart("th");
        page.writeHtml("Published");
        page.writeEnd();

        page.writeStart("td");
        if (publishDate != null) {
          page.writeHtml(page.formatUserDateTime(publishDate));
        }
        page.writeEnd();

        page.writeStart("td");
        if (publishUser != null) {
          page.writeObjectLabel(publishUser);
        }
        page.writeEnd();
        page.writeEnd();
      }

      if (updateDate != null || updateUser != null) {
        page.writeStart("tr");
        page.writeStart("th");
        page.writeHtml("Last Updated");
        page.writeEnd();

        page.writeStart("td");
        if (updateDate != null) {
          page.writeHtml(page.formatUserDateTime(updateDate));
        }
        page.writeEnd();

        page.writeStart("td");
        if (updateUser != null) {
          page.writeObjectLabel(updateUser);
        }
        page.writeEnd();
        page.writeEnd();
      }
      page.writeEnd();
      page.writeEnd();

      page.writeStart("h2");
      page.writeHtml("Advanced Edits");
      page.writeEnd();

      if (page.isFormPost() && page.param(String.class, "action-edits") != null) {
        if (page.getErrors().isEmpty()) {
          page.writeStart("div", "class", "message message-success");
          page.writeHtml("Advanced edits successfully saved.");
          page.writeEnd();

        } else {
          page.include("/WEB-INF/errors.jsp");
        }
      }

      page.writeStart("form", "method", "post", "action", page.url(""));

      page.writeStart("div", "class", "inputContainer");
      page.writeStart("div", "class", "inputLabel");
      page.writeStart("label", "for", page.createId());
      page.writeHtml("New Publish Date");
      page.writeEnd();
      page.writeEnd();

      page.writeStart("div", "class", "inputSmall");
      page.writeElement(
          "input",
          "type",
          "text",
          "class",
          "date",
          "name",
          "publishDate",
          "value",
          page.formatUserDateTime(publishDate));
      page.writeEnd();
      page.writeEnd();

      page.writeStart("div", "class", "actions");
      page.writeStart(
          "button", "class", "icon icon-action-save", "name", "action-edits", "value", true);
      page.writeHtml("Save");
      page.writeEnd();
      page.writeEnd();
      page.writeEnd();

      if (!user.equals(contentLock.getOwner())) {
        page.writeStart("h2");
        page.writeHtml("Content Lock");
        page.writeEnd();

        page.writeStart("div", "class", "message message-warning");
        page.writeStart("p");
        page.writeHtml("Locked by ");
        page.writeObjectLabel(contentLock.getOwner());
        page.writeHtml(" since ");
        page.writeHtml(page.formatUserDateTime(contentLock.getCreateDate()));
        page.writeHtml(".");
        page.writeEnd();
        page.writeEnd();

        page.writeStart("form", "method", "post", "action", page.url(""));
        page.writeStart("div", "class", "actions");
        page.writeStart(
            "button", "class", "icon icon-unlock", "name", "action-unlock", "value", true);
        page.writeHtml("Unlock");
        page.writeEnd();
        page.writeEnd();
        page.writeEnd();
      }
    }

    page.writeStart("h2");
    page.writeHtml("Settings");
    page.writeEnd();

    if (page.isFormPost() && page.param(String.class, "action-settings") != null) {
      if (page.getErrors().isEmpty()) {
        page.writeStart("div", "class", "message message-success");
        page.writeHtml("Settings successfully saved.");
        page.writeEnd();

      } else {
        page.include("/WEB-INF/errors.jsp");
      }
    }

    page.writeStart("form", "method", "post", "action", page.url(""), "style", "margin-bottom:0;");
    page.include("/WEB-INF/objectForm.jsp", "object", user, "includeFields", includeFields);

    page.writeStart("div", "class", "actions");
    page.writeStart(
        "button", "class", "icon icon-action-save", "name", "action-settings", "value", true);
    page.writeHtml("Save");
    page.writeEnd();
    page.writeEnd();
    page.writeEnd();
    page.writeEnd();

    page.writeStart("div", "class", "fixedScrollable", "data-tab", "For Developers");
    page.writeStart("ul");
    if (object != null) {
      page.writeStart("li");
      page.writeStart("a", "target", "_blank", "href", page.objectUrl("/contentRaw", object));
      page.writeHtml("View Raw Data");
      page.writeEnd();
      page.writeEnd();
    }

    if (!ObjectUtils.isBlank(returnUrl)) {
      page.writeStart("li");
      if (ObjectUtils.to(
          boolean.class, StringUtils.getQueryParameterValue(returnUrl, "deprecated"))) {
        page.writeStart(
            "a",
            "target",
            "_top",
            "href",
            StringUtils.addQueryParameters(returnUrl, "deprecated", null));
        page.writeHtml("Hide Deprecated Fields");
        page.writeEnd();

      } else {
        page.writeStart(
            "a",
            "target",
            "_top",
            "href",
            StringUtils.addQueryParameters(returnUrl, "deprecated", true));
        page.writeHtml("Show Deprecated Fields");
        page.writeEnd();
      }
      page.writeEnd();
    }
    page.writeEnd();

    if (object != null) {
      ObjectType type = state.getType();

      page.writeStart("table", "class", "table-striped");
      page.writeStart("tbody");
      if (type != null) {
        Class<?> objectClass = type.getObjectClass();

        if (objectClass != null) {
          page.writeStart("tr");
          page.writeStart("th");
          page.writeStart("label", "for", page.createId());
          page.writeHtml("Class");
          page.writeEnd();
          page.writeEnd();

          page.writeStart("td");
          page.writeJavaClassLink(objectClass);
          page.writeEnd();
          page.writeEnd();
        }
      }

      page.writeStart("tr");
      page.writeStart("th");
      page.writeStart("label", "for", page.createId());
      page.writeHtml("ID");
      page.writeEnd();
      page.writeEnd();

      page.writeStart("td");
      page.writeElement(
          "input",
          "type",
          "text",
          "id",
          page.getId(),
          "class",
          "code",
          "value",
          state.getId(),
          "readonly",
          "readonly",
          "style",
          "width:100%;",
          "onclick",
          "this.select();");
      page.writeEnd();
      page.writeEnd();

      page.writeStart("tr");
      page.writeStart("th");
      page.writeStart("label", "for", page.createId());
      page.writeHtml("URL");
      page.writeEnd();
      page.writeEnd();

      page.writeStart("td");
      page.writeElement(
          "input",
          "type",
          "text",
          "id",
          page.getId(),
          "value",
          JspUtils.getAbsoluteUrl(
              page.getRequest(), page.cmsUrl("/content/edit.jsp", "id", state.getId())),
          "readonly",
          "readonly",
          "style",
          "width:100%;",
          "onclick",
          "this.select();");
      page.writeEnd();
      page.writeEnd();
      page.writeEnd();
      page.writeEnd();
    }

    if (object != null) {
      ObjectType type = state.getType();

      if (type != null) {
        if (!ObjectUtils.isBlank(type.as(Renderer.TypeModification.class).getEmbedPath())) {
          String permalink = state.as(Directory.ObjectModification.class).getPermalink();

          if (!ObjectUtils.isBlank(permalink)) {
            String siteUrl = Application.Static.getInstance(CmsTool.class).getDefaultSiteUrl();
            StringBuilder embedCode = new StringBuilder();

            embedCode.append("<script type=\"text/javascript\" src=\"");
            embedCode.append(
                StringUtils.addQueryParameters(
                    StringUtils.removeEnd(siteUrl, "/") + permalink,
                    "_embed",
                    true,
                    "_format",
                    "js"));
            embedCode.append("\"></script>");

            page.writeHtml("Embed Code:");
            page.writeElement("br");
            page.writeStart(
                "textarea",
                "class",
                "code",
                "data-expandable-class",
                "code",
                "readonly",
                "readonly",
                "onclick",
                "this.select();");
            page.writeHtml(embedCode);
            page.writeEnd();
          }
        }

        String defaultPath = type.as(Renderer.TypeModification.class).getPath();
        Map<String, String> paths = type.as(Renderer.TypeModification.class).getPaths();

        if (!ObjectUtils.isBlank(defaultPath) || !ObjectUtils.isBlank(paths)) {
          page.writeStart("h2");
          page.writeHtml("Renderers");
          page.writeEnd();

          page.writeStart("table", "class", "table-striped");
          page.writeStart("tbody");
          if (!ObjectUtils.isBlank(defaultPath)) {
            page.writeStart("tr");
            page.writeStart("th");
            page.writeStart("code");
            page.writeHtml("Default");
            page.writeEnd();
            page.writeEnd();

            page.writeStart("td");
            page.writeStart("code");
            page.writeStart(
                "a",
                "target",
                "_blank",
                "href",
                DebugFilter.Static.getServletPath(
                    page.getRequest(),
                    "code",
                    "action",
                    "edit",
                    "type",
                    "JSP",
                    "servletPath",
                    defaultPath));
            page.writeHtml(defaultPath);
            page.writeEnd();
            page.writeEnd();
            page.writeEnd();
            page.writeEnd();
          }

          for (Map.Entry<String, String> entry : paths.entrySet()) {
            page.writeStart("tr");
            page.writeStart("th");
            page.writeStart("code");
            page.writeHtml(entry.getKey());
            page.writeEnd();
            page.writeEnd();

            page.writeStart("td");
            page.writeStart("code");
            page.writeStart(
                "a",
                "target",
                "_blank",
                "href",
                DebugFilter.Static.getServletPath(
                    page.getRequest(),
                    "code",
                    "action",
                    "edit",
                    "type",
                    "JSP",
                    "servletPath",
                    entry.getValue()));
            page.writeHtml(entry.getValue());
            page.writeEnd();
            page.writeEnd();
            page.writeEnd();
            page.writeEnd();
          }
          page.writeEnd();
          page.writeEnd();
        }

        Class<?> objectClass = type.getObjectClass();

        if (objectClass != null) {
          Static.writeJavaAnnotationDescriptions(page, objectClass);
        }
      }
    }
    page.writeEnd();
    page.writeEnd();
    page.writeEnd();
    page.writeFooter();
  }
  @Override
  public void doService(ToolPageContext page) throws IOException, ServletException {
    ToolUser user = page.getUser();
    Dashboard dashboard = user.getDashboard();
    String dashboardId = "user";

    if (dashboard == null) {
      ToolRole role = user.getRole();

      if (role != null) {
        dashboard = role.getDashboard();
        dashboardId = "role";
      }
    }

    if (dashboard == null) {
      dashboard = page.getCmsTool().getDefaultDashboard();
      dashboardId = "tool";
    }

    if (dashboard == null) {
      dashboard = Dashboard.createDefaultDashboard();
      dashboardId = "default";
    }

    page.writeHeader();
    page.writeStart("div", "class", "dashboard-columns");
    List<DashboardColumn> columns = dashboard.getColumns();
    double totalWidth = 0;

    for (DashboardColumn column : columns) {
      double width = column.getWidth();
      totalWidth += width > 0 ? width : 1;
    }

    CmsTool cms = Query.from(CmsTool.class).first();
    Set<String> disabled = cms != null ? cms.getDisabledPlugins() : Collections.emptySet();

    for (int c = 0, cSize = columns.size(); c < cSize; ++c) {
      DashboardColumn column = columns.get(c);
      double width = column.getWidth();

      page.writeStart(
          "div",
          "class",
          "dashboard-column",
          "style",
          page.cssString("width", ((width > 0 ? width : 1) / totalWidth * 100) + "%"));

      List<DashboardWidget> widgets = column.getWidgets();

      for (int w = 0, wSize = widgets.size(); w < wSize; ++w) {
        DashboardWidget widget = widgets.get(w);

        if (disabled.contains(widget.getClass().getName())) {
          continue;
        }

        String widgetUrl =
            page.toolUrl(
                CmsTool.class,
                "/dashboardWidget/"
                    + dashboardId
                    + "/"
                    + widget.getClass().getName()
                    + "/"
                    + widget.getId());

        page.writeStart(
            "div", "class", "frame dashboard-widget", "data-dashboard-widget-url", widgetUrl);
        page.writeStart("a", "href", widgetUrl);
        page.writeEnd();
        page.writeEnd();
      }
      page.writeEnd();
    }
    page.writeEnd();
    page.writeFooter();
  }
  /**
   * Delete all {@link SearchResultSelectionItem}s linking to this {@link SearchResultSelection}.
   */
  @Override
  protected void afterDelete() {

    Query.from(SearchResultSelectionItem.class).where("selectionId = ?", getId()).deleteAll();
  }
  @Override
  protected void doService(ToolPageContext page) throws IOException, ServletException {
    ToolUser user = page.getUser();
    Map<String, List<ToolUserDevice>> devicesByUserAgent =
        new CompactMap<String, List<ToolUserDevice>>();

    for (ToolUserDevice device :
        Query.from(ToolUserDevice.class).where("user = ?", user).selectAll()) {
      String userAgent = device.getUserAgentDisplay();
      List<ToolUserDevice> devices = devicesByUserAgent.get(userAgent);

      if (devices == null) {
        devices = new ArrayList<ToolUserDevice>();
        devicesByUserAgent.put(userAgent, devices);
      }

      devices.add(device);
    }

    final Map<ToolUserDevice, List<ToolUserAction>> actionsByDevice =
        new CompactMap<ToolUserDevice, List<ToolUserAction>>();

    for (Map.Entry<String, List<ToolUserDevice>> entry : devicesByUserAgent.entrySet()) {
      ToolUserDevice device = null;
      List<ToolUserAction> actions = null;
      long lastTime = 0;

      for (ToolUserDevice d : entry.getValue()) {
        List<ToolUserAction> a =
            Query.from(ToolUserAction.class)
                .where("device = ?", d)
                .sortDescending("time")
                .selectAll();

        if (!a.isEmpty()) {
          long time = a.get(0).getTime();

          if (lastTime < time) {
            lastTime = time;
            device = d;
            actions = a;
          }
        }
      }

      if (device != null) {
        actionsByDevice.put(device, actions);
      }
    }

    List<ToolUserDevice> recentDevices = new ArrayList<ToolUserDevice>(actionsByDevice.keySet());

    Collections.sort(
        recentDevices,
        new Comparator<ToolUserDevice>() {

          @Override
          public int compare(ToolUserDevice x, ToolUserDevice y) {
            long xTime = actionsByDevice.get(x).get(0).getTime();
            long yTime = actionsByDevice.get(y).get(0).getTime();

            return xTime < yTime ? 1 : (xTime > yTime ? -1 : 0);
          }
        });

    page.writeHeader();
    page.writeStart("div", "class", "widget", "style", "overflow: hidden;");
    page.writeStart("h1", "class", "icon icon-object-history");
    page.writeHtml(page.localize(ToolUserHistory.class, "title"));
    page.writeEnd();

    page.writeStart("div", "class", "tabbed");
    for (ToolUserDevice device : recentDevices) {
      List<ToolUserAction> actions = actionsByDevice.get(device);
      String lookingGlassUrl =
          page.cmsUrl("/lookingGlass", "id", device.getOrCreateLookingGlassId());

      page.writeStart("div", "data-tab", device.getUserAgentDisplay());
      page.writeStart(
          "div",
          "style",
          page.cssString(
              "float", "right",
              "text-align", "center"));
      page.writeStart(
          "a", "class", "icon icon-facetime-video", "target", "_blank", "href", lookingGlassUrl);
      page.writeHtml(page.localize(ToolUserHistory.class, "subtitle.lookingGlass"));
      page.writeEnd();

      page.writeElement("br");

      page.writeElement(
          "img",
          "width",
          150,
          "height",
          150,
          "src",
          page.cmsUrl(
              "qrCode",
              "data",
              JspUtils.getHostUrl(page.getRequest()) + lookingGlassUrl,
              "size",
              150));
      page.writeEnd();

      page.writeStart("ul", "class", "links", "style", page.cssString("margin-right", "150px"));
      for (ToolUserAction action : actions) {
        Object actionContent = action.getContent();

        if (actionContent == null) {
          continue;
        }

        page.writeStart("li");
        page.writeStart(
            "a", "target", "_top", "href", page.objectUrl("/content/edit.jsp", actionContent));
        page.writeTypeObjectLabel(actionContent);
        page.writeEnd();
        page.writeEnd();
      }
      page.writeEnd();
      page.writeEnd();
    }
    page.writeEnd();
    page.writeEnd();
    page.writeFooter();
  }
 /**
  * Clear the SearchResultSelection by deleting all of the SearchResultSelectionItem that point to
  * it.
  */
 public void clear() {
   Query.from(SearchResultSelectionItem.class).where("selectionId = ?", getId()).deleteAll();
 }
示例#23
0
          public HandlerResult findHandlerResult(
              HttpServletRequest request, HttpServletResponse response) {
            String servletPath = request.getServletPath();
            String[] pathParts = servletPath.split("/");
            String schoolKey = pathParts.length > 2 ? pathParts[2] : null;
            String athleteKey = pathParts.length > 3 ? pathParts[3] : null;
            String unknownMarker = pathParts.length > 4 ? pathParts[4] : null;
            String sportName = pathParts.length > 5 ? pathParts[5] : null;
            String levelName = pathParts.length > 6 ? pathParts[6] : null;
            String genderName = pathParts.length > 7 ? pathParts[7] : null;
            HandlerResult result = new HandlerResult();
            School school = null;
            if (!isBlank(schoolKey)) {
              school = School.findSchoolByKey(schoolKey.toLowerCase());
            }

            if (isBlank(school)) {
              result.content = null;
              result.page = null;
              result.stopHandlerChain = false;
              result.stopFilterChain = false;

              return result;
            } else if (isBlank(athleteKey)) {
              result.content = school;
              result.page = AppPageKeys.School.getPage();
              result.stopHandlerChain = true;
              result.stopFilterChain = false;

              try {
                Sport sport = Sport.valueOf(sportName.toUpperCase());
                SportLevel level = SportLevel.valueOf(levelName.toUpperCase());
                SportGender gender = SportGender.valueOf(genderName.toUpperCase());

                Query<Team> teamQuery =
                    Query.from(Team.class)
                        .where(
                            "sport = ? && gender = ? && level = ? && school = ?",
                            sport,
                            gender,
                            level,
                            school);
                getDisplayQuery(teamQuery);

                Team team = teamQuery.first();

                if (null != team) {
                  result.content = team;
                  result.page = AppPageKeys.Team.getPage();
                }
              } catch (Exception e) {
                logger.debug("failed to get team from request: " + servletPath, e);
              }

              return result;

            } else {

              try {
                Athlete athlete = Athlete.findAthleteByKey(athleteKey);

                if (null != athlete) {
                  setSchool(request, school);
                  result.content = athlete;
                  result.page = AppPageKeys.Athlete.getPage();
                  result.stopHandlerChain = true;
                  result.stopFilterChain = false;
                }

                return result;
              } catch (Exception e) {
                logger.debug("failed to get athlete from school request: " + servletPath, e);
              }
            }

            return result;
          }