use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.
the class RepositoryManagementServiceInternalImpl method removeRemote.
@RetryingOperation
@Override
public boolean removeRemote(String siteId, String remoteName) throws CryptoException, RemoteNotRemovableException {
if (!isRemovableRemote(siteId, remoteName)) {
throw new RemoteNotRemovableException("Remote repository " + remoteName + " is not removable");
}
logger.debug("Remove remote " + remoteName + " from the sandbox repo for the site " + siteId);
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
Repository repo = helper.getRepository(siteId, SANDBOX);
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, siteId);
generalLockService.lock(gitLockKey);
try (Git git = new Git(repo)) {
RemoteRemoveCommand remoteRemoveCommand = git.remoteRemove();
remoteRemoveCommand.setRemoteName(remoteName);
retryingRepositoryOperationFacade.call(remoteRemoveCommand);
List<Ref> resultRemoteBranches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
List<String> branchesToDelete = new ArrayList<String>();
for (Ref remoteBranchRef : resultRemoteBranches) {
if (remoteBranchRef.getName().startsWith(Constants.R_REMOTES + remoteName)) {
branchesToDelete.add(remoteBranchRef.getName());
}
}
if (CollectionUtils.isNotEmpty(branchesToDelete)) {
DeleteBranchCommand delBranch = git.branchDelete();
String[] array = new String[branchesToDelete.size()];
delBranch.setBranchNames(branchesToDelete.toArray(array));
delBranch.setForce(true);
retryingRepositoryOperationFacade.call(delBranch);
}
} catch (GitAPIException e) {
logger.error("Failed to remove remote " + remoteName + " for site " + siteId, e);
return false;
} finally {
generalLockService.unlock(gitLockKey);
}
logger.debug("Remove remote record from database for remote " + remoteName + " and site " + siteId);
Map<String, String> params = new HashMap<String, String>();
params.put("siteId", siteId);
params.put("remoteName", remoteName);
remoteRepositoryDao.deleteRemoteRepository(params);
return true;
}
use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.
the class GroupServiceInternalImpl method deleteGroup.
@RetryingOperation
@Override
public void deleteGroup(List<Long> groupIds) throws GroupNotFoundException, ServiceLayerException {
for (Long groupId : groupIds) {
if (!groupExists(groupId, StringUtils.EMPTY)) {
throw new GroupNotFoundException("No group found for id '" + groupId + "'");
}
}
Map<String, Object> params = new HashMap<>();
params.put(GROUP_IDS, groupIds);
try {
groupDao.deleteGroups(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 GroupServiceInternalImpl method updateGroup.
@RetryingOperation
@Override
public Group updateGroup(long orgId, Group group) throws GroupNotFoundException, ServiceLayerException {
if (!groupExists(group.getId(), StringUtils.EMPTY)) {
throw new GroupNotFoundException("No group found for id '" + group.getId() + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(ID, group.getId());
params.put(ORG_ID, orgId);
params.put(GROUP_NAME, group.getGroupName());
params.put(GROUP_DESCRIPTION, group.getGroupDescription());
try {
groupDao.updateGroup(params);
return group;
} 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 enableUsers.
@RetryingOperation
@Override
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException {
List<User> users = getUsersByIdOrUsername(userIds, usernames);
Map<String, Object> params = new HashMap<>();
params.put(USER_IDS, users.stream().map(User::getId).collect(Collectors.toList()));
params.put(ENABLED, enabled ? 1 : 0);
try {
userDao.enableUsers(params);
return getUsersByIdOrUsername(userIds, usernames);
} 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 setUserPassword.
@RetryingOperation
@Override
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
if (!userExists(-1, username)) {
throw new UserNotFoundException();
} else {
if (verifyPasswordRequirements(newPassword)) {
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 {
String hashedPassword = CryptoUtils.hashPassword(newPassword);
params = new HashMap<String, Object>();
params.put(USERNAME, username);
params.put(PASSWORD, hashedPassword);
userDao.setUserPassword(params);
return true;
}
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
} else {
throw new PasswordRequirementsFailedException("User password does not fulfill requirements");
}
}
}
Aggregations