use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class UserServiceImplTest method createUserIndex.
private UserIndex createUserIndex(String indexType, String indexValue, User user) {
UserIndex index = new UserIndex();
index.setId(new UserIndexKey(indexType, indexValue));
index.setUser(user);
index.setCredentials("");
user.getUserIndices().add(index);
return index;
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class KeysResource method saveOrUpdateKey.
// Private methods
private void saveOrUpdateKey(String apiKey, Long minApiRequestInterval, String contactName, String contactCompany, String contactEmail, String contactDetails) throws Exception {
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndexForId = _userService.getUserIndexForId(key);
if (userIndexForId != null) {
throw new Exception("API key " + apiKey + " already exists.");
}
UserIndex userIndex = _userService.getOrCreateUserForIndexKey(key, "", true);
_userPropertiesService.authorizeApi(userIndex.getUser(), minApiRequestInterval);
// Set the API Key contact info
User user = userIndex.getUser();
_userPropertiesService.updateApiKeyContactInfo(user, contactName, contactCompany, contactEmail, contactDetails);
// Clear the cached value here
_userService.getMinApiRequestIntervalForKey(apiKey, true);
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class KeysResource method listEmails.
@Path("/list-emails")
@GET
@Produces("application/json")
public Response listEmails() throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting listEmails");
try {
validateSecurity();
List<String> apiKeys = _userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
List<String> emails = new ArrayList<String>();
int count = 0;
for (String apiKey : apiKeys) {
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = _userService.getUserIndexForId(key);
count++;
if (userIndex != null) {
if (userIndex.getUser() != null) {
if (userIndex.getUser().getProperties() != null) {
Object o = userIndex.getUser().getProperties();
if (o instanceof UserPropertiesV3) {
UserPropertiesV3 v3 = (UserPropertiesV3) o;
if (!StringUtils.isBlank(v3.getContactEmail())) {
emails.add(v3.getContactEmail());
}
}
}
}
}
if (count % 100 == 0)
log.info("processed " + count + " users....");
}
log.info("processing complete of " + count + " users!");
Response response = constructResponse(emails);
log.info("Returning response from listEmails");
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class KeysResource method delete.
private void delete(String apiKey) 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();
boolean found = false;
for (UserIndex index : user.getUserIndices()) {
if (index.getId().getValue().equalsIgnoreCase(key.getValue())) {
userIndex = index;
found = true;
break;
}
}
if (!found)
throw new Exception("API key " + apiKey + " not found (no exact match).");
_userService.removeUserIndexForUser(user, userIndex.getId());
if (user.getUserIndices().isEmpty())
_userService.deleteUser(user);
// Clear the cached value here
try {
_userService.getMinApiRequestIntervalForKey(apiKey, true);
} catch (Exception e) {
// Ignore this
}
}
use of org.onebusaway.users.model.UserIndexKey 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);
}
Aggregations