Search in sources :

Example 36 with Group

use of org.craftercms.studio.api.v2.dal.Group in project studio by craftercms.

the class GroupServiceInternalImpl method getAllGroups.

@Override
public List<Group> getAllGroups(long orgId, int offset, int limit, String sort) throws ServiceLayerException {
    // Prepare parameters
    Map<String, Object> params = new HashMap<>();
    params.put(ORG_ID, orgId);
    params.put(OFFSET, offset);
    params.put(LIMIT, limit);
    params.put(SORT, sort);
    try {
        return groupDao.getAllGroupsForOrganization(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 37 with Group

use of org.craftercms.studio.api.v2.dal.Group in project studio by craftercms.

the class GroupServiceInternalImpl method addGroupMembers.

@Override
public List<User> addGroupMembers(long groupId, List<Long> userIds, List<String> usernames) throws GroupNotFoundException, UserNotFoundException, ServiceLayerException {
    if (!groupExists(groupId, StringUtils.EMPTY)) {
        throw new GroupNotFoundException("No group found for id '" + groupId + "'");
    }
    List<User> users = userServiceInternal.getUsersByIdOrUsername(userIds, usernames);
    Map<String, Object> params = new HashMap<>();
    params.put(USER_IDS, users.stream().map(User::getId).collect(Collectors.toList()));
    params.put(GROUP_ID, groupId);
    try {
        groupDao.addGroupMembers(params);
        return users;
    } 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) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 38 with Group

use of org.craftercms.studio.api.v2.dal.Group in project studio by craftercms.

the class DbVersionProvider method getCurrentVersion.

/**
 * {@inheritDoc}
 */
@Override
public String getCurrentVersion() throws UpgradeException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    logger.debug("Check if _meta table exists.");
    int count = jdbcTemplate.queryForObject(SQL_QUERY_META.replace(SCHEMA, studioConfiguration.getProperty(DB_SCHEMA)), Integer.class);
    if (count != 0) {
        logger.debug("_meta table exists.");
        logger.debug("Get version from _meta table.");
        return jdbcTemplate.queryForObject(SQL_QUERY_VERSION, String.class);
    } else {
        logger.debug("Check if group table exists.");
        count = jdbcTemplate.queryForObject(SQL_QUERY_GROUP.replace(SCHEMA, studioConfiguration.getProperty(DB_SCHEMA)), Integer.class);
        if (count != 0) {
            logger.debug("Database version is 3.0.0");
            return VERSION_3_0_0;
        } else {
            throw new UpgradeNotSupportedException("Automated migration from 2.5.x DB is not supported yet.");
        }
    }
}
Also used : UpgradeNotSupportedException(org.craftercms.studio.api.v2.exception.UpgradeNotSupportedException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Aggregations

Group (org.craftercms.studio.api.v2.dal.Group)26 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)23 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)20 HashMap (java.util.HashMap)17 GroupNotFoundException (org.craftercms.studio.api.v1.exception.security.GroupNotFoundException)13 ArrayList (java.util.ArrayList)12 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)12 User (org.craftercms.studio.api.v2.dal.User)12 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)11 GroupAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException)10 ConfigurationException (org.craftercms.studio.api.v2.exception.configuration.ConfigurationException)10 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)8 ResponseBody (org.craftercms.studio.model.rest.ResponseBody)6 List (java.util.List)5 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)4 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)4 AuditServiceInternal (org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal)4 StudioConfiguration (org.craftercms.studio.api.v2.utils.StudioConfiguration)4 ZonedDateTime (java.time.ZonedDateTime)3