Java Code Examples for com.alibaba.dubbo.common.utils.CollectionUtils#isEmpty()

The following examples show how to use com.alibaba.dubbo.common.utils.CollectionUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
@Override
public UserEntity login(LoginReq loginReq) {

    // 校验参数
    checkParam(loginReq);

    // 创建用户查询请求
    UserQueryReq userQueryReq = buildUserQueryReq(loginReq);

    // 查询用户
    List<UserEntity> userEntityList = userDAO.findUsers(userQueryReq);

    // 查询失败
    if (CollectionUtils.isEmpty(userEntityList)) {
        throw new CommonBizException(ExpCodeEnum.LOGIN_FAIL);
    }

    // 查询成功
    return userEntityList.get(0);
}
 
Example 2
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private void checkParam(RolePermissionReq rolePermissionReq) {
    // 参数不能为空
    if (rolePermissionReq==null) {
        throw new CommonBizException(ExpCodeEnum.PARAM_NULL);
    }

    // roleId不能为空 & TODO roleId 必须存在
    if (StringUtils.isEmpty(rolePermissionReq.getRoleId())) {
        throw new CommonBizException(ExpCodeEnum.ROLEID_NULL);
    }

    // 权限Id列表不能为空 & 权限Id必须都存在
    if (CollectionUtils.isEmpty(rolePermissionReq.getPermissionIdList())) {
        throw new CommonBizException(ExpCodeEnum.PERMISSIONIDLIST_NULL);
    }
}
 
Example 3
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private void checkParam(RoleMenuReq roleMenuReq) {
    // 参数不能为空
    if (roleMenuReq==null) {
        throw new CommonBizException(ExpCodeEnum.PARAM_NULL);
    }

    // roleId不能为空
    // TODO 确保roleId存在
    if (StringUtils.isEmpty(roleMenuReq.getRoleId())) {
        throw new CommonBizException(ExpCodeEnum.ROLEID_NULL);
    }

    // menuId列表不能为空 & TODO menuId必须存在
    if (CollectionUtils.isEmpty(roleMenuReq.getMenuIdList())) {
        throw new CommonBizException(ExpCodeEnum.MENUIDLIST_NULL);
    }
}
 
Example 4
Source File: Processor.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 处理函数
 * @param orderProcessContext
 */
public void handle(OrderProcessContext orderProcessContext) {
    overrideSuperComponentList();

    // componentList为空
    if (CollectionUtils.isEmpty(componentList)) {
        logger.error(this.getClass().getSimpleName() + "中componentList为空!");
        throw new CommonSysException(ExpCodeEnum.COMPONENT_NULL);
    }

    // 依次执行所有业务组件
    for (BaseComponent component : componentList) {
        component.handle(orderProcessContext);
        // 终止
        if (orderProcessContext.isStop()) {
            break;
        }
    }
}
 
Example 5
Source File: BaseIdempotencyComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 检查幂等性
 * @param curOrderState 订单当前的状态
 * @param allowStateList 订单允许的状态列表
 */
private void checkIdempotency(OrderStateEnum curOrderState, List<OrderStateEnum> allowStateList) {

    // allowStateList为空
    if (CollectionUtils.isEmpty(allowStateList)) {
        throw new CommonSysException(ExpCodeEnum.AllowStateList_NULL);
    }

    for (OrderStateEnum orderStateEnum : allowStateList) {
        if (orderStateEnum == curOrderState) {
            // 幂等性检查通过
            return;
        }
    }

    // 幂等性检查不通过
    throw new CommonBizException(ExpCodeEnum.NO_REPEAT);
}
 
Example 6
Source File: ProdIdCountMapTransferComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 订单查询
 * @param orderQueryReq 订单查询请求
 * @return 订单结果
 */
private OrdersEntity query(OrderQueryReq orderQueryReq) {
    List<OrdersEntity> ordersEntityList = orderDAO.findOrders(orderQueryReq);
    if (CollectionUtils.isEmpty(ordersEntityList)) {
        throw new CommonBizException(ExpCodeEnum.ORDER_NULL);
    }

    return ordersEntityList.get(0);
}
 
Example 7
Source File: ProdCountMapTransferComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 构建Map<ProductEntity, Integer>
 * @param productEntityList
 * @param prodIdCountMap
 * @return
 */
private Map<ProductEntity, Integer> buildProductEntityIntegerMap(List<ProductEntity> productEntityList, Map<String, Integer> prodIdCountMap) {
    Map<ProductEntity, Integer> map = Maps.newHashMap();

    if (CollectionUtils.isEmpty(productEntityList)) {
        return map;
    }

    for (ProductEntity productEntity : productEntityList) {
        Integer count = prodIdCountMap.get(productEntity.getId());
        map.put(productEntity, count);
    }
    return map;
}
 
Example 8
Source File: BaseIdempotencyComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前订单的状态
 * @param orderProcessContext 订单受理上下文
 * @return 订单状态
 */
private OrderStateEnum getOrderState(OrderProcessContext orderProcessContext) {
    // 获取订单ID
    String orderId = orderProcessContext.getOrderProcessReq().getOrderId();
    if (StringUtils.isEmpty(orderId)) {
        throw new CommonBizException(ExpCodeEnum.PROCESSREQ_ORDERID_NULL);
    }

    // 查询订单
    OrderQueryReq orderQueryReq = new OrderQueryReq();
    orderQueryReq.setId(orderId);
    List<OrdersEntity> ordersEntityList = orderDAO.findOrders(orderQueryReq);

    // 订单不存在
    if (CollectionUtils.isEmpty(ordersEntityList)) {
        throw new CommonBizException(ExpCodeEnum.ORDER_NULL);
    }

    // 获取订单状态
    // TODO 更新订单状态时,要连带更新order表中的状态
    OrderStateEnum orderStateEnum = ordersEntityList.get(0).getOrderStateEnum();

    // 订单存在 & 订单状态不存在
    if (orderStateEnum == null) {
        throw new CommonBizException(ExpCodeEnum.ORDER_STATE_NULL);
    }

    // 返回订单状态
    return orderStateEnum;
}
 
Example 9
Source File: BaseCheckParamComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 参数校验
 * @param param 待校验参数
 * @param expCodeEnum 异常错误码
 */
protected <T> void checkParam(T param, ExpCodeEnum expCodeEnum) {
    if (param == null) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof String && StringUtils.isEmpty((String) param)) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof Collection && CollectionUtils.isEmpty((Collection<?>) param)) {
        throw new CommonBizException(expCodeEnum);
    }
}
 
Example 10
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 4 votes vote down vote up
private void checkParam(BatchReq<UserStateReq> userStateReqs) {
    if (userStateReqs == null ||
            CollectionUtils.isEmpty(userStateReqs.getReqList())) {
        throw new CommonBizException(ExpCodeEnum.PARAM_NULL);
    }
}
 
Example 11
Source File: HttpPostDeliverService.java    From cicada with MIT License 4 votes vote down vote up
public boolean deliver(final List<Span> spanList) {
  boolean ret = false;

  if (CollectionUtils.isEmpty(spanList)) {
    LOGGER.error("spanList is Empty!");
    ret = false;
  } else {
    if (httpClient == null || httpPost == null) {
      LOGGER.error("httpClient({}) or httpPost({}) is null", httpClient, httpPost);
      ret = false;
    } else {
      final long startTime = System.currentTimeMillis();

      final int spanSize = spanList.size();
      final String spanListJson = JSON.toJSONString(spanList);
      final StringEntity postingString = new StringEntity(spanListJson, "utf-8");

      httpPost.setEntity(postingString);
      httpClient.execute(httpPost, new FutureCallback<HttpResponse>() {
        public void completed(final HttpResponse response) {
          if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("[push({})] [http_status:200] [spanSize:{}] [{}ms]", spanListJson, spanSize,
                (System.currentTimeMillis() - startTime));
          }
        }

        public void failed(final Exception ex) {
          LOGGER.error("[push({})] [{}] [error:{}]", httpPost.getURI(), spanListJson, ex);
        }

        public void cancelled() {
          LOGGER.error("[push({})] [http_status:cancelled]  [{}ms]", spanListJson,
              (System.currentTimeMillis() - startTime));
        }
      });

      ret = true;
    }
  }

  return ret;
}