/
FileUtils.java
668 lines (620 loc) · 26.8 KB
/
FileUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
package io.metersphere.commons.utils;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.commons.constants.StorageConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import io.metersphere.metadata.service.FileMetadataService;
import io.metersphere.request.BodyFile;
import io.metersphere.service.JarConfigService;
import io.metersphere.utils.LoggerUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
import org.apache.jorphan.collections.HashTree;
import org.aspectj.util.FileUtil;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class FileUtils {
public static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
public static final String MD_IMAGE_DIR = "/opt/metersphere/data/image/markdown";
public static final String UI_IMAGE_DIR = "/opt/metersphere/data/image/ui/screenshots";
public static final String ATTACHMENT_DIR = "/opt/metersphere/data/attachment";
public static final String ATTACHMENT_TMP_DIR = "/opt/metersphere/data/attachment/tmp";
public static void validateFileName(String fileName) {
if (StringUtils.isNotEmpty(fileName) && fileName.contains(File.separator)) {
MSException.throwException(Translator.get("invalid_parameter"));
}
}
public static byte[] listBytesToZip(Map<String, byte[]> mapReport) {
try {
if (!mapReport.isEmpty()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
for (Map.Entry<String, byte[]> report : mapReport.entrySet()) {
ZipEntry entry = new ZipEntry(report.getKey());
entry.setSize(report.getValue().length);
zos.putNextEntry(entry);
zos.write(report.getValue());
}
zos.closeEntry();
zos.close();
return baos.toByteArray();
}
} catch (Exception e) {
return new byte[10];
}
return new byte[10];
}
public static void createFile(String filePath, byte[] fileBytes) {
validateFileName(filePath);
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
File dir = file.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
file.createNewFile();
} catch (Exception e) {
LogUtil.error(e);
}
try (InputStream in = new ByteArrayInputStream(fileBytes); OutputStream out = new FileOutputStream(file)) {
final int MAX = 4096;
byte[] buf = new byte[MAX];
for (int bytesRead = in.read(buf, 0, MAX); bytesRead != -1; bytesRead = in.read(buf, 0, MAX)) {
out.write(buf, 0, bytesRead);
}
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
}
private static void create(List<String> bodyUploadIds, List<MultipartFile> bodyFiles, String path) {
String filePath = BODY_FILE_DIR;
if (StringUtils.isNotEmpty(path)) {
filePath = path;
}
if (CollectionUtils.isNotEmpty(bodyUploadIds) && CollectionUtils.isNotEmpty(bodyFiles)) {
File testDir = new File(filePath);
if (!testDir.exists()) {
testDir.mkdirs();
}
for (int i = 0; i < bodyUploadIds.size(); i++) {
MultipartFile item = bodyFiles.get(i);
validateFileName(item.getOriginalFilename());
File file = new File(filePath + File.separator + bodyUploadIds.get(i) + "_" + item.getOriginalFilename());
try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
final int MAX = 4096;
byte[] buf = new byte[MAX];
for (int bytesRead = in.read(buf, 0, MAX); bytesRead != -1; bytesRead = in.read(buf, 0, MAX)) {
out.write(buf, 0, bytesRead);
}
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
}
}
}
public static String create(String id, MultipartFile item) {
String filePath = BODY_FILE_DIR + "/plugin";
if (item != null) {
validateFileName(item.getOriginalFilename());
File testDir = new File(filePath);
if (!testDir.exists()) {
testDir.mkdirs();
}
File file = new File(filePath + File.separator + id + "_" + item.getOriginalFilename());
try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
final int MAX = 4096;
byte[] buf = new byte[MAX];
for (int bytesRead = in.read(buf, 0, MAX); bytesRead != -1; bytesRead = in.read(buf, 0, MAX)) {
out.write(buf, 0, bytesRead);
}
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
return file.getPath();
}
return null;
}
public static void createBodyFiles(String requestId, List<MultipartFile> bodyFiles) {
if (CollectionUtils.isNotEmpty(bodyFiles) && StringUtils.isNotBlank(requestId)) {
String path = BODY_FILE_DIR + File.separator + requestId;
File testDir = new File(path);
if (!testDir.exists()) {
testDir.mkdirs();
}
bodyFiles.forEach(item -> {
validateFileName(item.getOriginalFilename());
File file = new File(path + File.separator + item.getOriginalFilename());
try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
FileUtil.copyStream(in, out);
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
});
}
}
public static void copyBodyFiles(String sourceId, String targetId) {
try {
String sourcePath = BODY_FILE_DIR + File.separator + sourceId;
String targetPath = BODY_FILE_DIR + File.separator + targetId;
copyFolder(sourcePath, targetPath);
} catch (Exception e) {
LoggerUtil.error(e);
}
}
/**
* 复制文件夹(使用缓冲字节流)
*
* @param sourcePath 源文件夹路径
* @param targetPath 目标文件夹路径
*/
public static void copyFolder(String sourcePath, String targetPath) {
//源文件夹路径
File sourceFile = new File(sourcePath);
//目标文件夹路径
File targetFile = new File(targetPath);
if (!sourceFile.exists() || !sourceFile.isDirectory()) {
return;
}
if (!targetFile.exists()) {
targetFile.mkdirs();
}
File[] files = sourceFile.listFiles();
if (files == null || files.length == 0) {
return;
}
for (File file : files) {
copyFileToDir(file, targetFile);
}
}
public static void copyFileToDir(String filePath, String targetPath) {
//源文件路径
File sourceFile = new File(filePath);
//目标文件夹路径
File targetDir = new File(targetPath);
if (!sourceFile.exists()) {
return;
}
if (!targetDir.exists()) {
targetDir.mkdirs();
}
copyFileToDir(sourceFile, targetDir);
}
private static void copyFileToDir(File file, File targetDir) {
//文件要移动的路径
String movePath = targetDir + File.separator + file.getName();
if (file.isDirectory()) {
//如果是目录则递归调用
copyFolder(file.getAbsolutePath(), movePath);
} else {
//如果是文件则复制文件
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(movePath))) {
byte[] b = new byte[1024];
int temp;
while ((temp = in.read(b)) != -1) {
out.write(b, 0, temp);
}
} catch (Exception e) {
LoggerUtil.error(e);
}
}
}
public static File getFileByName(String name) {
String path = BODY_FILE_DIR + File.separator + name;
return new File(path);
}
public static File getBodyFileByName(String name, String requestId) {
String path = BODY_FILE_DIR + File.separator + requestId + File.separator + name;
return new File(path);
}
public static void copyBdyFile(String originId, String toId) {
try {
if (StringUtils.isNotEmpty(originId) && StringUtils.isNotEmpty(toId) && !StringUtils.equals(originId, toId)) {
FileUtil.copyDir(new File(FileUtils.BODY_FILE_DIR + File.separator + originId),
new File(FileUtils.BODY_FILE_DIR + File.separator + toId));
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
}
public static void createBodyFiles(List<String> bodyUploadIds, List<MultipartFile> bodyFiles) {
FileUtils.create(bodyUploadIds, bodyFiles, null);
}
public static void createFiles(List<String> bodyUploadIds, List<MultipartFile> bodyFiles, String path) {
FileUtils.create(bodyUploadIds, bodyFiles, path);
}
public static String createFile(MultipartFile bodyFile) {
validateFileName(bodyFile.getOriginalFilename());
String dir = "/opt/metersphere/data/body/tmp/";
File fileDir = new File(dir);
if (!fileDir.exists()) {
fileDir.mkdirs();
}
File file = new File(dir + UUID.randomUUID().toString() + "_" + bodyFile.getOriginalFilename());
try (InputStream in = bodyFile.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
FileUtil.copyStream(in, out);
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
return file.getPath();
}
public static void deleteBodyFiles(String requestId) {
File file = new File(BODY_FILE_DIR + File.separator + requestId);
FileUtil.deleteContents(file);
if (file.exists()) {
file.delete();
}
//删除临时目录中的文件
file = new File(BODY_FILE_DIR + File.separator + "tmp" + File.separator + requestId);
FileUtil.deleteContents(file);
if (file.exists()) {
file.delete();
}
}
public static String uploadFile(MultipartFile uploadFile, String path, String name) {
validateFileName(name);
if (uploadFile == null) {
return null;
}
File testDir = new File(path);
if (!testDir.exists()) {
testDir.mkdirs();
}
String filePath = testDir + File.separator + name;
File file = new File(filePath);
try (InputStream in = uploadFile.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
FileUtil.copyStream(in, out);
} catch (IOException e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("upload_fail"));
}
return filePath;
}
public static String uploadFile(MultipartFile uploadFile, String path) {
return uploadFile(uploadFile, path, uploadFile.getOriginalFilename());
}
public static void deleteFile(String path) {
File file = new File(path);
if (file.exists()) {
file.delete();
}
}
public static void deleteDir(String path) {
File file = new File(path);
FileUtil.deleteContents(file);
if (file.exists()) {
file.delete();
}
}
/**
* 获取当前jmx 涉及到的文件
*
* @param tree
*/
public static void getFiles(HashTree tree, List<BodyFile> files) {
for (Object key : tree.keySet()) {
HashTree node = tree.get(key);
if (key instanceof HTTPSamplerProxy) {
HTTPSamplerProxy source = (HTTPSamplerProxy) key;
if (source != null && source.getHTTPFiles().length > 0) {
for (HTTPFileArg arg : source.getHTTPFiles()) {
BodyFile file = new BodyFile();
file.setId(arg.getParamName());
file.setName(arg.getPath());
if (arg.getPropertyAsBoolean("isRef")) {
file.setStorage(StorageConstants.FILE_REF.name());
file.setFileId(arg.getPropertyAsString("fileId"));
}
files.add(file);
}
}
} else if (key instanceof CSVDataSet) {
CSVDataSet source = (CSVDataSet) key;
if (source != null && StringUtils.isNotEmpty(source.getPropertyAsString("filename"))) {
BodyFile file = new BodyFile();
file.setId(source.getPropertyAsString("filename"));
file.setName(source.getPropertyAsString("filename"));
files.add(file);
}
}
if (node != null) {
getFiles(node, files);
}
}
}
/**
* 获取当前jmx 涉及到的文件 执行时
*
* @param tree
*/
public static void getExecuteFiles(HashTree tree, String reportId, List<BodyFile> files) {
FileMetadataService fileMetadataService = CommonBeanFactory.getBean(FileMetadataService.class);
for (Object key : tree.keySet()) {
HashTree node = tree.get(key);
if (key instanceof HTTPSamplerProxy) {
HTTPSamplerProxy source = (HTTPSamplerProxy) key;
if (source != null && source.getHTTPFiles().length > 0) {
for (HTTPFileArg arg : source.getHTTPFiles()) {
BodyFile file = new BodyFile();
file.setId(arg.getParamName());
file.setName(arg.getPath());
if (arg.getPropertyAsBoolean("isRef") && fileMetadataService != null) {
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(arg.getPropertyAsString("fileId"));
if (fileMetadata != null && !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
file.setStorage(fileMetadata.getStorage());
file.setFileId(arg.getPropertyAsString("fileId"));
file.setName(reportId + File.separator + fileMetadata.getName());
arg.setPath(BODY_FILE_DIR + File.separator + reportId + File.separator + fileMetadata.getName());
}
}
files.add(file);
}
}
} else if (key instanceof CSVDataSet) {
CSVDataSet source = (CSVDataSet) key;
if (source != null && StringUtils.isNotEmpty(source.getPropertyAsString("filename"))) {
BodyFile file = new BodyFile();
file.setId(source.getPropertyAsString("filename"));
file.setName(source.getPropertyAsString("filename"));
if (source.getPropertyAsBoolean("isRef") && fileMetadataService != null) {
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(source.getPropertyAsString("fileId"));
if (fileMetadata != null && !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
file.setStorage(fileMetadata.getStorage());
file.setFileId(source.getPropertyAsString("fileId"));
file.setName(reportId + File.separator + fileMetadata.getName());
((CSVDataSet) key).setProperty("filename", BODY_FILE_DIR + File.separator + reportId + File.separator + fileMetadata.getName());
}
}
files.add(file);
}
}
if (node != null) {
getExecuteFiles(node, reportId, files);
}
}
}
public static byte[] fileToByte(File tradeFile) {
byte[] buffer = null;
try (FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
buffer = bos.toByteArray();
} catch (Exception e) {
LogUtil.error(e);
}
return buffer;
}
public static File byteToFile(byte[] buf, String filePath, String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File dir = new File(filePath);
if (!dir.exists()) {
dir.mkdirs();
}
file = new File(filePath + File.separator + fileName);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(buf);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return file;
}
public static String fileToStr(File tradeFile) {
String buffer = null;
try (FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
buffer = bos.toString();
} catch (Exception e) {
}
return buffer;
}
public static List<FileMetadata> getRepositoryFileMetadata(HashTree tree) {
FileMetadataService fileMetadataService = CommonBeanFactory.getBean(FileMetadataService.class);
List<FileMetadata> list = new ArrayList<>();
for (Object key : tree.keySet()) {
HashTree node = tree.get(key);
if (key instanceof HTTPSamplerProxy) {
HTTPSamplerProxy source = (HTTPSamplerProxy) key;
if (source != null && source.getHTTPFiles().length > 0) {
for (HTTPFileArg arg : source.getHTTPFiles()) {
if (arg.getPropertyAsBoolean("isRef") && fileMetadataService != null) {
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(arg.getPropertyAsString("fileId"));
if (fileMetadata != null && !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
list.add(fileMetadata);
arg.setPath(fileMetadata.getName());
arg.setName(fileMetadata.getName());
}
}
}
}
} else if (key instanceof CSVDataSet) {
CSVDataSet source = (CSVDataSet) key;
if (source != null && StringUtils.isNotEmpty(source.getPropertyAsString("filename"))) {
if (source.getPropertyAsBoolean("isRef") && fileMetadataService != null) {
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(source.getPropertyAsString("fileId"));
if (fileMetadata != null && !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
list.add(fileMetadata);
source.setFilename(fileMetadata.getName());
}
}
}
}
if (node != null) {
list.addAll(getRepositoryFileMetadata(node));
}
}
return list;
}
public static boolean isFolderExists(String requestId) {
File file = new File(BODY_FILE_DIR + File.separator + requestId);
return file.isDirectory();
}
public List<Object> getZipJar() {
List<Object> jarFiles = new LinkedList<>();
// jar 包
JarConfigService jarConfigService = CommonBeanFactory.getBean(JarConfigService.class);
List<JarConfig> jars = jarConfigService.list();
List<File> files = new ArrayList<>();
jars.forEach(jarConfig -> {
String path = jarConfig.getPath();
File file = new File(path);
if (file.isDirectory() && !path.endsWith(File.separator)) {
file = new File(path + File.separator);
}
files.add(file);
});
try {
File file = CompressUtils.zipFiles(UUID.randomUUID().toString() + ".zip", files);
FileSystemResource resource = new FileSystemResource(file);
byte[] fileByte = this.fileToByte(file);
if (fileByte != null) {
ByteArrayResource byteArrayResource = new ByteArrayResource(fileByte) {
@Override
public String getFilename() throws IllegalStateException {
return resource.getFilename();
}
};
jarFiles.add(byteArrayResource);
}
} catch (Exception e) {
LogUtil.error(e);
}
return jarFiles;
}
public List<Object> getJar() {
List<Object> jarFiles = new LinkedList<>();
// jar 包
JarConfigService jarConfigService = CommonBeanFactory.getBean(JarConfigService.class);
List<JarConfig> jars = jarConfigService.list();
jars.forEach(jarConfig -> {
try {
String path = jarConfig.getPath();
File file = new File(path);
if (file.isDirectory() && !path.endsWith(File.separator)) {
file = new File(path + File.separator);
}
FileSystemResource resource = new FileSystemResource(file);
byte[] fileByte = this.fileToByte(file);
if (fileByte != null) {
ByteArrayResource byteArrayResource = new ByteArrayResource(fileByte) {
@Override
public String getFilename() throws IllegalStateException {
return resource.getFilename();
}
};
jarFiles.add(byteArrayResource);
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
});
return jarFiles;
}
public List<Object> getMultipartFiles(HashTree hashTree) {
List<Object> multipartFiles = new LinkedList<>();
// 获取附件
List<BodyFile> files = new LinkedList<>();
getFiles(hashTree, files);
if (CollectionUtils.isNotEmpty(files)) {
for (BodyFile bodyFile : files) {
File file = new File(bodyFile.getName());
if (file != null && !file.exists()) {
FileSystemResource resource = new FileSystemResource(file);
byte[] fileByte = this.fileToByte(file);
if (fileByte != null) {
ByteArrayResource byteArrayResource = new ByteArrayResource(fileByte) {
@Override
public String getFilename() throws IllegalStateException {
return resource.getFilename();
}
};
multipartFiles.add(byteArrayResource);
}
}
}
}
return multipartFiles;
}
public static Boolean writeToFile(String filePath, byte[] content) {
OutputStream oStream = null;
try {
oStream = new FileOutputStream(filePath);
oStream.write(content);
return Boolean.TRUE;
} catch (Exception exception) {
exception.printStackTrace();
return Boolean.FALSE;
} finally {
try {
oStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getFilePath(BodyFile file) {
String type = StringUtils.isNotEmpty(file.getFileType()) ? file.getFileType().toLowerCase() : null;
String name = file.getName();
if (type != null && !name.endsWith(type)) {
name = StringUtils.join(name, ".", type);
}
return StringUtils.join(FileUtils.BODY_FILE_DIR, File.separator, file.getProjectId(), File.separator, name);
}
public static String getFilePath(FileMetadata fileMetadata) {
String type = StringUtils.isNotEmpty(fileMetadata.getType()) ? fileMetadata.getType().toLowerCase() : null;
String name = fileMetadata.getName();
if (type != null && !name.endsWith(type)) {
name = StringUtils.join(name, ".", type);
}
return StringUtils.join(FileUtils.BODY_FILE_DIR, File.separator, fileMetadata.getProjectId(), File.separator, name);
}
}