|
@@ -295,16 +295,18 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
}
|
|
|
|
|
|
//解压zip中的workspace到目标文件夹下
|
|
|
+ File importZipFile = null;
|
|
|
if(zipPath != null && zipPath.endsWith(".zip")){
|
|
|
zipPath = Paths.get(System.getProperty("java.io.tmpdir"),Constants.TARGET_PATH,zipPath)
|
|
|
.toString();
|
|
|
- File zipFile = new File(zipPath);
|
|
|
- if(zipFile.exists()){
|
|
|
+ importZipFile = new File(zipPath);
|
|
|
+ if(importZipFile.exists()){
|
|
|
FileUtils.unZipMultiFile(zipPath,targetPath);
|
|
|
- org.apache.commons.io.FileUtils.copyDirectory(
|
|
|
- Paths.get(targetPath, Constants.WORKSPACE_NAME).toFile()
|
|
|
- ,new File(targetContentPath));
|
|
|
- FileUtils.deleteDir(new File(zipPath));
|
|
|
+ File workspaceDir = Paths.get(targetPath, Constants.WORKSPACE_NAME).toFile();
|
|
|
+ if(workspaceDir.exists() && workspaceDir.isDirectory()){
|
|
|
+ org.apache.commons.io.FileUtils.copyDirectory(
|
|
|
+ workspaceDir,new File(targetContentPath));
|
|
|
+ }
|
|
|
}else{
|
|
|
log.warn("zip "+zipPath+" not exist!");
|
|
|
}
|
|
@@ -348,14 +350,17 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
}
|
|
|
target.setUrl(url);
|
|
|
targetService.updateTarget(target);
|
|
|
- Map<String, String> propertyMap = new HashMap<>();
|
|
|
- propertyMap.put("lang",lang);
|
|
|
- targetService.saveTargetProperties(propertyMap,targetId);
|
|
|
+ targetService.setTargetProperty(targetId,Constants.LANG_PROPERTY,lang);
|
|
|
TargetExtends importZipExtends = targetService.getTargetProperty(targetId,Constants
|
|
|
.TARGET_IMPORT_ZIP_PATH);
|
|
|
if(importZipExtends != null){
|
|
|
targetService.removeTargetProperty(importZipExtends.getId());
|
|
|
}
|
|
|
+
|
|
|
+ //target新建成功,import zip可被删除
|
|
|
+ if(importZipFile != null){
|
|
|
+ FileUtils.deleteDir(importZipFile);
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -391,9 +396,9 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
FileUtils.unZipMultiFile(tmpZipPath,tmpUnzipPath);
|
|
|
|
|
|
//检查zip包格式
|
|
|
- File workspace = new File(Paths.get(tmpUnzipPath,Constants.WORKSPACE_NAME).toString());
|
|
|
+// File workspace = new File(Paths.get(tmpUnzipPath,Constants.WORKSPACE_NAME).toString());
|
|
|
File meta = new File(Paths.get(tmpUnzipPath,Constants.META_NAME).toString());
|
|
|
- if(workspace.exists() && workspace.isDirectory() && meta.exists() && meta.isFile()){
|
|
|
+ if(meta.exists() && meta.isFile()){
|
|
|
//zip包格式正确
|
|
|
String fileContent = FileUtils.readToString(Paths.get(tmpUnzipPath,Constants.META_NAME)
|
|
|
.toString());
|
|
@@ -407,7 +412,7 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
log.info("delete tmp unzip dir: "+FileUtils.deleteDir(new File(tmpUnzipPath)));
|
|
|
log.info("delete error format zip: "+FileUtils.deleteDir(new File(tmpZipPath)));
|
|
|
throw new HttpBadRequestException("Zip format wrong! Please ensure you have 'meta"
|
|
|
- + ".json' FILE and 'workspace' DIRECTORY under the zip DIRECTLY!");
|
|
|
+ + ".json' FILE under the zip DIRECTLY!");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -455,13 +460,21 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
.LANG_PROPERTY);
|
|
|
targetDataVo.setLang(targetExtends==null?null:targetExtends.getPropertyValue());
|
|
|
|
|
|
+ //构造meta.json
|
|
|
String metaJson = new Gson().toJson(targetDataVo);
|
|
|
log.info("Meta json is: \n"+metaJson);
|
|
|
FileUtils.writingStringToFile(metaJson,Paths.get(downloadPath,Constants.META_NAME)
|
|
|
.toString());
|
|
|
|
|
|
+ //删除不需要的文件
|
|
|
+ FileUtils.deleteDir(Paths.get(workspacePath,Constants.MAIN_NAME).toFile());
|
|
|
+ FileUtils.deleteDir(Paths.get(workspacePath,Constants.MOOCTEST_PATH,Constants
|
|
|
+ .ANSWER_NAME).toFile());
|
|
|
+ FileUtils.deleteDir(Paths.get(workspacePath,Constants.MOOCTEST_PATH,Constants.TEST_CASE_NAME).toFile());
|
|
|
String finalZipPath = Paths.get(Constants.SAVE_PATH,target.getName()+"_"+System.currentTimeMillis
|
|
|
()+".zip").toString();
|
|
|
+
|
|
|
+ //压缩文件
|
|
|
FileUtils.zipMultiFile(downloadPath,finalZipPath,false);
|
|
|
targetService.setTargetProperty(targetId,Constants.TARGET_IMPORT_ZIP_PATH,finalZipPath);
|
|
|
FileUtils.deleteDir(new File(targetPath));
|