Search in sources :

Example 11 with UserDto

use of org.entando.entando.aps.system.services.user.model.UserDto in project entando-core by entando.

the class UserControllerUnitTest method mockUsers.

private PagedMetadata<UserDto> mockUsers() {
    List<UserDetails> users = new ArrayList<>();
    User user1 = new User();
    user1.setUsername("admin");
    user1.setDisabled(false);
    user1.setLastAccess(new Date());
    user1.setLastPasswordChange(new Date());
    user1.setMaxMonthsSinceLastAccess(2);
    user1.setMaxMonthsSinceLastPasswordChange(1);
    User user2 = new User();
    user2.setUsername("user2");
    user2.setDisabled(false);
    user2.setLastAccess(new Date());
    user1.setLastPasswordChange(new Date());
    user2.setMaxMonthsSinceLastAccess(2);
    user2.setMaxMonthsSinceLastPasswordChange(1);
    User user3 = new User();
    user3.setUsername("user3");
    user3.setDisabled(false);
    user3.setLastAccess(new Date());
    user3.setLastPasswordChange(new Date());
    user3.setMaxMonthsSinceLastAccess(2);
    user3.setMaxMonthsSinceLastPasswordChange(1);
    users.add(user1);
    users.add(user2);
    users.add(user3);
    List<UserDto> dtoList = new UserDtoBuilder().convert(users);
    SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
    PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(new RestListRequest(), result);
    pagedMetadata.setBody(dtoList);
    return pagedMetadata;
}
Also used : User(com.agiletec.aps.system.services.user.User) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) ArrayList(java.util.ArrayList) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) Date(java.util.Date) UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserDtoBuilder(org.entando.entando.aps.system.services.user.model.UserDtoBuilder)

Example 12 with UserDto

use of org.entando.entando.aps.system.services.user.model.UserDto 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 13 with UserDto

use of org.entando.entando.aps.system.services.user.model.UserDto 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

UserDto (org.entando.entando.aps.system.services.user.model.UserDto)13 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)6 RestResponse (org.entando.entando.web.common.model.RestResponse)6 ResponseEntity (org.springframework.http.ResponseEntity)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 ArrayList (java.util.ArrayList)4 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 User (com.agiletec.aps.system.services.user.User)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)3 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 Date (java.util.Date)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 RestListRequest (org.entando.entando.web.common.model.RestListRequest)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)1 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)1 Role (com.agiletec.aps.system.services.role.Role)1