/** * 字段重复判断。 (区分参数组、参数、参数项的概念) 不同参数的code不可以相同,必须帮助每个参数 的code值对整个参数表中的“参数”唯一 * * @param param */ private void judgeLegit(Param param, int flag) { // 如果保存的是参数(区分参数组、参数、参数项的概念),则要保证code值对所有“参数”唯一 Integer type = param.getType(); if (ParamConstants.NORMAL_PARAM_TYPE.equals(type)) { String hql = "select p.id from Param p where p.type = ? and p.code = ?"; List<?> list = paramDao.getEntities( hql, new Object[] {ParamConstants.NORMAL_PARAM_TYPE, param.getCode()}); if (list.size() > flag) { throw new BusinessException("相同参数名称(指CODE)已经存在,请更改参数名称后再保存!"); } return; } String hql = "select p.id from Param p where p.parentId=" + param.getParentId(); if (ParamConstants.GROUP_PARAM_TYPE.equals(param.getType())) { // 参数组不能同名 hql += " and p.name='" + param.getName() + "'"; } else if (ParamConstants.NORMAL_PARAM_TYPE.equals(param.getType())) { if (EasyUtils.isNullOrEmpty(param.getName())) { param.setName(param.getCode()); } hql += " and (p.name='" + param.getName() + "' or p.code='" + param.getCode() + "')"; } else { if (EasyUtils.isNullOrEmpty(param.getText())) { param.setText(param.getValue()); } Param parentParam = paramDao.getEntity(param.getParentId()); param.setModality(parentParam.getModality()); hql += " and (p.value='" + param.getValue() + "' or p.text='" + param.getText() + "')"; } if (paramDao.getEntities(hql).size() > flag) { throw new BusinessException("字段重复! + " + hql); } }
/** * 得到评论信息 * * @return */ public String getCommentList() { PageInfo pageInfo = null; if (!EasyUtils.isNullOrEmpty(keywords)) { pageInfo = service.searchCommentList(keywords, page); } else { pageInfo = service.getCommentListByArticle(articleId, page); } GridDataEncoder gridEncoder = new GridDataEncoder(pageInfo.getItems(), CMSConstants.GRID_TEMPLATE_COMMENTS); return print(new String[] {"CommentList", "PageList"}, new Object[] {gridEncoder, pageInfo}); }
public void applicationRegisterByXML(Document doc, String applicationType) { List<ResourceType> resourceTypeList = new ArrayList<ResourceType>(); List<ResourceTypeRoot> resourceTypeRootList = new ArrayList<ResourceTypeRoot>(); List<Operation> operationList = new ArrayList<Operation>(); // 解析应用 Application application = new Application(); Element appNode = (Element) doc.selectSingleNode("/application"); BeanUtil.setDataToBean(application, XMLDocUtil.dataNode2Map(appNode)); String applicationId = application.getApplicationId(); // 解析资源类型 List<Element> nodeList = XMLDocUtil.selectNodes(appNode, "resourceType"); for (Element resourceTypeNode : nodeList) { ResourceType resourceType = new ResourceType(); BeanUtil.setDataToBean(resourceType, XMLDocUtil.dataNode2Map(resourceTypeNode)); resourceType.setApplicationId(applicationId); resourceTypeList.add(resourceType); // 解析资源操作选项 List<Element> operationNodeList = XMLDocUtil.selectNodes(resourceTypeNode, "operation"); for (Element operationNode : operationNodeList) { Operation operation = new Operation(); BeanUtil.setDataToBean(operation, XMLDocUtil.dataNode2Map(operationNode)); operation.setApplicationId(applicationId); operation.setResourceTypeId(resourceType.getResourceTypeId()); operationList.add(operation); } } // 解析资源类型根节点 nodeList = XMLDocUtil.selectNodes(appNode, "resourceTypeRoot"); for (Element resourceTypeRootNode : nodeList) { ResourceTypeRoot resourceTypeRootId = new ResourceTypeRoot(); BeanUtil.setDataToBean(resourceTypeRootId, XMLDocUtil.dataNode2Map(resourceTypeRootNode)); resourceTypeRootList.add(resourceTypeRootId); } if (!EasyUtils.isNullOrEmpty(applicationType)) { application.setApplicationType(applicationType); } /** *************************** 仅仅把外部资源注册进来,不进行补全操作 ****************************** */ // 根据应用删除上次因导入失败产生的脏数据 applicationDao.clearDirtyData(applicationId); for (IEntity resourceTypeRoot : resourceTypeRootList) { resourceTypeDao.createObject(resourceTypeRoot); // 初始化资源类型根节点 } for (ResourceType resourceType : resourceTypeList) { String resourceTypeId = resourceType.getResourceTypeId(); ResourceTypeRoot resourceTypeRoot = resourceTypeDao.getResourceTypeRoot(applicationId, resourceTypeId); if (resourceTypeRoot != null) { resourceType.setRootId(resourceTypeRoot.getRootId()); } resourceTypeDao.create(resourceType); // 初始化资源类型 } for (Operation operation : operationList) { resourceTypeDao.createObject(operation); // 初始化权限选项 } /** *************************** 对外部已经注册的资源进行补全操作 *********************************** */ if (!initial) { permissionService = PermissionHelper.getPermissionService(applicationId, permissionService); } // 初始化资源类型 for (ResourceType resourceType : resourceTypeList) { /* 保存资源类型,同时还要为该类型资源建立一个根节点,以资源类型名字作为根节点名字 */ String resourceTypeId = resourceType.getResourceTypeId(); String unSuppliedTable = resourceTypeDao.getUnSuppliedTable(applicationId, resourceTypeId); String suppliedTable = resourceTypeDao.getSuppliedTable(applicationId, resourceTypeId); String initPermission = Config.getAttribute("initPermission"); if (Config.TRUE.equalsIgnoreCase(initPermission)) { permissionService.clearPermissionData(unSuppliedTable); permissionService.clearPermissionData(suppliedTable); } } // 初始化权限选项 for (Operation operation : operationList) { /* 让管理员角色拥有新添加的权限选项,即:让管理员拥有对资源 根节点 有permissionState=2的权限 */ String resourceTypeId = operation.getResourceTypeId(); ResourceTypeRoot resourceTypeRoot = resourceTypeDao.getResourceTypeRoot(applicationId, resourceTypeId); if (resourceTypeRoot != null) { String unSuppliedTable = resourceTypeDao.getUnSuppliedTable(applicationId, resourceTypeId); String suppliedTable = resourceTypeDao.getSuppliedTable(applicationId, resourceTypeId); String resourceTable = resourceTypeDao.getResourceTable(applicationId, resourceTypeId); permissionService.saveRoleResourceOperation( UMConstants.ADMIN_ROLE_ID, resourceTypeRoot.getRootId(), operation.getOperationId(), UMConstants.PERMIT_SUB_TREE, unSuppliedTable, suppliedTable, resourceTable); } } // 初始化平台应用系统,应用系统作为一类资源,需要做补全操作的,所以最后保存 application.setSeqNo(applicationDao.getNextSeqNo(new Long(UMConstants.PLATFORM_SYSTEM_APP))); applicationDao.create(application); }
public Object[] getCanAddParams(Integer mode) { List<?> paramAndGroups = paramDao.getCanAddParamsAndGroups(mode); List<?> paramIds = paramDao.getCanAddParams(mode); return new Object[] {paramAndGroups, EasyUtils.list2Str(paramIds)}; }