Skip to content

Commit

Permalink
Fix StorageFileInfo param error in init method (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivershen-wow authored Mar 7, 2023
1 parent d85a1da commit 3a45a57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Result add(@CurrentSecurityContext SysUser requestor,
commitCountInt);// CodeQL [java/log-injection] False Positive: Has verified the string by regular expression

try {
String relativePath = FileUtil.getPathForToday();
String relativeParent = FileUtil.getPathForToday();
//Init test file set info
TestFileSet testFileSet = new TestFileSet();
testFileSet.setBuildType(localBuildType);
Expand All @@ -132,8 +132,8 @@ public Result add(@CurrentSecurityContext SysUser requestor,

//Save app file to server
File tempAppFile =
attachmentService.verifyAndSaveFile(appFile, CENTER_FILE_BASE_DIR + relativePath, false, null, new String[]{FILE_SUFFIX.APK_FILE, FILE_SUFFIX.IPA_FILE});
StorageFileInfo appFileInfo = new StorageFileInfo(tempAppFile, relativePath, StorageFileInfo.FileType.APP_FILE);
attachmentService.verifyAndSaveFile(appFile, CENTER_FILE_BASE_DIR + relativeParent, false, null, new String[]{FILE_SUFFIX.APK_FILE, FILE_SUFFIX.IPA_FILE});
StorageFileInfo appFileInfo = new StorageFileInfo(tempAppFile, relativeParent, StorageFileInfo.FileType.APP_FILE);
//Upload app file
appFileInfo = attachmentService.addAttachment(testFileSet.getId(), EntityType.APP_FILE_SET, appFileInfo, tempAppFile, logger);
JSONObject appFileParser = appFileInfo.getFileParser();
Expand All @@ -144,10 +144,10 @@ public Result add(@CurrentSecurityContext SysUser requestor,

//Save test app file to server if exist
if (testAppFile != null && !testAppFile.isEmpty()) {
File tempTestAppFile = attachmentService.verifyAndSaveFile(testAppFile, CENTER_FILE_BASE_DIR + relativePath, false, null,
File tempTestAppFile = attachmentService.verifyAndSaveFile(testAppFile, CENTER_FILE_BASE_DIR + relativeParent, false, null,
new String[]{FILE_SUFFIX.APK_FILE, FILE_SUFFIX.JAR_FILE, FILE_SUFFIX.JSON_FILE});

StorageFileInfo testAppFileInfo = new StorageFileInfo(tempTestAppFile, relativePath, StorageFileInfo.FileType.TEST_APP_FILE);
StorageFileInfo testAppFileInfo = new StorageFileInfo(tempTestAppFile, relativeParent, StorageFileInfo.FileType.TEST_APP_FILE);
//Upload app file
testAppFileInfo = attachmentService.addAttachment(testFileSet.getId(), EntityType.APP_FILE_SET, testAppFileInfo, tempTestAppFile, logger);
testFileSet.getAttachments().add(testAppFileInfo);
Expand Down Expand Up @@ -235,11 +235,11 @@ public Result uploadAgentPackage(@RequestParam("packageFile") MultipartFile pack
return Result.error(HttpStatus.FORBIDDEN.value(), "package file empty");
}

String fileRelativePath = FileUtil.getPathForToday();
String parentDir = CENTER_FILE_BASE_DIR + fileRelativePath;
String fileRelativeParent = FileUtil.getPathForToday();
String parentDir = CENTER_FILE_BASE_DIR + fileRelativeParent;
try {
File savedPkg = attachmentService.verifyAndSaveFile(packageFile, parentDir, false, null, new String[]{FILE_SUFFIX.JAR_FILE});
StorageFileInfo storageFileInfo = new StorageFileInfo(savedPkg, fileRelativePath, StorageFileInfo.FileType.AGENT_PACKAGE);
StorageFileInfo storageFileInfo = new StorageFileInfo(savedPkg, fileRelativeParent, StorageFileInfo.FileType.AGENT_PACKAGE);
return Result.ok(attachmentService.saveFileInStorageAndDB(storageFileInfo, savedPkg, EntityType.AGENT_PACKAGE, logger));
} catch (HydraLabRuntimeException e) {
return Result.error(e.getCode(), e);
Expand Down Expand Up @@ -410,11 +410,11 @@ public Result addAttachment(@CurrentSecurityContext SysUser requestor,
}
try {
String newFileName = FileUtil.getLegalFileName(attachment.getOriginalFilename());
String fileRelativePath = FileUtil.getPathForToday();
String parentDir = CENTER_FILE_BASE_DIR + fileRelativePath;
String fileRelativeParent = FileUtil.getPathForToday();
String parentDir = CENTER_FILE_BASE_DIR + fileRelativeParent;

File savedAttachment = attachmentService.verifyAndSaveFile(attachment, parentDir, false, newFileName, limitFileTypes);
StorageFileInfo storageFileInfo = new StorageFileInfo(savedAttachment, fileRelativePath, fileType, loadType, loadDir);
StorageFileInfo storageFileInfo = new StorageFileInfo(savedAttachment, fileRelativeParent, fileType, loadType, loadDir);
attachmentService.addAttachment(fileSetId, EntityType.APP_FILE_SET, storageFileInfo, savedAttachment, logger);
testFileSet.setAttachments(attachmentService.getAttachments(fileSetId, EntityType.APP_FILE_SET));
testFileSetService.saveFileSetToMem(testFileSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public class StorageFileInfo implements Serializable {
public StorageFileInfo() {

}
public StorageFileInfo(File file, String relativePath, String fileType, String loadType, String loadDir){
this(file, relativePath, fileType);
public StorageFileInfo(File file, String relativeParent, String fileType, String loadType, String loadDir){
this(file, relativeParent, fileType);
this.loadType = loadType;
this.loadDir = loadDir;
}
public StorageFileInfo(File file, String relativePath, String fileType) {
public StorageFileInfo(File file, String relativeParent, String fileType) {
this.fileType = fileType;
this.fileName = file.getName();
this.fileLen = file.length();
this.blobPath = relativePath + "/" + file.getName();
this.blobPath = relativeParent + "/" + file.getName();

try {
FileInputStream inputStream = new FileInputStream(file);
Expand All @@ -64,11 +64,11 @@ public StorageFileInfo(File file, String relativePath, String fileType) {
}
}

public StorageFileInfo(File file, String relativePath, String fileType, EntityType entityType) {
public StorageFileInfo(File file, String fileRelPath, String fileType, EntityType entityType) {
this.fileType = fileType;
this.fileName = file.getName();
this.fileLen = file.length();
this.blobPath = relativePath + "/" + file.getName();
this.blobPath = fileRelPath;
this.blobContainer = entityType.storageContainer;

try {
Expand Down

0 comments on commit 3a45a57

Please sign in to comment.