Search in sources :

Example 1 with EmptyNullException

use of com.duangframework.core.exceptions.EmptyNullException in project duangframework by tcrct.

the class MongoBaseDao method findPage.

/**
 * 分页查找记录,按Page对象返回
 * @param mongoQuery		查询条件
 * @return	分页DTO对象
 * @throws Exception
 */
public PageDto<T> findPage(MongoQuery mongoQuery) throws Exception {
    if (ToolsKit.isEmpty(mongoQuery)) {
        throw new EmptyNullException("Mongodb findPage is Fail: mongoQuery is null");
    }
    Bson queryDoc = mongoQuery.getQueryBson();
    PageDto<T> page = mongoQuery.getPage();
    int pageNo = page.getPageNo();
    int pageSize = page.getPageSize();
    final List<T> resultList = new ArrayList<T>();
    collection.find(queryDoc).projection((BasicDBObject) mongoQuery.getDBFields()).sort((BasicDBObject) mongoQuery.getDBOrder()).skip((pageNo > 0 ? (pageNo - 1) : pageNo) * pageSize).limit(pageSize).hint((BasicDBObject) mongoQuery.getHintDBObject()).forEach(new Block<Document>() {

        @Override
        public void apply(Document document) {
            resultList.add((T) MongoUtils.toEntity(document, cls));
        }
    });
    page.setResult(resultList);
    if (page.isAutoCount()) {
        page.setTotalCount(count(mongoQuery));
    }
    return page;
}
Also used : EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) Document(org.bson.Document) Bson(org.bson.conversions.Bson)

Example 2 with EmptyNullException

use of com.duangframework.core.exceptions.EmptyNullException in project duangframework by tcrct.

the class RouteHelper method duang.

public static void duang() {
    Map<Class<?>, Object> controllerMap = BeanUtils.getAllBeanMaps().get(CONTROLLER_ENDWITH_NAME);
    if (ToolsKit.isEmpty(controllerMap)) {
        throw new EmptyNullException("mvc controller is null");
    }
    Set<String> excludedMethodName = ObjectKit.buildExcludedMethodName();
    Method[] baseControllerMethods = BaseController.class.getMethods();
    for (Method method : baseControllerMethods) {
        excludedMethodName.add(method.getName());
    }
    // 遍历所有Controller对象,取出Mapping注解,生成路由集合
    for (Iterator<Map.Entry<Class<?>, Object>> it = controllerMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<Class<?>, Object> entry = it.next();
        Class<?> controllerClass = entry.getKey();
        Mapping controllerMapping = controllerClass.getAnnotation(Mapping.class);
        // String controllerKey = ToolsKit.isEmpty(controllerMapping) ? buildMappingKey(controllerClass.getSimpleName()) : controllerMapping.value().toLowerCase();
        String controllerKey = buildMappingKey(controllerMapping, controllerClass.getSimpleName());
        for (Method method : controllerClass.getMethods()) {
            Mapping methodMapping = method.getAnnotation(Mapping.class);
            String methodName = method.getName();
            // Object类公用 方法名并且没有参数的方法
            if (!excludedMethodName.contains(methodName) && method.getParameterTypes().length == 0) {
                Action action = buildAction(controllerClass, controllerKey, methodMapping, method);
                String actionKey = action.getActionKey();
                if (actionKey.contains("{") && actionKey.contains("}")) {
                    action.setRestfulKey(actionKey);
                    restfulActionMapping.put(actionKey, action);
                }
                if (!ToolsKit.isExist(actionKey, actionMapping)) {
                    actionMapping.put(actionKey, action);
                }
            }
        }
    }
    List<String> keyList = getAllActionKeys();
    logger.warn("**************** Controller Mapper Key ****************");
    for (String key : keyList) {
        logger.warn(key);
    }
    if (!actionMapping.isEmpty()) {
        InstanceFactory.setActionMapping(actionMapping);
    }
    if (!restfulActionMapping.isEmpty()) {
        InstanceFactory.setRestfulActionMapping(restfulActionMapping);
    }
    logger.warn("RouteHelper Success...");
}
Also used : Action(com.duangframework.mvc.core.Action) Mapping(com.duangframework.core.annotation.mvc.Mapping) Method(java.lang.reflect.Method) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException)

Example 3 with EmptyNullException

use of com.duangframework.core.exceptions.EmptyNullException in project duangframework by tcrct.

the class NettyServiceHandler method handle.

private Object handle(RpcRequest request) throws Throwable {
    RpcAction rpcAction = RpcFactory.getRpcActionMap().get(request.getIface());
    Class<?> ifaceClass = rpcAction.getIface();
    Class<?> serviceClass = rpcAction.getService();
    String methodName = request.getMethodName();
    Class<?>[] parameterTypes = request.getParameterTypes();
    Object[] parameters = request.getParameters();
    Object serviceBean = BeanUtils.getBean(serviceClass);
    if (ToolsKit.isEmpty(serviceBean)) {
        throw new EmptyNullException("serviceBean is null");
    }
    logger.warn("[" + RpcUtils.formatDate(System.currentTimeMillis()) + "] receive rpc request[" + request.getRequestId() + "] :  " + ifaceClass.getName() + "." + methodName);
    Method method = ifaceClass.getMethod(methodName, parameterTypes);
    method.setAccessible(true);
    return method.invoke(serviceBean, parameters);
}
Also used : EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) Method(java.lang.reflect.Method)

Example 4 with EmptyNullException

use of com.duangframework.core.exceptions.EmptyNullException in project duangframework by tcrct.

the class RuleFactory method execute.

/**
 * 执行规则验证
 * @param ruleParams
 * @return
 */
public static RuleResult execute(List<RuleParam> ruleParams) {
    if (ToolsKit.isEmpty(ruleParams)) {
        throw new EmptyNullException("ruleParams is null");
    }
    if (ToolsKit.isEmpty(kieSessionHolder)) {
        throw new EmptyNullException("RuleFactory.kieSessionHolder is null");
    }
    KieSession kieSession = kieSessionHolder.kieSession();
    RuleResult ruleResult = new RuleResult(200, "success");
    try {
        for (RuleParam ruleParam : ruleParams) {
            Map<String, Object> ruleParamsMap = ruleParam.toMap();
            kieSession.insert(ruleParamsMap);
            int ruleFiredCount = kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter(ruleParam.getRuleName()));
            if (ruleFiredCount <= 0) {
                throw new ServiceException().setMessage("verification [" + ruleParam.getRuleName() + "] is not pass!");
            }
        }
    } catch (ServiceException e) {
        ruleResult.setCode(500);
        ruleResult.setMessage(e.getMessage());
        logger.warn(e.getMessage(), e);
    }
    kieSession.destroy();
    return ruleResult;
}
Also used : ServiceException(com.duangframework.core.exceptions.ServiceException) RuleParam(com.duangframework.rule.entity.RuleParam) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) KieSession(org.kie.api.runtime.KieSession) RuleResult(com.duangframework.rule.entity.RuleResult) RuleNameEndsWithAgendaFilter(org.drools.core.base.RuleNameEndsWithAgendaFilter)

Example 5 with EmptyNullException

use of com.duangframework.core.exceptions.EmptyNullException in project duangframework by tcrct.

the class MysqlQuery method append2Mapping.

private void append2Mapping(String key, String oper, Object value) {
    if (ToolsKit.isEmpty(key)) {
        throw new EmptyNullException("query key is null...");
    }
    Map<String, Object> map = null;
    Object obj = queryObj.get(key);
    if (obj instanceof Map) {
        ((Map) obj).put(oper, value);
    } else {
        map = new HashMap<>();
        map.put(oper, value);
        queryObj.put(key, map);
    }
}
Also used : EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)16 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 Mapping (com.duangframework.core.annotation.mvc.Mapping)1 Service (com.duangframework.core.annotation.mvc.Service)1 Rpc (com.duangframework.core.annotation.rpc.Rpc)1 AsyncContext (com.duangframework.core.common.dto.http.request.AsyncContext)1 HttpRequest (com.duangframework.core.common.dto.http.request.HttpRequest)1 HttpResponse (com.duangframework.core.common.dto.http.response.HttpResponse)1 RpcException (com.duangframework.core.exceptions.RpcException)1 ServiceException (com.duangframework.core.exceptions.ServiceException)1 Action (com.duangframework.mvc.core.Action)1 RpcAction (com.duangframework.rpc.common.RpcAction)1 ParamItem (com.duangframework.rule.entity.ParamItem)1 RuleParam (com.duangframework.rule.entity.RuleParam)1 RuleResult (com.duangframework.rule.entity.RuleResult)1 RuleInfoModel (com.duangframework.rule.entity.generate.RuleInfoModel)1 BasicDBObject (com.mongodb.BasicDBObject)1