Search in sources :

Example 1 with GroupAlreadyExistsException

use of org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException in project studio by craftercms.

the class GroupServiceInternalImpl method createGroup.

@Override
public Group createGroup(long orgId, String groupName, String groupDescription) throws GroupAlreadyExistsException, ServiceLayerException {
    if (groupExists(-1, groupName)) {
        throw new GroupAlreadyExistsException("Group '" + groupName + "' already exists");
    }
    Map<String, Object> params = new HashMap<>();
    params.put(ORG_ID, orgId);
    params.put(GROUP_NAME, groupName);
    params.put(GROUP_DESCRIPTION, groupDescription);
    try {
        groupDao.createGroup(params);
        Group group = new Group();
        group.setId((Long) params.get(ID));
        group.setGroupName(groupName);
        group.setGroupDescription(groupDescription);
        return group;
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) HashMap(java.util.HashMap) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) 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 2 with GroupAlreadyExistsException

use of org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException in project studio by craftercms.

the class GroupServiceImpl method createGroup.

@Override
@HasPermission(type = DefaultPermission.class, action = "create_groups")
public Group createGroup(long orgId, String groupName, String groupDescription) throws GroupAlreadyExistsException, ServiceLayerException, AuthenticationException {
    Group toRet = groupServiceInternal.createGroup(orgId, groupName, groupDescription);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CREATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(groupName);
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(groupName);
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Aggregations

Group (org.craftercms.studio.api.v2.dal.Group)2 HashMap (java.util.HashMap)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)1 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1 GroupAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException)1 GroupNotFoundException (org.craftercms.studio.api.v1.exception.security.GroupNotFoundException)1 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)1 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)1 ConfigurationException (org.craftercms.studio.api.v2.exception.configuration.ConfigurationException)1