| | |
| | | /** |
| | | * 查询文件 |
| | | */ |
| | | public List<MetaFileEntity> selectFiles(String subPath) { |
| | | public List<MetaFileEntity> selectFiles(String subPath, boolean hasMd5) { |
| | | String root = pathHelper.getConfig().getTempPath() + File.separator + subPath; |
| | | |
| | | File file = new File(root); |
| | |
| | | for (File f : files) { |
| | | String fileName = FileHelper.getFileName(f.getPath()); |
| | | String extName = FileHelper.getExtension(fileName); |
| | | if (!isExtValid(extName)) { |
| | | if (!isFileValid(f.getName())) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | mf.setExtName(extName); |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setPath(subPath + File.separator + fileName); |
| | | if (!StaticData.ZIP.equals(extName)) { |
| | | if (hasMd5 && !StaticData.ZIP.equals(extName)) { |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | } |
| | | |
| | |
| | | * 查询映射 |
| | | */ |
| | | public List<MetaFileEntity> selectMappers(UserEntity ue, String path, DirEntity dir, VerEntity ver, String epsgCode) { |
| | | List<MetaFileEntity> metas = selectFiles(path); |
| | | List<MetaFileEntity> metas = selectFiles(path, true); |
| | | if (null == metas || metas.isEmpty()) { |
| | | return null; |
| | | } |
| | |
| | | private void getFilesByPath(List<File> list, String path) { |
| | | File file = new File(path); |
| | | if (!file.isDirectory()) { |
| | | String extName = FileHelper.getExtension(file); |
| | | if (isExtValid(extName)) { |
| | | if (isFileValid(file.getName())) { |
| | | list.add(file); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (isGdbFile(file)) { |
| | | if (isGdbFile(file) || isOsgbFile(file)) { |
| | | list.add(file); |
| | | return; |
| | | } |
| | |
| | | if (f.isDirectory()) { |
| | | getFilesByPath(list, f.getPath()); |
| | | } else { |
| | | String extName = FileHelper.getExtension(f); |
| | | if (isExtValid(extName)) { |
| | | if (isFileValid(f.getName())) { |
| | | list.add(f); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 扩展是否有效 |
| | | * 文件是/否有效 |
| | | */ |
| | | private boolean isExtValid(String extName) { |
| | | return StaticData.ALL_EXTENSION.contains(extName) && !StaticData.MAPPER_EXCLUDE_EXT.contains(extName); |
| | | private boolean isFileValid(String fileName) { |
| | | String extName = FileHelper.getExtension(fileName); |
| | | if (fileName.startsWith(StaticData.TILDE) || !StaticData.ALL_EXTENSION.contains(extName)) { |
| | | return false; |
| | | } |
| | | |
| | | fileName = fileName.toLowerCase(); |
| | | for (String ext : StaticData.MAPPER_EXCLUDE_EXT) { |
| | | if (fileName.contains(ext)) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | for (File f : files) { |
| | | boolean isGdb = isGdbFile(f); |
| | | if (!isGdb && f.isDirectory()) { |
| | | boolean isOsgb = isOsgbFile(f); |
| | | boolean isFile = isGdb || isOsgb; |
| | | if (f.isDirectory() && !isFile) { |
| | | continue; |
| | | } |
| | | |
| | | String fileName = FileHelper.getFileName(f.getPath()); |
| | | String extName = FileHelper.getExtension(fileName); |
| | | if (!isExtValid(extName) || fileName.startsWith("~")) { |
| | | String extName = isOsgb ? StaticData.OSGB : FileHelper.getExtension(fileName); |
| | | if (!isFileValid(f.getName())) { |
| | | continue; |
| | | } |
| | | |
| | | String dircode = getDirByPath(f.getPath(), fileName, dir, dirs); |
| | | boolean isShp = StaticData.SHP.equals(extName); |
| | | if (isGdb) { |
| | | List<MetaFileEntity> rs = getGdbMappers(f, meta, dircode, start); |
| | | if (null != rs && rs.size() > 0) { |
| | |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setDircode(dircode); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setExtName(extName); |
| | | mf.setPath(f.getPath().substring(start)); |
| | | |
| | | if (isShp) { |
| | | List<String> shpFiles = getShpFiles(f.getPath()); |
| | | mf.setTab(fileName.replace(StaticData.SHP, "")); |
| | | mf.setSizes(getFilesSize(shpFiles)); |
| | | mf.setGuid(getFilesMd5(shpFiles)); |
| | | } else { |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | if (isOsgb) { |
| | | list.add(getOsgbMapper(f, meta, dircode, start)); |
| | | continue; |
| | | } |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(f, meta, fileName, extName); |
| | | mf.setPath(f.getPath().substring(start)); |
| | | mf.setDircode(dircode); |
| | | list.add(mf); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 创建元数据文件实体类 |
| | | */ |
| | | private MetaFileEntity createMetaFileEntity(File f, MetaFileEntity meta, String fileName, String extName) { |
| | | boolean isShp = StaticData.SHP.equals(extName); |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setExtName(extName); |
| | | |
| | | if (isShp) { |
| | | List<String> shpFiles = getShpFiles(f.getPath()); |
| | | mf.setTab(fileName.replace(StaticData.SHP, "")); |
| | | mf.setSizes(getFilesSize(shpFiles)); |
| | | mf.setGuid(getFilesMd5(shpFiles)); |
| | | } else { |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | } |
| | | |
| | | return mf; |
| | | } |
| | | |
| | | /** |
| | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setDircode(dircode); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setName(fileName + "\\" + tab); |
| | | mf.setExtName(extName); |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setPath(f.getPath().substring(start)); |
| | |
| | | */ |
| | | private boolean isGdbFile(File f) { |
| | | if (f.isDirectory() && f.getName().toLowerCase().endsWith(StaticData.GDB)) { |
| | | File[] files = f.listFiles(); |
| | | if (null == files || files.length == 0) { |
| | | return false; |
| | | } |
| | | File gdb = new File(f.getPath() + File.separator + "gdb"); |
| | | |
| | | for (File file : files) { |
| | | if ("gdb".equals(file.getName())) { |
| | | return true; |
| | | } |
| | | } |
| | | return gdb.exists() && !gdb.isDirectory(); |
| | | } |
| | | |
| | | return false; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 是/否为OSGB文件 |
| | | */ |
| | | private boolean isOsgbFile(File f) { |
| | | if (f.isDirectory()) { |
| | | File meta = new File(f.getPath() + File.separator + "metadata.xml"); |
| | | File data = new File(f.getPath() + File.separator + "Data"); |
| | | |
| | | return meta.exists() && !meta.isDirectory() && data.exists() && data.isDirectory(); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取OSGB文件映射 |
| | | */ |
| | | private MetaFileEntity getOsgbMapper(File f, MetaFileEntity meta, String dircode, int start) { |
| | | String fileName = FileHelper.getFileName(f.getPath()); |
| | | |
| | | List<String> files = new ArrayList<>(); |
| | | FileHelper.getFilesByPath(files, f.getPath()); |
| | | |
| | | String md5 = getFilesMd5(files); |
| | | double sizes = getFilesSize(files); |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setDircode(dircode); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setExtName(StaticData.OSGB); |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setPath(f.getPath().substring(start)); |
| | | mf.setSizes(sizes); |
| | | mf.setGuid(md5); |
| | | |
| | | return mf; |
| | | } |
| | | |
| | | /** |
| | | * 获取参数 * |
| | | * Enumeration<String> headers = req.getHeaderNames(); |
| | | * Enumeration<String> attributes = req.getAttributeNames(); |