Search in sources :

Example 1 with BaseNodeModel

use of io.jpom.model.BaseNodeModel in project Jpom by dromara.

the class PermissionInterceptor method checkNodeDataPermission.

/**
 * 检查管理员权限
 *
 * @param userModel     用户
 * @param response      响应
 * @param handlerMethod 拦截到到方法
 * @return true 有权限
 */
private boolean checkNodeDataPermission(UserModel userModel, HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) {
    NodeDataPermission nodeDataPermission = this.getNodeDataPermission(handlerMethod);
    if (nodeDataPermission == null || userModel.isSuperSystemUser()) {
        return true;
    }
    NodeModel node = (NodeModel) request.getAttribute("node");
    if (node != null) {
        String parameterName = nodeDataPermission.parameterName();
        BaseNodeService<?> baseNodeService = SpringUtil.getBean(nodeDataPermission.cls());
        String dataId = request.getParameter(parameterName);
        if (StrUtil.isNotEmpty(dataId)) {
            BaseNodeModel data = baseNodeService.getData(node.getId(), dataId);
            if (data != null) {
                boolean exists = userBindWorkspaceService.exists(userModel.getId(), data.getWorkspaceId());
                if (!exists) {
                    this.errorMsg(response, "您没有对应到数据权限:-3");
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : BaseNodeModel(io.jpom.model.BaseNodeModel) NodeModel(io.jpom.model.data.NodeModel) BaseNodeModel(io.jpom.model.BaseNodeModel) NodeDataPermission(io.jpom.permission.NodeDataPermission)

Example 2 with BaseNodeModel

use of io.jpom.model.BaseNodeModel in project Jpom by dromara.

the class BaseNodeService method syncExecuteNode.

/**
 * 同步执行 同步节点信息
 *
 * @param nodeModel 节点信息
 * @return json
 */
public String syncExecuteNode(NodeModel nodeModel) {
    String nodeModelName = nodeModel.getName();
    if (!nodeModel.isOpenStatus()) {
        DefaultSystemLog.getLog().debug("{} 节点未启用", nodeModelName);
        return "节点未启用";
    }
    try {
        JSONArray jsonArray = this.getLitDataArray(nodeModel);
        if (CollUtil.isEmpty(jsonArray)) {
            Entity entity = Entity.create();
            entity.set("nodeId", nodeModel.getId());
            int del = super.del(entity);
            // 
            DefaultSystemLog.getLog().debug("{} 节点没有拉取到任何{}", nodeModelName, dataName);
            return "节点没有拉取到任何" + dataName;
        }
        // 查询现在存在的项目
        T where = ReflectUtil.newInstance(this.tClass);
        where.setWorkspaceId(nodeModel.getWorkspaceId());
        where.setNodeId(nodeModel.getId());
        List<T> cacheAll = super.listByBean(where);
        cacheAll = ObjectUtil.defaultIfNull(cacheAll, Collections.EMPTY_LIST);
        Set<String> cacheIds = cacheAll.stream().map(BaseNodeModel::dataId).collect(Collectors.toSet());
        // 
        List<T> projectInfoModels = jsonArray.toJavaList(this.tClass);
        List<T> models = projectInfoModels.stream().peek(item -> this.fullData(item, nodeModel)).filter(item -> {
            // 检查对应的工作空间 是否存在
            return workspaceService.exists(new WorkspaceModel(item.getWorkspaceId()));
        }).filter(projectInfoModel -> {
            // 避免重复同步
            return StrUtil.equals(nodeModel.getWorkspaceId(), projectInfoModel.getWorkspaceId());
        }).peek(item -> cacheIds.remove(item.dataId())).collect(Collectors.toList());
        // 设置 临时缓存,便于放行检查
        BaseServerController.resetInfo(UserModel.EMPTY);
        // 
        models.forEach(BaseNodeService.super::upsert);
        // 删除项目
        Set<String> strings = cacheIds.stream().map(s -> BaseNodeModel.fullId(nodeModel.getWorkspaceId(), nodeModel.getId(), s)).collect(Collectors.toSet());
        if (CollUtil.isNotEmpty(strings)) {
            super.delByKey(strings, null);
        }
        String format = StrUtil.format("{} 节点拉取到 {} 个{},已经缓存 {} 个{},更新 {} 个{},删除 {} 个缓存", nodeModelName, CollUtil.size(jsonArray), dataName, CollUtil.size(cacheAll), dataName, CollUtil.size(models), dataName, CollUtil.size(strings));
        DefaultSystemLog.getLog().debug(format);
        return format;
    } catch (Exception e) {
        return this.checkException(e, nodeModelName);
    } finally {
        BaseServerController.removeEmpty();
    }
}
Also used : PageResultDto(io.jpom.model.PageResultDto) ObjectUtil(cn.hutool.core.util.ObjectUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JSONArray(com.alibaba.fastjson.JSONArray) HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeService(io.jpom.service.node.NodeService) Map(java.util.Map) BaseNodeModel(io.jpom.model.BaseNodeModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) NodeModel(io.jpom.model.data.NodeModel) Set(java.util.Set) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) Collectors(java.util.stream.Collectors) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Const(io.jpom.common.Const) ReflectUtil(cn.hutool.core.util.ReflectUtil) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) ThreadUtil(cn.hutool.core.thread.ThreadUtil) UserModel(io.jpom.model.data.UserModel) AgentException(io.jpom.system.AgentException) Collections(java.util.Collections) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) Entity(cn.hutool.db.Entity) WorkspaceModel(io.jpom.model.data.WorkspaceModel) JSONArray(com.alibaba.fastjson.JSONArray) AgentException(io.jpom.system.AgentException)

Aggregations

BaseNodeModel (io.jpom.model.BaseNodeModel)2 NodeModel (io.jpom.model.data.NodeModel)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ThreadUtil (cn.hutool.core.thread.ThreadUtil)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 ReflectUtil (cn.hutool.core.util.ReflectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 Entity (cn.hutool.db.Entity)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1 SpringUtil (cn.jiangzeyin.common.spring.SpringUtil)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseServerController (io.jpom.common.BaseServerController)1 Const (io.jpom.common.Const)1 PageResultDto (io.jpom.model.PageResultDto)1 UserModel (io.jpom.model.data.UserModel)1 WorkspaceModel (io.jpom.model.data.WorkspaceModel)1 NodeDataPermission (io.jpom.permission.NodeDataPermission)1 NodeService (io.jpom.service.node.NodeService)1