summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java46
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java6
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java130
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerAddrConfig.java5
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerPathConfig.java15
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/MsbAddrConfig.java4
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java105
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java2
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java286
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java104
10 files changed, 311 insertions, 392 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java
index 5432300f..efeef061 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java
@@ -16,6 +16,9 @@
package org.onap.vnfsdk.marketplace.common;
public class CommonConstant {
+ // Address
+ public static final String DEFAULT_MSB_ADDRESS = "http://127.0.0.1:8080";
+
// Package Status
public static final String PACKAGE_STATUS_DELETING = "deleting";
@@ -39,9 +42,9 @@ public class CommonConstant {
public static final String DEFINITIONS = "Definitions";
public static final String CSAR_META = "csar.meta";
-
+
public static final String MANIFEST = ".mf";
-
+
public static final String MF_VERSION_META = "vnf_package_version";
public static final String MF_PRODUCT_NAME = "vnf_product_name";
@@ -53,46 +56,46 @@ public class CommonConstant {
public static final String CSAR_SUFFIX = ".csar";
public static final String HTTP_HEADER_CONTENT_RANGE = "Content-Range";
-
+
public static final String CATALOG_CSAR_DIR_NAME = "/csar";
-
+
public static final String REPORT_CSAR_DIR_NAME = "/reports";
-
+
public static final String COMETD_CHANNEL_PACKAGE_DELETE = "/package/delete";
-
+
public static final String SUCCESS_STR = "SUCCESS";
-
+
public static final int ONBOARDING_THREAD_COUNT = 1;
public static final int SUCESS = 0;
public static final int FAILED = -1;
-
+
public static final String CATALOUGE_UPLOAD_URL = "/openoapi/catalog/v1/csars";
-
+
private CommonConstant (){
- // Cannot create instance of the class
+ // Cannot create instance of the class
}
-
- public static class functionTest
- {
+
+ public static class functionTest
+ {
public static final String FUNCTEST_URL = "/openoapi/vnfsdk/v1/functest/";
public static final String FUNCTEST_RESULT_URL = "/openoapi/vnfsdk/v1/functest/download/";
public static final String FUNCTEST_OPERTYPE_ID = "functiontest";
public static final String FUNCTEST_PACKAGE_EXISTS = "packageExists";
public static final String FUNCTEST_EXEC = "functestexec";
-
+
private functionTest() {
}
}
-
- public static class LifeCycleTest
- {
+
+ public static class LifeCycleTest
+ {
public static final String LIFECYCLE_TEST_URL = "/openoapi/nslcm/v1/vnfpackage";
public static final String LIFECYCLE_TEST_OPERTYPE_ID = "lifecycletest";
public static final String LIFECYCLE_TEST_EXEC = "lifecycleTestexec";
private LifeCycleTest() {
}
}
-
+
public static class HttpContext {
public static final String CONTENT_TYPE = "Content-Type";
@@ -106,7 +109,7 @@ public class CommonConstant {
private HttpContext() {
}
}
-
+
public static class MethodType {
public static final String POST = "post";
@@ -120,12 +123,12 @@ public class CommonConstant {
private MethodType() {
}
}
-
+
public static class MsbRegisterCode {
public static final int MSDB_REGISTER_RETRIES = 12;
public static final int MSDB_REGISTER_RETRY_SLEEP = 10000;
-
+
public static final int MSDB_REGISTER_FILE_NOT_EXISTS = 2;
public static final int MSDB_REGISTER_SUCESS = 0;
public static final int MSDB_REGISTER_FAILED = -1;
@@ -133,3 +136,4 @@ public class CommonConstant {
}
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java
index e2514a88..2c22bdca 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java
@@ -18,10 +18,11 @@ package org.onap.vnfsdk.marketplace.common;
public class CommonErrorResponse {
- private String code;
-
private String message;
+ public String getMessage() {
+ return message;
+ }
public static Object failure(String message) {
return message;
@@ -33,3 +34,4 @@ public class CommonErrorResponse {
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java
index 564e7d79..87fb75b6 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java
@@ -15,16 +15,6 @@
*/
package org.onap.vnfsdk.marketplace.common;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.io.Resources;
-
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -34,9 +24,19 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public final class FileUtil {
@@ -101,31 +101,30 @@ public final class FileUtil {
* @return unzip file name
* @throws IOException e1
*/
- public static ArrayList<String> unzip(String zipFileName, String extPlace) throws IOException {
- ZipFile zipFile = null;
- ArrayList<String> unzipFileNams = new ArrayList<String>();
+ public static List<String> unzip(String zipFileName, String extPlace) throws IOException {
+ List<String> unzipFileNams = new ArrayList<>();
- try {
- zipFile = new ZipFile(zipFileName);
+ try (
+ ZipFile zipFile = new ZipFile(zipFileName);
+ ) {
Enumeration<?> fileEn = zipFile.entries();
byte[] buffer = new byte[BUFFER_SIZE];
while (fileEn.hasMoreElements()) {
- InputStream input = null;
- BufferedOutputStream bos = null;
- try {
- ZipEntry entry = (ZipEntry) fileEn.nextElement();
- if (entry.isDirectory()) {
- continue;
- }
+ ZipEntry entry = (ZipEntry) fileEn.nextElement();
+ if (entry.isDirectory()) {
+ continue;
+ }
- input = zipFile.getInputStream(entry);
- File file = new File(extPlace, entry.getName());
- if (!file.getParentFile().exists()) {
- createDirectory(file.getParentFile().getAbsolutePath());
- }
+ File file = new File(extPlace, entry.getName());
+ if (!file.getParentFile().exists()) {
+ createDirectory(file.getParentFile().getAbsolutePath());
+ }
- bos = new BufferedOutputStream(new FileOutputStream(file));
+ try (
+ InputStream input = zipFile.getInputStream(entry);
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
+ ) {
while (true) {
int length = input.read(buffer);
if (length == -1) {
@@ -134,20 +133,15 @@ public final class FileUtil {
bos.write(buffer, 0, length);
}
unzipFileNams.add(file.getAbsolutePath());
- } finally {
- closeOutputStream(bos);
- closeInputStream(input);
}
}
- } finally {
- closeZipFile(zipFile);
}
return unzipFileNams;
}
/**
* close InputStream.
- *
+ *
* @param inputStream the inputstream to close
*/
public static void closeInputStream(InputStream inputStream) {
@@ -162,7 +156,7 @@ public final class FileUtil {
/**
* close OutputStream.
- *
+ *
* @param outputStream the output stream to close
*/
public static void closeOutputStream(OutputStream outputStream) {
@@ -174,7 +168,7 @@ public final class FileUtil {
logger.info("error while closing OutputStream!", e1);
}
}
-
+
public static void closeFileStream(FileInputStream ifs) {
try {
if (ifs != null) {
@@ -187,14 +181,13 @@ public final class FileUtil {
/**
* close zipFile.
- *
+ *
* @param zipFile the zipFile to close
*/
public static void closeZipFile(ZipFile zipFile) {
try {
if (zipFile != null) {
zipFile.close();
- zipFile = null;
}
} catch (IOException e1) {
logger.info("close ZipFile error!", e1);
@@ -213,34 +206,34 @@ public final class FileUtil {
return deleteFile(file);
}
- public static boolean writeJsonDatatoFile(String fileAbsPath, Object obj)
- {
+ public static boolean writeJsonDatatoFile(String fileAbsPath, Object obj)
+ {
logger.info("Write JsonData to file :"+fileAbsPath);
-
+
boolean bResult = false;
if(checkFileExists(fileAbsPath))
{
deleteFile(fileAbsPath);
}
-
- ObjectMapper mapper = new ObjectMapper();
- try
+
+ ObjectMapper mapper = new ObjectMapper();
+ try
{
mapper.writeValue(new File(fileAbsPath), obj);
bResult = true;
- }
- catch (JsonGenerationException e)
+ }
+ catch (JsonGenerationException e)
{
logger.info("JsonGenerationException Exception: writeJsonDatatoFile-->"+fileAbsPath, e);
- }
- catch (JsonMappingException e)
+ }
+ catch (JsonMappingException e)
{
logger.info("JsonMappingException Exception: writeJsonDatatoFile-->"+fileAbsPath, e);
- }
- catch (IOException e)
+ }
+ catch (IOException e)
{
logger.info("IOException Exception: writeJsonDatatoFile-->"+fileAbsPath, e);
- }
+ }
return bResult;
}
@@ -251,44 +244,44 @@ public final class FileUtil {
logger.info("read JsonData from file , file not found :"+fileAbsPath);
return null;
}
-
+
logger.info("read JsonData from file :"+fileAbsPath);
-
- T obj = null;
+
+ T obj = null;
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- try
+ try
{
obj = mapper.readValue(new File(fileAbsPath), clazz);
- }
- catch (JsonParseException e1)
+ }
+ catch (JsonParseException e1)
{
logger.info("JsonParseException Exception: writeJsonDatatoFile-->"+fileAbsPath, e1);
- }
- catch (JsonMappingException e1)
+ }
+ catch (JsonMappingException e1)
{
logger.info("JsonMappingException Exception: writeJsonDatatoFile-->"+fileAbsPath, e1);
- }
- catch (IOException e1)
+ }
+ catch (IOException e1)
{
logger.info("IOException Exception: writeJsonDatatoFile-->"+fileAbsPath, e1);
}
return obj;
}
-
- public static boolean deleteDirectory(String path)
+
+ public static boolean deleteDirectory(String path)
{
File file = new File(path);
return deleteDirectory(file);
}
-
- public static boolean deleteDirectory(File file)
+
+ public static boolean deleteDirectory(File file)
{
if (!file.exists())
{
- return true;
- }
- if (file.isDirectory())
+ return true;
+ }
+ if (file.isDirectory())
{
for (File f : file.listFiles())
{
@@ -298,3 +291,4 @@ public final class FileUtil {
return file.delete();
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerAddrConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerAddrConfig.java
index 2adf1b89..88913a1c 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerAddrConfig.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerAddrConfig.java
@@ -17,9 +17,11 @@ package org.onap.vnfsdk.marketplace.common;
public class HttpServerAddrConfig {
-
protected static String httpServerAddress;
+ private HttpServerAddrConfig () {
+ }
+
public static String getHttpServerAddress() {
return httpServerAddress;
}
@@ -29,3 +31,4 @@ public class HttpServerAddrConfig {
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerPathConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerPathConfig.java
index 3d5cfacc..f7a499b5 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerPathConfig.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/HttpServerPathConfig.java
@@ -17,15 +17,15 @@ package org.onap.vnfsdk.marketplace.common;
public class HttpServerPathConfig {
protected static String httpServerPath;
-
+
+ private HttpServerPathConfig() {
+ }
+
static
{
-// CatalogAppConfiguration configuration = new CatalogAppConfiguration();
-// Config.setConfigration(configuration);
-// Config.getConfigration().setMsbServerAddr("http://127.0.0.1:80");
- MsbAddrConfig.setMsbAddress("http://127.0.0.1:8080");
- HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
- HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
+ MsbAddrConfig.setMsbAddress(CommonConstant.DEFAULT_MSB_ADDRESS);
+ HttpServerAddrConfig.setHttpServerAddress(CommonConstant.DEFAULT_MSB_ADDRESS);
+ HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
}
public static String getHttpServerPath() {
@@ -36,3 +36,4 @@ public class HttpServerPathConfig {
HttpServerPathConfig.httpServerPath = httpServerPath;
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/MsbAddrConfig.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/MsbAddrConfig.java
index d2ff4b55..379f1037 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/MsbAddrConfig.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/MsbAddrConfig.java
@@ -19,6 +19,9 @@ public class MsbAddrConfig {
protected static String msbAddress;
+ private MsbAddrConfig() {
+ }
+
public static String getMsbAddress() {
return msbAddress;
}
@@ -28,3 +31,4 @@ public class MsbAddrConfig {
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
index 1b45e75f..1d5d46f9 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
@@ -17,7 +17,6 @@ package org.onap.vnfsdk.marketplace.filemanage.http;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -31,6 +30,8 @@ import org.slf4j.LoggerFactory;
public class ToolUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ToolUtil.class);
+ private ToolUtil() {
+ }
/**
* copy from directory.
* @param srcDirName source directory name
@@ -42,49 +43,36 @@ public class ToolUtil {
public static boolean copyDirectory(String srcDirName, String destDirName, boolean overlay)
throws IOException {
File srcDir = new File(srcDirName);
- if (!srcDir.exists()) {
- return false;
- } else if (!srcDir.isDirectory()) {
+ if (!srcDir.exists() || !srcDir.isDirectory()) {
return false;
}
- if (!destDirName.endsWith(File.separator)) {
- destDirName = destDirName + File.separator;
+ String useDestDirName = destDirName;
+ if (!useDestDirName.endsWith(File.separator)) {
+ useDestDirName += File.separator;
}
- File destDir = new File(destDirName);
- if (destDir.exists()) {
- if (overlay) {
+ File destDir = new File(useDestDirName);
+ if (destDir.exists() && overlay) {
new File(destDirName).delete();
- } else {
+ } else if ((destDir.exists() && !overlay) || (!destDir.exists() && !destDir.mkdirs())) {
return false;
- }
- } else {
- if (!destDir.mkdirs()) {
- return false;
- }
}
boolean flag = true;
File[] files = srcDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true);
- if (!flag) {
- break;
- }
} else if (files[i].isDirectory()) {
flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay);
- if (!flag) {
- break;
- }
+ }
+ if (!flag) {
+ String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
+ LOGGER.error(message);
+ return false;
}
}
- if (!flag) {
- String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
- LOGGER.error(message);
- return false;
- } else {
- return true;
- }
+
+ return true;
}
/**
@@ -97,56 +85,36 @@ public class ToolUtil {
public static boolean copyFile(String srcFileName, String destFileName, boolean overlay) {
File srcFile = new File(srcFileName);
- if (!srcFile.exists()) {
+ if (!srcFile.exists() || !srcFile.isFile()) {
String message = "Source file : " + srcFileName + " not exist !";
LOGGER.error(message);
return false;
- } else if (!srcFile.isFile()) {
- return false;
}
File destFile = new File(destFileName);
- if (destFile.exists()) {
- if (overlay) {
+ if (destFile.exists() && overlay) {
new File(destFileName).delete();
- }
- } else {
- if (!destFile.getParentFile().exists()) {
- if (!destFile.getParentFile().mkdirs()) {
- return false;
- }
- }
+ } else if (!destFile.exists() && !destFile.getParentFile().exists() && !destFile.getParentFile().mkdirs()) {
+ return false;
}
int byteread = 0;
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new FileInputStream(srcFile);
- out = new FileOutputStream(destFile);
+ try (
+ InputStream in = new FileInputStream(srcFile);
+ OutputStream out = new FileOutputStream(destFile);
+ ) {
byte[] buffer = new byte[1024];
while ((byteread = in.read(buffer)) != -1) {
out.write(buffer, 0, byteread);
}
return true;
- } catch (FileNotFoundException e1) {
- return false;
- } catch (IOException e1) {
+ } catch (IOException e) {
+ LOGGER.error("IOException in copyFile", e);
return false;
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- if (in != null) {
- in.close();
- }
- } catch (IOException e1) {
- e1.printStackTrace();
- }
}
+
}
/**
@@ -155,18 +123,16 @@ public class ToolUtil {
* @return boolean
*/
public static boolean createDir(String destDirName) {
- File dir = new File(destDirName);
+ String useDestDirName = destDirName;
+ if (!useDestDirName.endsWith(File.separator)) {
+ useDestDirName += File.separator;
+ }
+ File dir = new File(useDestDirName);
if (dir.exists()) {
dir.delete();
}
- if (!destDirName.endsWith(File.separator)) {
- destDirName = destDirName + File.separator;
- }
- if (dir.mkdirs()) {
- return true;
- } else {
- return false;
- }
+
+ return dir.mkdirs();
}
public static String getHttpServerAbsolutePath() {
@@ -190,9 +156,10 @@ public class ToolUtil {
}
return dir.delete();
}
-
+
public static String getAppDeployPath()
{
return Thread.currentThread().getContextClassLoader().getResource("/").getPath();
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
index 83babfa2..7ad48c61 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
@@ -73,7 +73,7 @@ public class PackageResource {
@ApiParam(value = "http header") @Context HttpHeaders head
) throws Exception {
InputStream input = request.getInputStream();
- return PackageWrapper.getInstance().updateValidateStatus(input, head);
+ return PackageWrapper.getInstance().updateValidateStatus(input);
}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
index e21418f9..518d2060 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java
@@ -31,7 +31,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
@@ -54,12 +53,13 @@ import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingSteps;
import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor;
import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
-import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.LifecycleTestExceutor;
import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.ValidateLifecycleTestResponse;
import org.onap.vnfsdk.marketplace.onboarding.onboardmanager.OnBoardingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import net.sf.json.JSONObject;
+
public class PackageWrapper {
private static PackageWrapper packageWrapper;
private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class);
@@ -75,7 +75,7 @@ public class PackageWrapper {
return packageWrapper;
}
- public Response updateValidateStatus(InputStream inputStream, HttpHeaders head) throws Exception
+ public Response updateValidateStatus(InputStream inputStream) throws IOException
{
String reqParam = IOUtils.toString(inputStream);
LOG.info("updateValidateStatus request param:"+reqParam);
@@ -83,39 +83,39 @@ public class PackageWrapper {
LOG.error("The updateValidateStatus request params can't be null");
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
+
ValidateLifecycleTestResponse lyfValidateResp = JsonUtil.fromJson(reqParam, ValidateLifecycleTestResponse.class);
if(!checkOperationSucess(lyfValidateResp))
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
+
String funcTestResponse = FunctionTestExceutor.executeFunctionTest(reqParam);
if(null == funcTestResponse)
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
- JSONObject funcTestRspObject = JSONObject.fromObject(funcTestResponse);
+
+ JSONObject funcTestRspObject = JSONObject.fromObject(funcTestResponse);
if(!funcTestRspObject.get("status").equals(CommonConstant.SUCCESS_STR))
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
- JSONObject result = new JSONObject();
+
+ JSONObject result = new JSONObject();
result.put("msg","SUCCESS");
return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
}
-
- private boolean checkOperationSucess(ValidateLifecycleTestResponse lyfValidateResp)
+
+ private boolean checkOperationSucess(ValidateLifecycleTestResponse lyfValidateResp)
{
boolean bOperStatus = false;
- if(null == lyfValidateResp)
+ if(null == lyfValidateResp)
{
LOG.error("ValidateLifecycleTestResponse is NUll !!!");
return bOperStatus;
}
- if(lyfValidateResp.getLifecycle_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR)
+ if(lyfValidateResp.getLifecycle_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR)
&& lyfValidateResp.getValidate_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR))
{
LOG.error("Lifecycle/Validation Response failed :" + lyfValidateResp.getLifecycle_status() + File.separator + lyfValidateResp.getValidate_status());
@@ -135,8 +135,8 @@ public class PackageWrapper {
*/
public Response queryPackageListByCond(String name, String provider, String version,
String deletionPending, String type) {
- ArrayList<PackageData> dbresult = new ArrayList<PackageData>();
- List<PackageMeta> result = new ArrayList<PackageMeta>();
+ ArrayList<PackageData> dbresult = new ArrayList<>();
+ List<PackageMeta> result = new ArrayList<>();
LOG.info("query package info.name:" + name + " provider:" + provider + " version" + version
+ " deletionPending" + deletionPending + " type:" + type);
try {
@@ -156,10 +156,8 @@ public class PackageWrapper {
* @return Response
*/
public Response queryPackageById(String csarId) {
- PackageData dbResult = new PackageData();
- PackageMeta result = new PackageMeta();
- dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
- result = PackageWrapperUtil.packageData2PackageMeta(dbResult);
+ PackageData dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
+ PackageMeta result = PackageWrapperUtil.packageData2PackageMeta(dbResult);
return Response.ok(ToolUtil.objectToString(result)).build();
}
@@ -172,10 +170,10 @@ public class PackageWrapper {
* @throws Exception e
*/
public Response uploadPackage(InputStream uploadedInputStream,
- FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws Exception
+ FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws IOException, MarketplaceResourceException
{
LOG.info("Upload/Reupload request Received !!!!");
-
+
String packageId = MarketplaceDbUtil.generateId();
return handlePackageUpload(packageId,uploadedInputStream, fileDetail, details, head);
}
@@ -192,8 +190,8 @@ public class PackageWrapper {
* @throws MarketplaceResourceException
*/
private Response handlePackageUpload(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail,
- String details, HttpHeaders head) throws IOException, MarketplaceResourceException
- {
+ String details, HttpHeaders head) throws IOException, MarketplaceResourceException
+ {
boolean bResult = handleDataValidate(packageId,uploadedInputStream,fileDetail);
if(!bResult)
{
@@ -208,11 +206,11 @@ public class PackageWrapper {
fileName = ToolUtil.processFileName(fileDetail.getFileName());
}
-
+
String localDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
String contentRange = null;
- if (head != null)
+ if (head != null)
{
contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE);
}
@@ -228,66 +226,48 @@ public class PackageWrapper {
uploadedInputStream.close();
- PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
- if (null == basicInfo.getType() || null == basicInfo.getProvider() || null == basicInfo.getVersion())
- {
- LOG.error("Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo));
- return Response.serverError().build();
- }
-
- UploadPackageResponse result = new UploadPackageResponse();
+ PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
+ UploadPackageResponse result = new UploadPackageResponse();
Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange);
- if (isEnd)
+ if (isEnd)
{
PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId,fileName, fileLocation, basicInfo, details);
-
- String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator + packageMeta.getCsarId() + File.separator + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion();
- String dowloadUri = File.separator + path + File.separator;
- packageMeta.setDownloadUri(dowloadUri);
-
- LOG.info("dest path is : " + path);
- LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
-
- PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
-
- String destPath = File.separator + path + File.separator + File.separator;
- boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath);
- if (uploadResult)
- {
- //Create OnBoarding Request
- //--------------------------
- OnBoradingRequest oOnboradingRequest = new OnBoradingRequest();
- oOnboradingRequest.setCsarId(packageId);
- oOnboradingRequest.setPackageName(fileName);
- oOnboradingRequest.setPackagePath(localDirName);
-
- //Upload the Package to CATALOUGE and get CSARID
- //---------------------------------------------
- //String catalougeCsarId = LifecycleTestExceutor.uploadPackageToCatalouge(oOnboradingRequest);
- //if((null == catalougeCsarId) || catalougeCsarId.isEmpty())
- //{
- // LOG.error("Failed to Upload Package to catalougeCsarId " + ToolUtil.objectToString(basicInfo));
- //return Response.status(Status.INTERNAL_SERVER_ERROR).build();
- // }
- //oOnboradingRequest.setCsarIdCatalouge(catalougeCsarId);
- //LOG.info("catalougeCsarId :" + catalougeCsarId);
-
-
- //Update Default download count to -1
- packageData.setCsarId(packageId);
- packageData.setDownloadCount(-1);
- PackageData packateDbData = PackageManager.getInstance().addPackage(packageData);
-
- LOG.info("Store package data to database succed ! packateDbData = " + ToolUtil.objectToString(packateDbData));
- LOG.info("upload package file end, fileName:" + fileName);
-
- result.setCsarId(packateDbData.getCsarId());
-
- //Assign OnBoarding Request to OnBoarding Handler
- //------------------------------------------------
- addOnBoardingRequest(oOnboradingRequest);
-
- LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest));
+ try {
+ String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator + packageMeta.getCsarId() + File.separator + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion();
+
+ String dowloadUri = File.separator + path + File.separator;
+ packageMeta.setDownloadUri(dowloadUri);
+
+ LOG.info("dest path is : " + path);
+ LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
+
+ PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
+
+ String destPath = File.separator + path + File.separator + File.separator;
+ boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath);
+ if (uploadResult)
+ {
+ OnBoradingRequest oOnboradingRequest = new OnBoradingRequest();
+ oOnboradingRequest.setCsarId(packageId);
+ oOnboradingRequest.setPackageName(fileName);
+ oOnboradingRequest.setPackagePath(localDirName);
+
+ packageData.setCsarId(packageId);
+ packageData.setDownloadCount(-1);
+ PackageData packateDbData = PackageManager.getInstance().addPackage(packageData);
+
+ LOG.info("Store package data to database succed ! packateDbData = " + ToolUtil.objectToString(packateDbData));
+ LOG.info("upload package file end, fileName:" + fileName);
+
+ result.setCsarId(packateDbData.getCsarId());
+
+ addOnBoardingRequest(oOnboradingRequest);
+
+ LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest));
+ }
+ } catch (NullPointerException e) {
+ LOG.error("Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo), e);
+ return Response.serverError().build();
}
}
return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
@@ -297,17 +277,14 @@ public class PackageWrapper {
* Execute OnBarding request
* @param oOnboradingRequest
*/
- private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest)
+ private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest)
{
ExecutorService es = Executors.newFixedThreadPool(CommonConstant.ONBOARDING_THREAD_COUNT);
- es.submit(new Callable<Integer>()
- {
- public Integer call() throws Exception
- {
- new OnBoardingHandler().handleOnBoardingReq(oOnboradingRequest);
- return CommonConstant.SUCESS;
- }
- });
+ Callable<Integer> callableInteger = () -> {
+ new OnBoardingHandler().handleOnBoardingReq(oOnboradingRequest);
+ return CommonConstant.SUCESS;
+ };
+ es.submit(callableInteger);
}
/**
@@ -334,13 +311,13 @@ public class PackageWrapper {
if (packagePath == null) {
LOG.error("package path is null! ");
}
-
+
//Delete Package
FileManagerFactory.createFileManager().delete(packagePath);
//Delete Results Data
FileManagerFactory.createFileManager().delete(File.separator + csarId);
-
+
//delete package data from database
try {
PackageManager.getInstance().deletePackage(csarId);
@@ -356,29 +333,29 @@ public class PackageWrapper {
*/
public Response downloadCsarPackagesById(String csarId) {
PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
-
+
String packageName = packageData.getName();
String path = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath() +File.separatorChar+packageData.getType()+File.separatorChar+
- packageData.getProvider()+File.separatorChar+ packageData.getCsarId() +File.separator +packageName+File.separatorChar+packageData.getVersion()
+ packageData.getProvider()+File.separatorChar+ packageData.getCsarId() +File.separator +packageName+File.separatorChar+packageData.getVersion()
+File.separator + packageName + ".csar";
-
+
LOG.info("downloadCsarPackagesById path is : " + path);
-
+
File csarFile = new File(path);
if (!csarFile.exists()) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
LOG.info("downloadCsarPackagesById ABS path is : " + csarFile.getAbsolutePath());
-
- try
+
+ try
{
InputStream fis = new BufferedInputStream(new FileInputStream(csarFile.getAbsolutePath()));
return Response.ok(fis)
.header("Content-Disposition", "attachment; filename=\"" + csarFile.getName() + "\"")
.build();
- }
- catch (Exception e1)
+ }
+ catch (Exception e1)
{
LOG.error("download vnf package fail.", e1);
return RestUtil.getRestException(e1.getMessage());
@@ -401,8 +378,8 @@ public class PackageWrapper {
* @return
*/
public Response updateDwonloadCount(String csarId) {
- return handleDownladCountUpdate(csarId) ?
- Response.ok().build() :
+ return handleDownladCountUpdate(csarId) ?
+ Response.ok().build() :
Response.status(Status.EXPECTATION_FAILED).build();
}
@@ -413,12 +390,12 @@ public class PackageWrapper {
*/
private boolean handleDownladCountUpdate(String csarId) {
boolean bupdateSucess = false;
- try
+ try
{
PackageManager.getInstance().updateDwonloadCount(csarId);
bupdateSucess = true;
- }
- catch (Exception exp)
+ }
+ catch (Exception exp)
{
LOG.error("Updating Donwload count failed for Package with ID !!! : " + exp.getMessage(), exp);
}
@@ -426,7 +403,7 @@ public class PackageWrapper {
}
/**
- * Interface to Re upload Package
+ * Interface to Re upload Package
* @param csarId
* @param uploadedInputStream
* @param fileDetail
@@ -436,14 +413,14 @@ public class PackageWrapper {
* @throws Exception
*/
public Response reUploadPackage(String csarId,
- InputStream uploadedInputStream,
+ InputStream uploadedInputStream,
FormDataContentDisposition fileDetail,
- String details,
- HttpHeaders head) throws Exception
+ String details,
+ HttpHeaders head) throws IOException, MarketplaceResourceException
{
LOG.info("Reupload request Received !!!!");
-
- //STEP 1: Validate Input Data
+
+ //STEP 1: Validate Input Data
//----------------------------
boolean bResult = handleDataValidate(csarId,uploadedInputStream,fileDetail);
if(!bResult)
@@ -471,31 +448,30 @@ public class PackageWrapper {
public Response getOnBoardingResult(String csarId, String operTypeId, String operId)
{
LOG.info("getOnBoardingResult request : csarId:" + csarId + " operTypeId:" + operTypeId + " operId:" + operId);
- if ((null == csarId) || (null == operTypeId) || (null == operId)) {
- return Response.status(Response.Status.BAD_REQUEST).build();
- }
- if ((csarId.isEmpty()) || (operTypeId.isEmpty()) || (operId.isEmpty())) {
+ try {
+ PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
+ if (null == packageData) {
+ return Response.status(Response.Status.PRECONDITION_FAILED).build();
+ }
+
+ handleDelayExec(operId);
+
+ OnBoardingResult oOnBoardingResult = FunctionTestHook.getOnBoardingResult(packageData);
+ if (null == oOnBoardingResult) {
+ return Response.status(Response.Status.PRECONDITION_FAILED).build();
+ }
+ filterOnBoardingResultByOperId(oOnBoardingResult, operId);
+
+ String strResult = ToolUtil.objectToString(oOnBoardingResult);
+ LOG.info("getOnBoardingResult response : " + strResult);
+ return Response.ok(strResult, "application/json").build();
+ } catch (NullPointerException e) {
+ LOG.error("Null param in getOnBoardingResult", e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
- PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
- if (null == packageData) {
- return Response.status(Response.Status.PRECONDITION_FAILED).build();
- }
-
- handleDelayExec(operId);
-
- OnBoardingResult oOnBoardingResult = FunctionTestHook.getOnBoardingResult(packageData);
- if (null == oOnBoardingResult) {
- return Response.status(Response.Status.PRECONDITION_FAILED).build();
- }
- filterOnBoardingResultByOperId(oOnBoardingResult, operId);
-
- String strResult = ToolUtil.objectToString(oOnBoardingResult);
- LOG.info("getOnBoardingResult response : " + strResult);
- return Response.ok(strResult, "application/json").build();
}
-
+
private void filterOnBoardingResultByOperId(OnBoardingResult oOnBoardingResult, String operId)
{
if (0 == operId.compareToIgnoreCase("all")) {
@@ -503,7 +479,7 @@ public class PackageWrapper {
}
if (0 == operId.compareToIgnoreCase("download"))
{
- List<OnBoardingOperResult> operResultListTemp = new ArrayList<OnBoardingOperResult>();
+ List<OnBoardingOperResult> operResultListTemp = new ArrayList<>();
OnBoardingOperResult operResultListTmp = new OnBoardingOperResult();
operResultListTmp.setOperId("download");
operResultListTmp.setStatus(0);
@@ -511,7 +487,7 @@ public class PackageWrapper {
oOnBoardingResult.setOperResult(operResultListTemp);
return;
}
- List<OnBoardingOperResult> operResultListOut = new ArrayList<OnBoardingOperResult>();
+ List<OnBoardingOperResult> operResultListOut = new ArrayList<>();
List<OnBoardingOperResult> operResultList = oOnBoardingResult.getOperResult();
for (OnBoardingOperResult operResult : operResultList) {
if (0 == operResult.getOperId().compareToIgnoreCase(operId)) {
@@ -527,37 +503,37 @@ public class PackageWrapper {
* @param operTypeId
* @return
*/
- public Response getOperResultByOperTypeId(String csarId, String operTypeId)
+ public Response getOperResultByOperTypeId(String csarId, String operTypeId)
{
- LOG.error("getOnBoardingResult request : csarId:"+ csarId + " operTypeId:"+operTypeId);
+ LOG.error("getOnBoardingResult request : csarId:"+ csarId + " operTypeId:"+operTypeId);
if(null == csarId || null == operTypeId || csarId.isEmpty() || operTypeId.isEmpty())
{
- return Response.status(Status.BAD_REQUEST).build();
+ return Response.status(Status.BAD_REQUEST).build();
}
PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
if(null == packageData)
{
- LOG.error("Failed to find package for PackageID:"+ csarId);
- return Response.status(Status.PRECONDITION_FAILED).build();
- }
+ LOG.error("Failed to find package for PackageID:"+ csarId);
+ return Response.status(Status.PRECONDITION_FAILED).build();
+ }
//Get result key to fetch Function Test Results
//---------------------------------------------
String strResult = FunctionTestHook.getFuncTestResults(packageData);
if(null == strResult)
{
- LOG.error("NULL reponse for getOperResultByOperTypeId response :"+ strResult);
- return Response.status(Status.INTERNAL_SERVER_ERROR).build();
- }
- LOG.info("getOperResultByOperTypeId response :"+ strResult);
+ LOG.error("NULL reponse for getOperResultByOperTypeId response :"+ strResult);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).build();
+ }
+ LOG.info("getOperResultByOperTypeId response :"+ strResult);
return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
}
- private boolean handleDataValidate(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
+ private boolean handleDataValidate(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
{
boolean bvalidateOk = false;
- if ((null != uploadedInputStream) && (fileDetail != null) && !ToolUtil.isEmptyString(packageId))
+ if ((null != uploadedInputStream) && (fileDetail != null) && !ToolUtil.isEmptyString(packageId))
{
bvalidateOk = true;
}
@@ -572,7 +548,7 @@ public class PackageWrapper {
{
LOG.info("Get OnBoarding Steps request Received !!!");
- String filePath = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getAppDeployPath() + File.separator +"generalconfig/OnBoardingSteps.json";
+ String filePath = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getAppDeployPath() + File.separator +"generalconfig/OnBoardingSteps.json";
LOG.info("Onboarding Steps Json file Path :" + filePath);
OnBoardingSteps oOnBoardingSteps = (OnBoardingSteps)FileUtil.readJsonDatafFromFile(filePath, OnBoardingSteps.class);
@@ -583,19 +559,21 @@ public class PackageWrapper {
LOG.info("getOnBoardingSteps response :" + strResult);
return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
}
-
- private void handleDelayExec(String operId)
+
+ private void handleDelayExec(String operId)
{
- if (0 == operId.compareToIgnoreCase(CommonConstant.functionTest.FUNCTEST_EXEC))
+ if (0 == operId.compareToIgnoreCase(CommonConstant.functionTest.FUNCTEST_EXEC))
{
- try
+ try
{
Thread.sleep(8000);
- }
- catch (InterruptedException e)
+ }
+ catch (InterruptedException e)
{
LOG.info("handleDelayExex response : ", e);
+ Thread.currentThread().interrupt();
}
}
}
}
+
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java
index a763a361..c55019d5 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java
@@ -113,7 +113,7 @@ public class PackageWrapperUtil {
result = PackageManager.getInstance().queryPackageByCsarId(csarId).get(0);
}
} catch (MarketplaceResourceException e1) {
- LOG.error("query package by csarId from db error ! " + e1.getMessage());
+ LOG.error("query package by csarId from db error ! " + e1.getMessage(), e1);
}
return result;
}
@@ -130,12 +130,10 @@ public class PackageWrapperUtil {
PackageMeta packageMeta = new PackageMeta();
long size = getPacakgeSize(fileLocation);
packageMeta.setFormat(basic.getFormat());
- String usedPackageId = null;
+ String usedPackageId = packageId;
if(null == packageId)
{
usedPackageId = ToolUtil.generateId();
- } else {
- usedPackageId = packageId;
}
packageMeta.setCsarId(usedPackageId);
@@ -167,13 +165,13 @@ public class PackageWrapperUtil {
* @return download uri
*/
public static String getPackagePath(String csarId) {
- ArrayList<PackageData> packageList = new ArrayList<PackageData>();
+ ArrayList<PackageData> packageList = new ArrayList<>();
String downloadUri = null;
try {
packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);
downloadUri = packageList.get(0).getDownloadUri();
} catch (MarketplaceResourceException e1) {
- LOG.error("Query CSAR package by ID failed ! csarId = " + csarId);
+ LOG.error("Query CSAR package by ID failed ! csarId = " + csarId, e1);
}
return downloadUri;
}
@@ -198,11 +196,10 @@ public class PackageWrapperUtil {
public static List<PackageMeta> packageDataList2PackageMetaList(
List<PackageData> dbResult) {
ArrayList<PackageMeta> metas = new ArrayList<>();
- PackageMeta meta = null;
if (! dbResult.isEmpty()) {
for (int i = 0; i < dbResult.size(); i++) {
PackageData data = dbResult.get(i);
- meta = packageData2PackageMeta(data);
+ PackageMeta meta = packageData2PackageMeta(data);
metas.add(meta);
}
}
@@ -245,8 +242,7 @@ public class PackageWrapperUtil {
} else {
url += uri;
}
- String urlresult = url.replace("\\", "/");
- return urlresult;
+ return url.replace("\\", "/");
}
public static String getDownloadUriHead() {
@@ -275,20 +271,20 @@ public class PackageWrapperUtil {
boolean isXmlCsar = false;
try {
String tempfolder = unzipDir;
- ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder);
+ List<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder);
if (unzipFiles.isEmpty()) {
isXmlCsar = true;
}
for (String unzipFile : unzipFiles) {
- if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
- basicInfo = readManifest(unzipFile);
+ if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
+ basicInfo = readManifest(unzipFile);
}
if (ToolUtil.isYamlFile(new File(unzipFile))) {
isXmlCsar = false;
}
}
} catch (IOException e1) {
- LOG.error("judge package type error ! " + e1.getMessage());
+ LOG.error("judge package type error ! " + e1.getMessage(), e1);
}
if (isXmlCsar) {
basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT);
@@ -298,81 +294,51 @@ public class PackageWrapperUtil {
return basicInfo;
}
- private static PackageBasicInfo readCsarMeta(String unzipFile) {
+ /**
+ * Reads the manifest file in the package and fills the basic infor about package
+ * @param unzipFile
+ * @return basic infor about package
+ */
+ private static PackageBasicInfo readManifest(String unzipFile) {
+
+ // Fix the package type to CSAR, temporary
PackageBasicInfo basicInfo = new PackageBasicInfo();
+ basicInfo.setType(EnumType.CSAR);
+
File file = new File(unzipFile);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+
String tempString = null;
while ((tempString = reader.readLine()) != null) {
- if (tempString.equals("")) {
+
+ // If line is empty, ignore
+ if ("".equals(tempString)) {
continue;
}
+
int count1 = tempString.indexOf(":");
String meta = tempString.substring(0, count1).trim();
- if (CommonConstant.CSAR_TYPE_META.equalsIgnoreCase(meta)) {
- int count = tempString.indexOf(":") + 1;
- basicInfo.setType(EnumType.valueOf(tempString.substring(count).trim()));
- }
- if (CommonConstant.CSAR_PROVIDER_META.equalsIgnoreCase(meta)) {
+
+ // Check for the package provider name
+ if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) {
int count = tempString.indexOf(":") + 1;
basicInfo.setProvider(tempString.substring(count).trim());
}
- if (CommonConstant.CSAR_VERSION_META.equalsIgnoreCase(meta)) {
+
+ // Check for package version
+ if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) {
int count = tempString.indexOf(":") + 1;
basicInfo.setVersion(tempString.substring(count).trim());
}
}
+
reader.close();
- } catch (IOException e2) {
- e2.printStackTrace();
+ } catch (IOException e) {
+ LOG.error("Exception while parsing manifest file" + e, e);
}
+
return basicInfo;
}
- /**
- * Reads the manifest file in the package and fills the basic infor about package
- * @param unzipFile
- * @return basic infor about package
- */
- private static PackageBasicInfo readManifest(String unzipFile) {
-
- // Fix the package type to CSAR, temporary
- PackageBasicInfo basicInfo = new PackageBasicInfo();
- basicInfo.setType(EnumType.CSAR);
-
- File file = new File(unzipFile);
- try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
-
- String tempString = null;
- while ((tempString = reader.readLine()) != null) {
-
- // If line is empty, ignore
- if (tempString.equals("")) {
- continue;
- }
-
- int count1 = tempString.indexOf(":");
- String meta = tempString.substring(0, count1).trim();
-
- // Check for the package provider name
- if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) {
- int count = tempString.indexOf(":") + 1;
- basicInfo.setProvider(tempString.substring(count).trim());
- }
-
- // Check for package version
- if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) {
- int count = tempString.indexOf(":") + 1;
- basicInfo.setVersion(tempString.substring(count).trim());
- }
- }
-
- reader.close();
- } catch (IOException e) {
- LOG.error("Exception while parsing manifest file" + e);
- }
-
- return basicInfo;
- }
/**
* get package format enum.
* @param format package format