/** * ************************************************************************* 返回的分类列表 * * @return */ public IPropertySelectionModel getPrivileges() { List<ResourceType> resourcetype = getResourceService() .findResourceTypeBy(1, Integer.MAX_VALUE, "id", false, getSearchExpressions()); // 过滤掉父类对象,只放子类的对象------------------------------ Set<ResourceType> parentType = new HashSet<ResourceType>(); for (ResourceType type : resourcetype) { if (type.getParent() != null) { parentType.add(type.getParent()); } } if (parentType != null) { for (ResourceType parent : parentType) { resourcetype.remove(parent); } } // ------------------------------------------------------ ObjectPropertySelectionModel model = new ObjectPropertySelectionModel( resourcetype, ResourceType.class, "getName", "getId", false, null); return model; }
@Override protected boolean persist(Object object) { try { NewsPapers newsPapers = (NewsPapers) object; String errorMessage = ""; if (!isModelNew()) { if (getUploadFileImage() != null) { // 上传了封面图片 File dir = new File(getResourceService().getChapterAddress(newsPapers.getId())); if (!dir.exists()) dir.mkdirs(); String uploadfileName = getUploadFileImage() .getFileName() .substring(getUploadFileImage().getFileName().lastIndexOf("\\") + 1); boolean resIsRightFormat = isRightFormat(uploadfileName); if (!resIsRightFormat) { // 文件格式判断 throw new Exception("图片格式不正确[gif/jpg/png],请重新选择!"); } if (dir.exists()) { // 删除文件 for (File file : dir.listFiles()) { if (file.getName().startsWith("cover")) { getResourceService().deleteFile(file.toString()); // 同步删除图片: getResourceService() .rsyncUploadFile( ResourceUtil.RSYNC_TYPE_DEL, new String[] {file.getAbsolutePath()}); } } } errorMessage = getResourceService().upload(getUploadFileImage(), "", dir); if (!"".equals(errorMessage)) throw new Exception(errorMessage); // 给文件重命名: File file = new File(dir + File.separator + uploadfileName); // 上传到服务器的文件名称 String fileName = "cover." + uploadfileName.split("\\.")[1]; File newFile = new File(dir + File.separator + fileName); file.renameTo(newFile); getUploadService().resizeCoverFile(dir.toString(), fileName); newsPapers.setImage(fileName); // 同步图片: getUploadService().rsyncDirectry(dir); } // ___________新增_______________ Integer copyrighId = getCopyrightId(); if (copyrighId != null && !"".equals(copyrighId)) { if (!copyrighId.equals(newsPapers.getCopyrightId())) { // 表明修改了 newsPapers.setLastCopyrightId(newsPapers.getCopyrightId()); newsPapers.setCopyrightId(copyrighId); } } UserImpl user = (UserImpl) getUser(); newsPapers.setModifierId(user.getId()); if (selectedResourceType.size() == 0) throw new Exception("请选择资源分类!"); getResourceService().updateResource(newsPapers, ResourceAll.RESOURCE_TYPE_NEWSPAPER); // 根据资源id将引用关系先删除 getResourceService().deleteResourceResType(newsPapers.getId()); // 添加资源与资源列表关系表 for (int i = 0; i < selectedResourceType.size(); i++) { ResourceType type = (ResourceType) selectedResourceType.get(i); ResourceResType rel = new ResourceResType(); rel.setRid(newsPapers.getId()); rel.setResTypeId(type.getId()); getResourceService().addResourceResType(rel); } } } catch (Exception e) { getDelegate().setFormComponent(null); getDelegate().record(e.getMessage(), null); return false; } return true; }