use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getMinApiRequestIntervalForKey.
@Cacheable
@Transactional
@Override
public Long getMinApiRequestIntervalForKey(String key, @CacheableArgument(cacheRefreshIndicator = true) boolean forceRefresh) {
UserIndexKey indexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
UserIndex userIndex = getUserIndexForId(indexKey);
if (userIndex == null) {
return null;
}
User user = userIndex.getUser();
UserBean bean = getUserAsBean(user);
return bean.getMinApiRequestInterval();
}
use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.
the class DefaultSearchLocationServiceImpl method getDefaultSearchLocationForCurrentUser.
@Override
public DefaultSearchLocation getDefaultSearchLocationForCurrentUser() {
UserBean user = _currentUserService.getCurrentUser();
if (user != null && user.hasDefaultLocation()) {
return new DefaultSearchLocation(user.getDefaultLocationName(), user.getDefaultLocationLat(), user.getDefaultLocationLon(), false);
}
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
DefaultSearchLocation location = (DefaultSearchLocation) attributes.getAttribute(KEY_DEFAULT_SEARCH_LOCATION_FOR_SESSSION, RequestAttributes.SCOPE_SESSION);
return location;
}
use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.
the class KeysResource method updateKeyContactInfo.
private void updateKeyContactInfo(String apiKey, String contactName, String contactCompany, String contactEmail, String contactDetails, Long minApiReqIntervalLong) throws Exception {
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = _userService.getUserIndexForId(key);
if (userIndex == null)
throw new Exception("API key " + apiKey + " not found (userIndex null).");
User user = userIndex.getUser();
UserBean bean = _userService.getUserAsBean(user);
String keyContactName = bean.getContactName();
String keyContactCompany = bean.getContactCompany();
String keyContactEmail = bean.getContactEmail();
String keyContactDetails = bean.getContactDetails();
if (contactName != null) {
keyContactName = contactName;
}
if (contactCompany != null) {
keyContactCompany = contactCompany;
}
if (contactEmail != null) {
keyContactEmail = contactEmail;
}
if (contactDetails != null) {
keyContactDetails = contactDetails;
}
_userPropertiesService.authorizeApi(userIndex.getUser(), minApiReqIntervalLong);
_userPropertiesService.updateApiKeyContactInfo(user, keyContactName, keyContactCompany, keyContactEmail, keyContactDetails);
}
use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.
the class KeysResource method listKeyDetails.
@Path("/list/{apiKey}")
@GET
@Produces("application/json")
public Response listKeyDetails(@PathParam("apiKey") String apiKey) throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting listKeyDetails");
try {
validateSecurity();
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = _userService.getUserIndexForId(key);
if (userIndex == null)
throw new Exception("API key " + apiKey + " not found (userIndex null).");
User user = userIndex.getUser();
UserBean bean = _userService.getUserAsBean(user);
Map<String, String> result = new HashMap<String, String>();
result.put("keyValue", apiKey);
result.put("contactName", bean.getContactName());
result.put("contactCompany", bean.getContactCompany());
result.put("contactEmail", bean.getContactEmail());
result.put("contactDetails", bean.getContactDetails());
result.put("minApiRequestInterval", bean.getMinApiRequestInterval().toString());
Response response = constructResponse(result);
log.info("Returning response from listKeyDetails");
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.
the class CommandBookmarksAction method execute.
@Override
public String execute() throws ServiceException, BookmarkException {
UserBean currentUser = _currentUserService.getCurrentUser();
if (_arg != null && _arg.length() > 0) {
if (_arg.startsWith("add")) {
if (currentUser == null)
return "noUser";
List<String> lastSelectedStopIds = currentUser.getLastSelectedStopIds();
if (!lastSelectedStopIds.isEmpty()) {
String name = _bookmarkPresentationService.getNameForStopIds(lastSelectedStopIds);
_currentUserService.addStopBookmark(name, lastSelectedStopIds, new RouteFilter());
}
return "added";
}
if (_arg.startsWith("delete")) {
int index = _arg.indexOf(' ');
if (index == -1)
return INPUT;
int bookmarkIndex = Integer.parseInt(_arg.substring(index + 1).trim()) - 1;
_currentUserService.deleteStopBookmarks(bookmarkIndex);
return "deleted";
}
if (_arg.matches("\\d+")) {
int index = Integer.parseInt(_arg) - 1;
List<BookmarkBean> bookmarks = currentUser.getBookmarks();
if (index < 0 || index >= bookmarks.size())
return INPUT;
BookmarkBean bookmark = bookmarks.get(index);
_stopIds = bookmark.getStopIds();
_routeFilter = bookmark.getRouteFilter().getRouteIds();
return "arrivals-and-departures";
}
}
_bookmarks = _bookmarkPresentationService.getBookmarksWithStops(currentUser.getBookmarks());
return SUCCESS;
}
Aggregations