Search in sources :

Example 16 with RetryingOperation

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;
}
Also used : NavigationOrderSequence(org.craftercms.studio.api.v1.dal.NavigationOrderSequence) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 17 with RetryingOperation

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);
    }
}
Also used : User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation)

Example 18 with RetryingOperation

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);
    }
}
Also used : UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation)

Aggregations

RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)18 HashMap (java.util.HashMap)13 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)8 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)7 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)7 User (org.craftercms.studio.api.v2.dal.User)6 PasswordDoesNotMatchException (org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException)5 UserExternallyManagedException (org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException)5 PasswordRequirementsFailedException (org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)4 ArrayList (java.util.ArrayList)3 ItemState (org.craftercms.studio.api.v1.dal.ItemState)3 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)3 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)3 GitRepositoryHelper (org.craftercms.studio.api.v2.utils.GitRepositoryHelper)3 DeleteBranchCommand (org.eclipse.jgit.api.DeleteBranchCommand)3 Git (org.eclipse.jgit.api.Git)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 Repository (org.eclipse.jgit.lib.Repository)3