use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.
the class DmPageNavigationOrderServiceImpl method getNewNavOrder.
@RetryingOperation
@Override
@ValidateParams
public double getNewNavOrder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateDoubleParam(name = "currentMaxNavOrder") double currentMaxNavOrder) {
double lastNavOrder = 1000D;
try {
Map<String, String> params = new HashMap<String, String>();
params.put("site", site);
params.put("path", path);
NavigationOrderSequence navigationOrderSequence = navigationOrderSequenceMapper.getPageNavigationOrderForSiteAndPath(params);
if (navigationOrderSequence == null) {
navigationOrderSequence = new NavigationOrderSequence();
navigationOrderSequence.setSite(site);
navigationOrderSequence.setPath(path);
ContentItemTO itemTreeTO = contentService.getContentItemTree(site, path, 1);
if (itemTreeTO == null) {
navigationOrderSequence.setMaxCount(0F);
} else {
if (StringUtils.isEmpty(itemTreeTO.getNodeRef())) {
navigationOrderSequence.setFolderId(UUID.randomUUID().toString());
} else {
navigationOrderSequence.setFolderId(itemTreeTO.getNodeRef());
}
if (currentMaxNavOrder < 0) {
navigationOrderSequence.setMaxCount(1000F * itemTreeTO.getNumOfChildren());
} else {
double newMaxCount = currentMaxNavOrder + getPageNavigationOrderIncrement();
navigationOrderSequence.setMaxCount(newMaxCount);
}
}
navigationOrderSequenceMapper.insert(navigationOrderSequence);
} else {
double newMaxCount = navigationOrderSequence.getMaxCount() + getPageNavigationOrderIncrement();
navigationOrderSequence.setMaxCount(newMaxCount);
navigationOrderSequenceMapper.update(navigationOrderSequence);
}
lastNavOrder = navigationOrderSequence.getMaxCount();
} catch (Exception e) {
logger.error("Unexpected error: ", e);
}
return lastNavOrder;
}
use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.
the class UserServiceInternalImpl method deleteUsers.
@RetryingOperation
@Override
public void deleteUsers(List<Long> userIds, List<String> usernames) throws UserNotFoundException, ServiceLayerException {
List<User> users = getUsersByIdOrUsername(userIds, usernames);
Map<String, Object> params = new HashMap<>();
params.put(USER_IDS, users.stream().map(User::getId).collect(Collectors.toList()));
try {
userDao.deleteUsers(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.
the class UserServiceInternalImpl method changePassword.
@RetryingOperation
@Override
public boolean changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException {
Map<String, Object> params = new HashMap<String, Object>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
try {
User user = userDao.getUserByIdOrUsername(params);
if (user.isExternallyManaged()) {
throw new UserExternallyManagedException();
} else {
if (CryptoUtils.matchPassword(user.getPassword(), current)) {
if (verifyPasswordRequirements(newPassword)) {
String hashedPassword = CryptoUtils.hashPassword(newPassword);
params = new HashMap<>();
params.put(USERNAME, username);
params.put(PASSWORD, hashedPassword);
userDao.setUserPassword(params);
return true;
} else {
throw new PasswordRequirementsFailedException();
}
} else {
throw new PasswordDoesNotMatchException();
}
}
} catch (RuntimeException e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
Aggregations