Code cleanup. Such as Providing new public method, changing method name.
authorYuanHu <yuan.hu1@zte.com.cn>
Fri, 23 Sep 2016 06:03:50 +0000 (14:03 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Fri, 23 Sep 2016 06:03:50 +0000 (14:03 +0800)
Change-Id: Ida1cd134c94c8c014a4a827acdb06404633d1fc3
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/ToolUtil.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java

index dea67c8..5880df0 100644 (file)
@@ -38,8 +38,7 @@ public class HttpFileManagerImpl implements FileManager {
     }
     // File dstFile = new File(ToolUtil.getHttpServerPath() + dstPath);
     // LOGGER.info("dstFile AbsolutePath:" + dstFile.getAbsolutePath());
-    String targetDir =
-        Class.class.getClass().getResource("/").getPath() + ToolUtil.getHttpServerPath() + dstPath;
+    String targetDir = ToolUtil.getHttpServerAbsolutePath() + dstPath;
     try {
       ToolUtil.copyDirectory(srcPath, targetDir, true);
     } catch (IOException e1) {
@@ -60,7 +59,7 @@ public class HttpFileManagerImpl implements FileManager {
   public boolean delete(String srcPath) {
     boolean flag = true;
     LOGGER.info("start delete file from http server.srcPath:" + srcPath);
-    flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerPath() + srcPath));
+    flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerAbsolutePath() + srcPath));
     LOGGER.info("delete file from http server end.flag:" + flag);
     return flag;
   }
index 931c5f3..2ceffb4 100644 (file)
@@ -170,8 +170,8 @@ public class ToolUtil {
     }
   }
 
-  public static String getHttpServerPath() {
-    return HttpServerPathConfig.getHttpServerPath();
+  public static String getHttpServerAbsolutePath() {
+    return Class.class.getClass().getResource("/").getPath() +  HttpServerPathConfig.getHttpServerPath();
   }
 
   /**
index 4d2134f..4b44a6c 100644 (file)
@@ -16,7 +16,7 @@
 
 package org.openo.commontosca.catalog.model.parser;
 
-import org.openo.commontosca.catalog.common.MsbAddrConfig;
+import org.openo.commontosca.catalog.common.Config;
 import org.openo.commontosca.catalog.common.ToolUtil;
 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
 import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
@@ -47,9 +47,8 @@ public abstract class AbstractModelParser {
       throws CatalogResourceException;
   
   public String copyTemporaryFile2HttpServer(String fileLocation) throws CatalogResourceException {
-    String destPath = Class.class.getClass().getResource("/").getPath()
-        + org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerPath()
-        + toTempFileLocalPath(fileLocation);
+    String destPath = org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerAbsolutePath()
+        + toTempFilePath(fileLocation);
     if (!org.openo.commontosca.catalog.filemanage.http.ToolUtil.copyFile(
         fileLocation, destPath, true)) {
       throw new CatalogResourceException("Copy Temporary To HttpServer Failed.");
@@ -57,17 +56,11 @@ public abstract class AbstractModelParser {
     return destPath;
   }
   
-  public String getUrl(String uri) {
-    String url = null;
-    if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {
-      url = MsbAddrConfig.getMsbAddress() + uri.substring(1);
-    }
-    url = MsbAddrConfig.getMsbAddress() + uri;
-    String urlresult = url.replace("\\", "/");
-    return urlresult;
+  public String getUrlOnHttpServer(String path) {
+    return Config.getConfigration().getHttpServerAddr() + "/" + path;
   }
   
-  protected String toTempFileLocalPath(String fileLocation) {
+  protected String toTempFilePath(String fileLocation) {
     return File.separator + "temp" + File.separator + (new File(fileLocation)).getName();
   }
   
index 33c1676..70e8ff5 100644 (file)
@@ -290,7 +290,7 @@ public class AriaModelParser extends AbstractModelParser {
   private AriaParserResult getAriaParserResult(String fileLocation) throws CatalogResourceException {
     String destPath = copyTemporaryFile2HttpServer(fileLocation);
     try {
-      String url = getUrl(toTempFileLocalPath(fileLocation));
+      String url = getUrlOnHttpServer(toTempFilePath(fileLocation));
       return AriaParserServiceConsumer.parseCsarPackage(url);
     } finally {
       if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) {
index 5b59998..760e31b 100644 (file)
@@ -81,7 +81,7 @@ public class ToscaYamlModelParser extends AbstractModelParser {
   private ParseYamlResult getParseYamlResult(String fileLocation) throws CatalogResourceException {
     String destPath = copyTemporaryFile2HttpServer(fileLocation);
     try {
-      String url = getUrl(toTempFileLocalPath(fileLocation));
+      String url = getUrlOnHttpServer(toTempFilePath(fileLocation));
       return YamlParseServiceConsumer.getServiceTemplates(comboRequest(url));
     } finally {
       if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) {