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;
}
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...");
}
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);
}
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;
}
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);
}
}
Aggregations