use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method getAllUsers.
@Override
public List<User> getAllUsers(int offset, int limit, String sort) throws ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(OFFSET, offset);
params.put(LIMIT, limit);
params.put(SORT, sort);
try {
return userDao.getAllUsers(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method getAllUsersForSite.
@Override
public List<User> getAllUsersForSite(long orgId, List<String> groupNames, int offset, int limit, String sort) throws ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(GROUP_NAMES, groupNames);
params.put(OFFSET, offset);
params.put(LIMIT, limit);
params.put(SORT, StringUtils.EMPTY);
try {
return userDao.getAllUsersForSite(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method getUserByIdOrUsername.
@Override
public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException {
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, userId);
params.put(USERNAME, username);
User user;
try {
user = userDao.getUserByIdOrUsername(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
if (user == null) {
throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
}
return user;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class GroupServiceImpl method updateGroup.
@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public Group updateGroup(long orgId, Group group) throws ServiceLayerException, GroupNotFoundException, AuthenticationException {
Group toRet = groupServiceInternal.updateGroup(orgId, group);
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(userService.getCurrentUser().getUsername());
auditLog.setPrimaryTargetId(group.getGroupName());
auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
auditLog.setPrimaryTargetValue(group.getGroupName());
auditServiceInternal.insertAuditLog(auditLog);
return toRet;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class GroupServiceImpl method removeGroupMembers.
@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public void removeGroupMembers(long groupId, List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException, GroupNotFoundException, AuthenticationException {
Group group = getGroup(groupId);
generalLockService.lock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
try {
if (group.getGroupName().equals(SYSTEM_ADMIN_GROUP)) {
List<User> members = getGroupMembers(groupId, 0, Integer.MAX_VALUE, StringUtils.EMPTY);
if (CollectionUtils.isNotEmpty(members)) {
List<User> membersAfterRemove = new ArrayList<User>();
membersAfterRemove.addAll(members);
members.forEach(m -> {
if (CollectionUtils.isNotEmpty(userIds)) {
if (userIds.contains(m.getId())) {
membersAfterRemove.remove(m);
}
}
if (CollectionUtils.isNotEmpty(usernames)) {
if (usernames.contains(m.getUsername())) {
membersAfterRemove.remove(m);
}
}
});
if (CollectionUtils.isEmpty(membersAfterRemove)) {
throw new ServiceLayerException("Removing all members of the System Admin group is not allowed." + " We must have at least one system administrator.");
}
}
}
List<User> users = userServiceInternal.getUsersByIdOrUsername(userIds, usernames);
groupServiceInternal.removeGroupMembers(groupId, userIds, usernames);
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_REMOVE_MEMBERS);
auditLog.setActorId(userService.getCurrentUser().getUsername());
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(Long.toString(group.getId()));
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(group.getGroupName());
List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
for (User user : users) {
AuditLogParameter paramter = new AuditLogParameter();
paramter.setTargetId(Long.toString(user.getId()));
paramter.setTargetType(TARGET_TYPE_USER);
paramter.setTargetValue(user.getUsername());
paramters.add(paramter);
}
auditLog.setParameters(paramters);
auditServiceInternal.insertAuditLog(auditLog);
} finally {
generalLockService.unlock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
}
}
Aggregations