use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.
the class AbstractBookmarkAction method populateBookmarks.
protected void populateBookmarks(List<BookmarkWithStopsBean> bookmarks, String messageKey) {
int index = 1;
for (BookmarkWithStopsBean bookmark : bookmarks) {
_log.debug("found bookmark=" + bookmark);
String toPress = Integer.toString(index);
addMessage(messageKey);
List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
addBookmarkDescription(bookmark);
addText(", ");
addMessage(Messages.PLEASE_PRESS);
addText(toPress);
addText(". ");
index++;
}
addMessage(Messages.HOW_TO_GO_BACK);
}
use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.
the class AbstractBookmarkAction method setSelection.
protected void setSelection() {
List<BookmarkWithStopsBean> bookmarks = _bookmarkPresentationService.getBookmarksWithStops(_currentUser.getBookmarks());
int selection = 0;
try {
selection = Integer.parseInt(getInput()) - 1;
} catch (NumberFormatException nfe) {
// bury
}
if (selection >= bookmarks.size()) {
_log.warn("resetting bookmark size to " + (bookmarks.size() - 1));
selection = bookmarks.size() - 1;
}
_log.debug("bookmark selection=" + selection);
if (selection < 0) {
_isValidSelection = false;
setStopIds(null);
setRouteIds(null);
} else {
_isValidSelection = true;
BookmarkWithStopsBean bookmark = bookmarks.get(selection);
_log.debug("selected stop=" + bookmark.getStops());
List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
setStopIds(stopIds);
setRouteIds(routeIds);
setIndex(selection);
}
}
use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.
the class ManageTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack stack = context.getValueStack();
List<BookmarkWithStopsBean> bookmarks = (List<BookmarkWithStopsBean>) stack.findValue("bookmarks");
if (bookmarks.isEmpty()) {
addMessage(Messages.BOOKMARKS_EMPTY);
} else {
int index = 1;
for (BookmarkWithStopsBean bookmark : bookmarks) {
addMessage(Messages.BOOKMARKS_TO_DELETE_THE_BOOKMARK_FOR);
addBookmarkDescription(bookmark);
addMessage(Messages.PLEASE_PRESS);
String toPress = Integer.toString(index);
addText(toPress);
AgiActionName deleteAction = addAction(toPress, "/bookmarks/deleteByIndex");
deleteAction.putParam("index", index - 1);
index++;
}
}
addAction("(#|0|.+\\*)", "/repeat");
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.
the class BookmarkPresentationServiceImpl method getBookmarksWithStops.
@Override
public List<BookmarkWithStopsBean> getBookmarksWithStops(List<BookmarkBean> bookmarks) {
List<BookmarkWithStopsBean> beans = new ArrayList<BookmarkWithStopsBean>(bookmarks.size());
for (BookmarkBean bookmark : bookmarks) {
BookmarkWithStopsBean bean = new BookmarkWithStopsBean();
bean.setId(bookmark.getId());
bean.setName(bookmark.getName());
bean.setStops(getStopsForStopIds(bookmark.getStopIds()));
bean.setRoutes(getRoutesForRouteFilter(bookmark.getRouteFilter()));
beans.add(bean);
}
return beans;
}
use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.
the class BookmarkStopAction method execute.
@Override
public String execute() throws Exception {
_log.debug("in execute! with input=" + getInput() + " and stops=" + _stops + " and stopIds=" + _stopIds + " and user=" + _currentUser);
if (PREVIOUS_MENU_ITEM.equals(getInput()) || "9".equals(getInput())) {
clearNextAction();
return "index";
}
if (_currentUser != null && !_currentUser.isRememberPreferencesEnabled())
return "preferences_disabled";
setNextAction("bookmarks/bookmark-stop");
if (_currentUser == null) {
// something went wrong, bail
addMessage(Messages.BOOKMARKS_EMPTY);
addMessage(Messages.HOW_TO_GO_BACK);
addMessage(Messages.TO_REPEAT);
return INPUT;
}
// from here we have a currentUser
if (_stops.isEmpty()) {
_log.debug("empty stops!");
addMessage(Messages.BOOKMARKS_EMPTY);
addMessage(Messages.HOW_TO_GO_BACK);
addMessage(Messages.TO_REPEAT);
return INPUT;
}
// to allow REPEAT/BACK choices to still work, we need to limit bookmarks to 7
List<BookmarkWithStopsBean> bookmarks = _bookmarkPresentationService.getBookmarksWithStops(_currentUser.getBookmarks());
if (bookmarks.size() > MAX_BOOKMARKS) {
addMessage(Messages.BOOKMARKS_AT_CAPACITY);
addMessage(Messages.HOW_TO_GO_BACK);
return SUCCESS;
}
// make sure the bookmark isn't already there
for (BookmarkWithStopsBean bookmark : bookmarks) {
for (StopBean stopBean : _stops) {
if (bookmark.getStops().contains(stopBean)) {
addMessage(Messages.BOOKMARK_ALREADY_ADDED);
addMessage(Messages.HOW_TO_GO_BACK);
return SUCCESS;
}
}
}
// add the bookmark
String name = _bookmarkPresentationService.getNameForStops(_stops);
List<String> stopIds = MappingLibrary.map(_stops, "id");
_currentUserService.addStopBookmark(name, stopIds, new RouteFilter());
logUserInteraction("stopIds", stopIds);
addMessage(Messages.BOOKMARK_ADDED);
return SUCCESS;
}
Aggregations