use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class ApiKeyAction method searchContactEmail.
public String searchContactEmail() {
String searchResult = "Email address '" + contactEmail + "' could not be found";
List<String> apiKeys = userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
// clear other fields
contactName = "";
contactCompany = "";
contactDetails = "";
key = "";
for (String apiKey : apiKeys) {
// for each api key, check if contact email matches
UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = userService.getUserIndexForId(userKey);
if (userIndex != null) {
User user = userIndex.getUser();
UserBean bean = userService.getUserAsBean(user);
if (contactEmail.equals(bean.getContactEmail())) {
minApiReqInt = bean.getMinApiRequestInterval();
contactName = bean.getContactName();
contactCompany = bean.getContactCompany();
contactDetails = bean.getContactDetails();
key = apiKey;
searchResult = "Email address '" + contactEmail + "' found";
break;
}
}
}
addActionMessage(searchResult);
return SUCCESS;
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class ApiKeyAction method updateAPIKey.
public void updateAPIKey(UserIndex userIndexForId) {
User user = userIndexForId.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(user, minApiReqInt);
userPropertiesService.updateApiKeyContactInfo(user, keyContactName, keyContactCompany, keyContactEmail, keyContactDetails);
// Clear the cached value here
userService.getMinApiRequestIntervalForKey(key, true);
return;
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class ApiKeyAction method deleteAPIKey.
public String deleteAPIKey() {
// Check if key already exists
UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
UserIndex userIndexForId = userService.getUserIndexForId(userKey);
if (userIndexForId == null) {
addActionMessage("Key '" + key + "' does not exist");
} else {
User user = userIndexForId.getUser();
boolean found = false;
for (UserIndex index : user.getUserIndices()) {
if (index.getId().getValue().equalsIgnoreCase(userKey.getValue())) {
userIndexForId = index;
found = true;
break;
}
}
if (!found) {
addActionMessage("API key " + key + " not found (no exact match).");
}
userService.removeUserIndexForUser(user, userIndexForId.getId());
if (user.getUserIndices().isEmpty()) {
userService.deleteUser(user);
}
// Clear the cached value here
userService.getMinApiRequestIntervalForKey(key, true);
addActionMessage("Key '" + key + "' deleted");
clearContactInfoAndKey();
}
return SUCCESS;
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method inactivateUser.
// Marks the user as inactive, can activate again
@Override
public boolean inactivateUser(UserDetail userDetail) {
User user = userService.getUserForId(userDetail.getId());
if (user == null) {
log.info("User '{}' does not exist in the system", userDetail.getUsername());
return false;
}
userPropertiesService.disableUser(user);
log.info("User '{}' disabled successfully", userDetail.getUsername());
return true;
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method getInactiveUsersDetails.
@Override
public List<UserDetail> getInactiveUsersDetails() {
List<UserDetail> userDetails = new ArrayList<UserDetail>();
List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {
@SuppressWarnings("unchecked")
@Override
public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME));
List<User> users = criteria.list();
return users;
}
});
if (!users.isEmpty()) {
for (User user : users) {
UserBean bean = userService.getUserAsBean(user);
if (bean.isDisabled()) {
if (!user.getUserIndices().isEmpty()) {
UserDetail userDetail = buildUserDetail(user);
userDetails.add(userDetail);
}
}
}
}
log.debug("Returning user details");
return userDetails;
}
Aggregations