\r
package org.openo.commontosca.catalog.model.parser;\r
\r
+import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
import org.openo.commontosca.catalog.common.ToolUtil;\r
import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
import org.openo.commontosca.catalog.db.resource.TemplateManager;\r
\r
@Override\r
public String parse(String packageId, String fileLocation) throws CatalogResourceException {\r
- ParseYamlResult result =\r
- YamlParseServiceConsumer.getServiceTemplates(comboRequest(fileLocation));\r
-\r
+ ParseYamlResult result = getParseYamlResult(fileLocation);\r
+ \r
Map<String, String> toscaMeta = parseToscaMeta(fileLocation);\r
String stFileName = toscaMeta.get(TOSCA_META_FIELD_ENTRY_DEFINITIONS);\r
CsarFileUriResponse stDownloadUri =\r
return st.getServiceTemplateId();\r
}\r
\r
+ private ParseYamlResult getParseYamlResult(String fileLocation) throws CatalogResourceException {\r
+ String destPath = copyTemporaryFile2HttpServer(fileLocation);\r
+ try {\r
+ String url = getUrl(toTempFileLocalPath(fileLocation));\r
+ return YamlParseServiceConsumer.getServiceTemplates(comboRequest(url));\r
+ } finally {\r
+ if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) {\r
+ (new File(destPath)).deleteOnExit();\r
+ }\r
+ }\r
+ }\r
+\r
+ private String toTempFileLocalPath(String fileLocation) {\r
+ return File.separator + "temp" + File.separator + (new File(fileLocation)).getName();\r
+ }\r
+ \r
+ private String getUrl(String uri) {\r
+ String url = null;\r
+ if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {\r
+ url = MsbAddrConfig.getMsbAddress() + uri.substring(1);\r
+ }\r
+ url = MsbAddrConfig.getMsbAddress() + uri;\r
+ String urlresult = url.replace("\\", "/");\r
+ return urlresult;\r
+ }\r
+\r
+ private String copyTemporaryFile2HttpServer(String fileLocation) throws CatalogResourceException {\r
+ String destPath = Class.class.getClass().getResource("/").getPath()\r
+ + org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerPath()\r
+ + toTempFileLocalPath(fileLocation);\r
+ if (!org.openo.commontosca.catalog.filemanage.http.ToolUtil.copyFile(fileLocation, destPath,\r
+ true)) {\r
+ throw new CatalogResourceException("Copy Temporary To HttpServer Failed.");\r
+ }\r
+ return destPath;\r
+ }\r
+\r
@SuppressWarnings("resource")\r
private Map<String, String> parseToscaMeta(String fileLocation) throws CatalogResourceException {\r
Map<String, String> toscaMeta = new HashMap<>();\r