Search in sources :

Example 61 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class UserService method addUserAuthorities.

@Override
public List<UserAuthorityDto> addUserAuthorities(String username, UserAuthoritiesRequest request) {
    try {
        List<UserAuthorityDto> authorizations = new ArrayList<>();
        final UserDetails user = this.getUserManager().getUser(username);
        ;
        request.forEach(authorization -> {
            try {
                if (!this.getAuthorizationManager().isAuthOnGroupAndRole(user, authorization.getGroup(), authorization.getRole(), true)) {
                    this.getAuthorizationManager().addUserAuthorization(username, authorization.getGroup(), authorization.getRole());
                }
            } catch (ApsSystemException ex) {
                logger.error("Error in add authorities for {}", username, ex);
                throw new RestServerError("Error in add authorities", ex);
            }
            authorizations.add(new UserAuthorityDto(authorization.getGroup(), authorization.getRole()));
        });
        return authorizations;
    } catch (ApsSystemException ex) {
        logger.error("Error in add authorities for {}", username, ex);
        throw new RestServerError("Error in add authorities", ex);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 62 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class UserService method addUser.

@Override
public UserDto addUser(UserRequest userRequest) {
    try {
        UserDetails newUser = this.createUser(userRequest);
        this.getUserManager().addUser(newUser);
        return dtoBuilder.convert(newUser);
    } catch (ApsSystemException e) {
        logger.error("Error in adding user {}", userRequest.getUsername(), e);
        throw new RestServerError("Error in adding user", e);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 63 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class WidgetService method addWidget.

@Override
public WidgetDto addWidget(WidgetRequest widgetRequest) {
    WidgetType widgetType = new WidgetType();
    this.processWidgetType(widgetType, widgetRequest);
    WidgetType oldWidgetType = this.getWidgetManager().getWidgetType(widgetType.getCode());
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widgetType, "widget");
    if (null != oldWidgetType) {
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_ALREADY_EXISTS, new String[] { widgetType.getCode() }, "widgettype.exists");
        throw new ValidationGenericException(bindingResult);
    } else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
        throw new ValidationGenericException(bindingResult);
    }
    WidgetDto widgetDto = null;
    try {
        this.getWidgetManager().addWidgetType(widgetType);
        this.createAndAddFragment(widgetType, widgetRequest);
        widgetDto = this.dtoBuilder.convert(widgetType);
        this.addFragments(widgetDto);
    } catch (Exception e) {
        logger.error("Failed to add widget type for request {} ", widgetRequest);
        throw new RestServerError("error in add widget", e);
    }
    return widgetDto;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 64 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class AuthorizationService method getRoleUtilizer.

@Override
public List<UserDto> getRoleUtilizer(String roleCode) {
    try {
        List<String> usernames = this.getAuthorizationManager().getUsersByRole(roleCode, false);
        List<UserDto> dtoList = new ArrayList<>();
        if (null != usernames) {
            usernames.stream().forEach(i -> {
                try {
                    dtoList.add(this.getDtoBuilder().convert(this.getUserManager().getUser(i)));
                } catch (ApsSystemException e) {
                    logger.error("error loading {}", i, e);
                }
            });
        }
        return dtoList;
    } catch (ApsSystemException ex) {
        logger.error("Error loading user references for role {}", roleCode, ex);
        throw new RestServerError("Error loading user references by role", ex);
    }
}
Also used : UserDto(org.entando.entando.aps.system.services.user.model.UserDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 65 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class AuthorizationService method getGroupUtilizer.

@Override
public List<UserDto> getGroupUtilizer(String groupCode) {
    try {
        List<String> usernames = ((GroupUtilizer<String>) this.getAuthorizationManager()).getGroupUtilizers(groupCode);
        List<UserDto> dtoList = new ArrayList<>();
        if (null != usernames) {
            usernames.stream().forEach(i -> {
                try {
                    dtoList.add(this.getDtoBuilder().convert(this.getUserManager().getUser(i)));
                } catch (ApsSystemException e) {
                    logger.error("error loading {}", i, e);
                }
            });
        }
        return dtoList;
    } catch (ApsSystemException ex) {
        logger.error("Error loading user references for group {}", groupCode, ex);
        throw new RestServerError("Error loading user references by group", ex);
    }
}
Also used : UserDto(org.entando.entando.aps.system.services.user.model.UserDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Aggregations

RestServerError (org.entando.entando.aps.system.exception.RestServerError)65 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)45 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)28 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)25 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)13 ArrayList (java.util.ArrayList)12 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)12 IPage (com.agiletec.aps.system.services.page.IPage)10 List (java.util.List)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)9 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)8 LoggerFactory (org.slf4j.LoggerFactory)8 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 Logger (org.slf4j.Logger)7 ApsProperties (com.agiletec.aps.util.ApsProperties)6 Group (com.agiletec.aps.system.services.group.Group)5 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Category (com.agiletec.aps.system.services.category.Category)4