Search in sources :

Example 6 with Pagination

use of org.mx.dal.Pagination in project main by JohnPeng739.

the class UserManageResource method listUsersPagination.

@Path("users")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<UserVO>> listUsersPagination(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        List<User> users = accessor.list(pagination, User.class);
        List<UserVO> userVOs = UserVO.transform(users);
        return new PaginationDataVO<>(pagination, userVOs);
    } catch (UserInterfaceException ex) {
        return new PaginationDataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("List users fail.", ex);
        }
        return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Pagination(org.mx.dal.Pagination) User(org.mx.comps.rbac.dal.entity.User) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserVO(org.mx.comps.rbac.rest.vo.UserVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 7 with Pagination

use of org.mx.dal.Pagination in project main by JohnPeng739.

the class GeneralAccessorImpl method list.

/**
 * {@inheritDoc}
 *
 * @see GeneralAccessor#list(Pagination, Class, boolean)
 */
@Override
public <T extends Base> List<T> list(Pagination pagination, Class<T> clazz, boolean isValid) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        if (clazz.isInterface()) {
            clazz = EntityFactory.getEntityClass(clazz);
        }
        pagination.setTotal((int) count(clazz, isValid));
        int skip = (pagination.getPage() - 1) * pagination.getSize();
        int limit = pagination.getSize();
        if (isValid) {
            return template.find(query(where("valid").is(true)).skip(skip).limit(limit), clazz);
        } else {
            return template.find(new Query().skip(skip).limit(limit), clazz);
        }
    } catch (ClassNotFoundException ex) {
        throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.ENTITY_INSTANCE_FAIL);
    }
}
Also used : Pagination(org.mx.dal.Pagination) TextQuery(org.springframework.data.mongodb.core.query.TextQuery) Query(org.springframework.data.mongodb.core.query.Query) UserInterfaceDalErrorException(org.mx.dal.error.UserInterfaceDalErrorException)

Example 8 with Pagination

use of org.mx.dal.Pagination in project main by JohnPeng739.

the class NotifyServerResource method getOnlineDevices.

/**
 * 获取符合条件的在线设备列表
 *
 * @param state      指定的状态
 * @param later      注册时间晚于指定时间
 * @param early      注册时间早于指定时间
 * @param pagination 分页对象
 * @return 在线设备列表
 */
@Path("onlines")
@POST
public PaginationDataVO<List<OnlineDeviceVO>> getOnlineDevices(@QueryParam("state") String state, @QueryParam("later") long later, @QueryParam("early") long early, Pagination pagination) {
    List<Predicate<OnlineDevice>> filters = new ArrayList<>();
    if (!StringUtils.isBlank(state)) {
        filters.add(onlineDevice -> state.equals(onlineDevice.getState()));
    }
    if (later > 0) {
        filters.add(onlineDevice -> onlineDevice.getRegistryTime() >= later);
    }
    if (early > 0) {
        filters.add(onlineDevice -> onlineDevice.getRegistryTime() <= early);
    }
    Set<OnlineDevice> set = onlineManager.getOnlineDevices(filters);
    if (pagination == null) {
        pagination = new Pagination();
    }
    List<OnlineDevice> list = new ArrayList<>();
    list.addAll(set);
    // 按照注册时间排序
    list.sort((od1, od2) -> (int) (od1.getRegistryTime() - od2.getRegistryTime()));
    pagination.setTotal(set.size());
    List<OnlineDevice> result = new ArrayList<>();
    int skip = (pagination.getPage() - 1) * pagination.getSize();
    int num = Math.min(pagination.getSize(), list.size() - skip);
    for (int index = skip; index < skip + num; index++) {
        result.add(list.get(index));
    }
    return new PaginationDataVO<>(pagination, OnlineDeviceVO.transform(result));
}
Also used : Pagination(org.mx.dal.Pagination) OnlineDevice(org.mx.comps.notify.online.OnlineDevice) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) ArrayList(java.util.ArrayList) Predicate(java.util.function.Predicate)

Example 9 with Pagination

use of org.mx.dal.Pagination in project main by JohnPeng739.

the class ServerManageResource method getServers.

@Path("servers")
@POST
public PaginationDataVO<List<ServerInfoVO>> getServers(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        Map<String, JSONObject> map = serverManageService.getServerInfos(pagination);
        List<ServerInfoVO> list = new ArrayList<>();
        map.values().forEach(json -> list.add(new ServerInfoVO(json)));
        return new PaginationDataVO<>(pagination, list);
    } catch (UserInterfaceErrorException ex) {
        return new PaginationDataVO<>(ex);
    }
}
Also used : Pagination(org.mx.dal.Pagination) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) JSONObject(com.alibaba.fastjson.JSONObject) ServerInfoVO(com.ds.retl.rest.vo.server.ServerInfoVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) ArrayList(java.util.ArrayList)

Example 10 with Pagination

use of org.mx.dal.Pagination in project main by JohnPeng739.

the class AccountManageResource method logs.

@Path("logs")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<OperateLogVO>> logs(Pagination pagination, @Context Request request) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        List<OperateLog> logs = accessor.list(pagination, OperateLog.class);
        List<OperateLogVO> vos = OperateLogVO.transform(logs);
        return new PaginationDataVO(pagination, vos);
    } catch (UserInterfaceException ex) {
        return new PaginationDataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("List logs fail.", ex);
        }
        return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Pagination(org.mx.dal.Pagination) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) OperateLog(org.mx.dal.entity.OperateLog) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Aggregations

Pagination (org.mx.dal.Pagination)10 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)8 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)7 UserInterfaceException (org.mx.error.UserInterfaceException)7 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)7 ArrayList (java.util.ArrayList)2 JSONObject (com.alibaba.fastjson.JSONObject)1 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)1 ServerInfoVO (com.ds.retl.rest.vo.server.ServerInfoVO)1 Predicate (java.util.function.Predicate)1 OnlineDevice (org.mx.comps.notify.online.OnlineDevice)1 Accredit (org.mx.comps.rbac.dal.entity.Accredit)1 Department (org.mx.comps.rbac.dal.entity.Department)1 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)1 Privilege (org.mx.comps.rbac.dal.entity.Privilege)1 Role (org.mx.comps.rbac.dal.entity.Role)1 User (org.mx.comps.rbac.dal.entity.User)1 AccreditVO (org.mx.comps.rbac.rest.vo.AccreditVO)1 DepartmentVO (org.mx.comps.rbac.rest.vo.DepartmentVO)1 PrivilegeVO (org.mx.comps.rbac.rest.vo.PrivilegeVO)1