use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findRange.
@Override
public Iterable<Profile> findRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_QUERY);
Find find = getCollection().find(query, tenantName);
addSort(find, sortBy, sortOrder);
addRange(find, start, count);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find range of profiles for tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class AuthenticationServiceImpl method refreshPersistentLoginToken.
@Override
public PersistentLogin refreshPersistentLoginToken(String loginId) throws ProfileException {
PersistentLogin login = getPersistentLogin(loginId);
if (login != null) {
try {
login.setToken(UUID.randomUUID().toString());
persistentLoginRepository.save(login);
logger.debug(LOG_KEY_PERSISTENT_LOGIN_TOKEN_REFRESHED, loginId, login.getToken());
return login;
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_UPDATE_PERSISTENT_LOGIN_ERROR, loginId);
}
} else {
throw new NoSuchPersistentLoginException(loginId);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class AuthenticationServiceImpl method getTicket.
@Override
public Ticket getTicket(String ticketId) throws ProfileException {
Ticket ticket;
try {
ticket = ticketRepository.findByStringId(ticketId);
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_GET_TICKET_ERROR, e, ticketId);
}
if (ticket != null) {
checkIfManageTicketsIsAllowed(ticket.getTenant());
ticket.setLastRequestTime(new Date());
try {
ticketRepository.save(ticket);
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_UPDATE_TICKET_ERROR, ticketId);
}
logger.debug(LOG_KEY_TICKET_REQUESTED, ticketId);
return ticket;
}
return null;
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class TenantServiceImpl method updateTenant.
protected Tenant updateTenant(String tenantName, UpdateCallback callback) throws ProfileException {
Tenant tenant = getTenant(tenantName);
if (tenant != null) {
checkIfTenantActionIsAllowed(tenantName, TenantAction.UPDATE_TENANT);
UpdateHelper updateHelper = new UpdateHelper();
TenantUpdater tenantUpdater = new TenantUpdater(tenant, updateHelper, tenantRepository);
callback.doWithTenant(tenantUpdater);
try {
tenantUpdater.update();
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_UPDATE_TENANT_ERROR, e, tenant.getName());
}
} else {
throw new NoSuchTenantException(tenantName);
}
return tenant;
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class TenantServiceImpl method createTenant.
@Override
public Tenant createTenant(Tenant tenant) throws ProfileException {
checkIfTenantActionIsAllowed(null, TenantAction.CREATE_TENANT);
// Make sure ID is null, we want it auto-generated
tenant.setId(null);
try {
tenantRepository.insert(tenant);
} catch (DuplicateKeyException e) {
throw new TenantExistsException(tenant.getName());
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_CREATE_TENANT_ERROR, e, tenant.getName());
}
logger.debug(LOG_KEY_TENANT_CREATED, tenant);
return tenant;
}
Aggregations