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