diff options
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace')
17 files changed, 514 insertions, 619 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..1ba18cd6 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,7 @@ package org.onap.vnfsdk.marketplace.common; public class CommonConstant { + // Package Status public static final String PACKAGE_STATUS_DELETING = "deleting"; @@ -39,9 +40,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 +54,37 @@ 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 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 +98,16 @@ public class CommonConstant { private HttpContext() { } } - + + 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 MethodType { public static final String POST = "post"; @@ -120,12 +121,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 +134,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..642fc8f0 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,53 +101,44 @@ 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)); - while (true) { - int length = input.read(buffer); - if (length == -1) { - break; - } + try ( + InputStream input = zipFile.getInputStream(entry); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + ) { + int length = 0; + while ((length = input.read(buffer)) != -1) { 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 +153,7 @@ public final class FileUtil { /** * close OutputStream. - * + * * @param outputStream the output stream to close */ public static void closeOutputStream(OutputStream outputStream) { @@ -174,7 +165,7 @@ public final class FileUtil { logger.info("error while closing OutputStream!", e1); } } - + public static void closeFileStream(FileInputStream ifs) { try { if (ifs != null) { @@ -187,14 +178,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 +203,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 +241,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 +288,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..af6f428f 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 @@ -14,18 +14,30 @@ * limitations under the License. */ package org.onap.vnfsdk.marketplace.common; +import java.net.InetAddress; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class HttpServerPathConfig { + public static final Logger logger = LoggerFactory.getLogger(FileUtil.class); + 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/"); + try { + InetAddress address = InetAddress.getByName("localhost"); + String msbAddress = "http://" + address.getHostAddress() + ":8080"; + MsbAddrConfig.setMsbAddress(msbAddress); + HttpServerAddrConfig.setHttpServerAddress(msbAddress); + HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/"); + } catch (Exception e) { + logger.info("error while config htttp server", e); + } } public static String getHttpServerPath() { @@ -36,3 +48,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/common/RestUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/RestUtil.java index 557428d6..ea157ace 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/RestUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/RestUtil.java @@ -19,16 +19,17 @@ import javax.ws.rs.core.Response; public class RestUtil { - + private RestUtil() { + } /** * get rest exception. * @param errorMsg error message * @return Response */ public static Response getRestException(String errorMsg) { - String code = "001"; return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(new CommonErrorResponse(errorMsg)).build(); + .entity(new CommonErrorResponse(errorMsg)).build(); } } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/ToolUtil.java index b9fe5caa..1f3a79d6 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/ToolUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/ToolUtil.java @@ -15,27 +15,26 @@ */ package org.onap.vnfsdk.marketplace.common; -import com.google.gson.Gson; -import com.google.gson.JsonElement; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.DecimalFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.UUID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; + /** * common utility class. - * + * */ public class ToolUtil { private static final Logger LOG = LoggerFactory.getLogger(ToolUtil.class); @@ -46,6 +45,9 @@ public class ToolUtil { public static final int FILE_PERCENT = 1024 * 1024; // 1M + private ToolUtil() { + } + public static boolean isEmptyString(String val) { return val == null || "".equals(val); } @@ -60,7 +62,7 @@ public class ToolUtil { /** * trimed string. - * + * * @param val string array to trim * @return String[] */ @@ -82,7 +84,7 @@ public class ToolUtil { /** * store chunk file to local temp directory. - * + * * @param dirName directory name * @param fileName file name * @param uploadedInputStream upload input stream @@ -97,32 +99,29 @@ public class ToolUtil { tmpDir.mkdirs(); } File file = new File(tmpDir + File.separator + fileName); - OutputStream os = null; - try { + + try ( + OutputStream os = new FileOutputStream(file, true); + ) + { int read = 0; byte[] bytes = new byte[1024]; - os = new FileOutputStream(file, true); while ((read = uploadedInputStream.read(bytes)) != -1) { os.write(bytes, 0, read); } os.flush(); return file.getAbsolutePath(); - } finally { - if (os != null) { - os.close(); - } } } /** * get temp dirctory when upload package. - * + * * @param dirName temp directory name * @param fileName package name * @return String */ public static String getTempDir(String dirName, String fileName) { - // File tmpDir = new File(File.separator + dirName); return Thread.currentThread().getContextClassLoader().getResource("/").getPath() + dirName + File.separator + fileName.replace(".csar", ""); } @@ -134,13 +133,13 @@ public class ToolUtil { /** * delete file. - * + * * @param dirName the directory of file * @param fileName file name * @return boolean */ public static boolean deleteFile(String dirName, String fileName) { - File tmpDir = new File(getCataloguePath() + File.separator + dirName); + File tmpDir = new File(File.separator + dirName); if (!tmpDir.exists()) { return true; } @@ -151,22 +150,17 @@ public class ToolUtil { return true; } - public static String getCataloguePath() { -// return Config.getConfigration().getCataloguePath(); - return ""; - } - public static String getCatalogueCsarPath() { - return getCataloguePath() + File.separator + CATALOGUE_CSAR_DIR_NAME; + return File.separator + CATALOGUE_CSAR_DIR_NAME; } public static String getCatalogueImagePath() { - return getCataloguePath() + File.separator + CATALOGUE_IMAGE_DIR_NAME; + return File.separator + CATALOGUE_IMAGE_DIR_NAME; } /** * get file size. - * + * * @param file file which to get the size * @param fileUnit file unit * @return String file size @@ -187,7 +181,7 @@ public class ToolUtil { /** * get file size by content. - * + * * @param contentRange content range * @return String */ @@ -199,7 +193,7 @@ public class ToolUtil { /** * fix package format. - * + * * @param csarId package ID * @return String */ @@ -214,7 +208,7 @@ public class ToolUtil { /** * delete the file and file directory. - * + * * @param dir file * @return boolean */ @@ -231,17 +225,9 @@ public class ToolUtil { return dir.delete(); } - // public static boolean unZipCsar(String fileLocation) throws IOException { - // String tempfolder=System.getProperty("java.io.tmpdir"); - // ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder); - // if(unzipFiles.isEmpty()){ - // return true; - // } - // } - /** * judge the file's format is yaml or not. - * + * * @param file file to judge * @return boolean */ @@ -254,7 +240,7 @@ public class ToolUtil { /** * remove the csar suffix. - * + * * @param csarName package name * @return String */ @@ -264,7 +250,7 @@ public class ToolUtil { /** * add the csar fuffix. - * + * * @param csarName package name * @return String */ @@ -277,7 +263,7 @@ public class ToolUtil { /** * process file name. - * + * * @param fileName file's name * @return String */ @@ -292,7 +278,7 @@ public class ToolUtil { /** * exchange object to string. - * + * * @param obj object * @return String */ @@ -311,7 +297,7 @@ public class ToolUtil { /** * get the size format according file size. - * + * * @param fileSize file size * @return size format */ @@ -353,7 +339,7 @@ public class ToolUtil { Gson gson = new Gson(); return gson.toJson(template); } - + /** * @param value * @return @@ -365,5 +351,6 @@ public class ToolUtil { return value.toString(); } - + } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/entity/BaseData.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/entity/BaseData.java index 30a074a2..3168a6a2 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/entity/BaseData.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/entity/BaseData.java @@ -16,5 +16,7 @@ package org.onap.vnfsdk.marketplace.db.entity; public class BaseData { - + public BaseData() { + //Do nothing + } } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeException.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeException.java index 9921a8cb..85d486c9 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeException.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeException.java @@ -23,18 +23,6 @@ public class ErrorCodeException extends Exception { private final int errorCode; private final String[] arguments; - private static String defaultText = null; - - - public static void setDefaultText(String text) { - defaultText = text; - } - - - public static String getDefaultText() { - return defaultText; - } - public ErrorCodeException(int code, String debugMessage) { this(code, debugMessage, null); @@ -145,3 +133,4 @@ public class ErrorCodeException extends Exception { } } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java index 67cfb355..1e152991 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/impl/MarketplaceDaoImpl.java @@ -32,9 +32,9 @@ import org.slf4j.LoggerFactory; /** * This class is the implementation for the DAO Layer for Driver Manager. * <br/> - * + * * @author - * @version + * @version */ public class MarketplaceDaoImpl implements IMarketplaceDao { @@ -43,12 +43,12 @@ public class MarketplaceDaoImpl implements IMarketplaceDao { private SqlSessionFactory sqlSessionFactory = null; /** - * + * * Constructor<br/> * <p> * </p> - * - * @since + * + * @since */ public MarketplaceDaoImpl() { sqlSessionFactory = ConnectionUtil.getSession(); @@ -57,21 +57,20 @@ public class MarketplaceDaoImpl implements IMarketplaceDao { /** * get all package data. * <br/> - * + * * @return - * @since + * @since */ + @Override public List<PackageData> getAllPackageData() { SqlSession session = sqlSessionFactory.openSession(); - List<PackageData> csars = null; + List<PackageData> csars = null; try { IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class); csars = mapper.getAllPackageData(); session.commit(); } catch(PersistenceException e) { LOGGER.error("Exception caught {}", e); -// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, -// ErrorCode.INVALID_DB); } finally { session.close(); } @@ -81,59 +80,57 @@ public class MarketplaceDaoImpl implements IMarketplaceDao { /** * saving the package data object to the DB using the mybatis. * <br/> - * + * * @param dirverInstance - * @since + * @since */ - public void savePackageData(PackageData lPackageData) { - SqlSession session = sqlSessionFactory.openSession(); + @Override + public void savePackageData(PackageData lPackageData) { + SqlSession session = sqlSessionFactory.openSession(); try { IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class); mapper.savePackageData(lPackageData); session.commit(); } catch(PersistenceException e) { LOGGER.error("Exception caught {}", e); -// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, -// ErrorCode.INVALID_DB); } finally { session.close(); } - - } - public List<PackageData> getPackageData(String csarId) { + } + + @Override + public List<PackageData> getPackageData(String csarId) { SqlSession session = sqlSessionFactory.openSession(); - List<PackageData> csars = null; + List<PackageData> csars = null; try { IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class); csars = mapper.getPackageData(csarId); session.commit(); } catch(PersistenceException e) { LOGGER.error("Exception caught {}", e); -// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, -// ErrorCode.INVALID_DB); } finally { session.close(); } return csars; - } + } - public void deletePackageData(String csarId) { - SqlSession session = sqlSessionFactory.openSession(); + @Override + public void deletePackageData(String csarId) { + SqlSession session = sqlSessionFactory.openSession(); try { IMarketplaceMapper mapper = session.getMapper(IMarketplaceMapper.class); mapper.deletePackageData(csarId); session.commit(); } catch(PersistenceException e) { - LOGGER.error("Exception caught {}", e); -// throw new DriverManagerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, -// ErrorCode.INVALID_DB); + LOGGER.error("Exception caught {}", e);; } finally { session.close(); } - - } + } + + @Override public void updatePackageData(PackageData oPackageData) { SqlSession session = sqlSessionFactory.openSession(); try { @@ -145,6 +142,7 @@ public class MarketplaceDaoImpl implements IMarketplaceDao { } finally { session.close(); } - - } + + } } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/entity/response/PackageMeta.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/entity/response/PackageMeta.java index 49b78429..e094fc87 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/entity/response/PackageMeta.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/entity/response/PackageMeta.java @@ -82,14 +82,6 @@ public class PackageMeta { this.size = size; } - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - public String getProvider() { return provider; } @@ -98,6 +90,14 @@ public class PackageMeta { this.provider = provider; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + public String getType() { return type; } @@ -139,6 +139,13 @@ public class PackageMeta { } + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } public String getShortDesc() { return shortDesc; @@ -148,14 +155,6 @@ public class PackageMeta { this.shortDesc = shortDesc; } - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - public String getRemarks() { return remarks; } @@ -182,3 +181,4 @@ public class PackageMeta { } } + 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 diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java index 13dcf2f6..d9081166 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java @@ -41,7 +41,6 @@ import org.junit.Test; import org.onap.vnfsdk.marketplace.common.FileUtil; import org.onap.vnfsdk.marketplace.common.JsonUtil; import org.onap.vnfsdk.marketplace.common.ToolUtil; -import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil; import org.onap.vnfsdk.marketplace.db.entity.PackageData; import org.onap.vnfsdk.marketplace.db.impl.MarketplaceDaoImpl; import org.onap.vnfsdk.marketplace.db.resource.PackageManager; @@ -62,14 +61,13 @@ import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest; import org.onap.vnfsdk.marketplace.onboarding.entity.ResultKey; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook; -import org.onap.vnfsdk.marketplace.resource.PackageResource; import org.onap.vnfsdk.marketplace.rest.RestResponse; import org.onap.vnfsdk.marketplace.rest.RestfulClient; import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper; import org.onap.vnfsdk.marketplace.wrapper.PackageWrapperUtil; -import mockit.MockUp; import mockit.Mock; +import mockit.MockUp; public class PackageResourceTest { @@ -112,7 +110,7 @@ public class PackageResourceTest { catch(Exception e) { e.printStackTrace(); } - + filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; file = new File(filePath); if(!file.exists()) { @@ -121,7 +119,7 @@ public class PackageResourceTest { StringBuilder sb = new StringBuilder(); sb.append("test data"); - + filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "temp.zip"; file = new File(filePath); try { @@ -143,15 +141,15 @@ public class PackageResourceTest { public void testQueryPackageListByCond() throws Exception{ new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getAllPackageData() { - return new ArrayList<PackageData>(); + public List<PackageData> getAllPackageData() { + return new ArrayList<PackageData>(); } }; try { response = PackageWrapper.getInstance().queryPackageListByCond( null, null, null, null, null); } catch( Exception e ) { e.printStackTrace(); - } + } assertNotNull( response ); assertEquals( 200, response.getStatus()); @@ -167,11 +165,11 @@ public class PackageResourceTest { return null; } - }; + }; new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { - packageDataList = new ArrayList<PackageData>(); + public List<PackageData> getPackageData( String csarId ) { + packageDataList = new ArrayList<PackageData>(); packageData = new PackageData(); packageData.setCsarId( csarId ); packageData.setDownloadUri( "src\\test\\resources\\clearwater_ns.csar" ); @@ -180,9 +178,9 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Huawei" ); packageDataList.add( packageData ); - return packageDataList; + return packageDataList; } - }; + }; try { response = PackageWrapper.getInstance().queryPackageById( csarID ); @@ -190,53 +188,53 @@ public class PackageResourceTest { e.printStackTrace(); } assertNotNull( response ); - assertEquals( 200, response.getStatus()); - } + assertEquals( 200, response.getStatus()); + } @Test public void testDelPackageFaiure() { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getAllPackageData() { - return new ArrayList<PackageData>(); + public List<PackageData> getAllPackageData() { + return new ArrayList<PackageData>(); } }; new MockUp<MarketplaceDaoImpl>() { @Mock - public void deletePackageData( String csarId ) { - return; + public void deletePackageData( String csarId ) { + return; } }; new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { - return new ArrayList<PackageData>(); + public List<PackageData> getPackageData( String csarId ) { + return new ArrayList<PackageData>(); } - }; + }; try { response = PackageWrapper.getInstance().delPackage( "" ); } catch ( Exception e5 ) { e5.printStackTrace(); - } + } assertEquals( 500, response.getStatus()); try { response = PackageWrapper.getInstance().delPackage( null ); } catch ( Exception e5 ) { e5.printStackTrace(); - } - assertEquals( 500, response.getStatus()); + } + assertEquals( 500, response.getStatus()); } @Test public void testDelPackageSuccess() { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getAllPackageData() { - packageDataList = new ArrayList<PackageData>(); + public List<PackageData> getAllPackageData() { + packageDataList = new ArrayList<PackageData>(); packageData = new PackageData(); packageData.setCsarId( csarID ); packageData.setDownloadUri( "src\\test\\resources\\clearwater_ns.csar" ); @@ -245,28 +243,28 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Huawei" ); packageDataList.add( packageData ); - return packageDataList; + return packageDataList; } }; new MockUp<PackageManager>() { @Mock - public void deletePackage( String csarId ) { - return; + public void deletePackage( String csarId ) { + return; } }; new MockUp<HttpFileManagerImpl>() { @Mock - public boolean delete( String srcPath ) { - return true; + public boolean delete( String srcPath ) { + return true; } }; new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { - packageDataList = new ArrayList<PackageData>(); + public List<PackageData> getPackageData( String csarId ) { + packageDataList = new ArrayList<PackageData>(); packageData = new PackageData(); packageData.setCsarId( csarID ); packageData.setDownloadUri( "src\\test\\resources\\" ); @@ -275,26 +273,26 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Huawei" ); packageDataList.add( packageData ); - return packageDataList; + return packageDataList; } - }; + }; try { response = PackageWrapper.getInstance().delPackage( "csarid" ); } catch ( Exception e ) { e.printStackTrace(); - } + } assertNotNull( response ); - assertEquals( 200, response.getStatus()); + assertEquals( 200, response.getStatus()); } @Test - public void testGetCsarFileUri() { + public void testGetCsarFileUri() { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { - packageDataList = new ArrayList<PackageData>(); + public List<PackageData> getPackageData( String csarId ) { + packageDataList = new ArrayList<PackageData>(); packageData = new PackageData(); packageData.setCsarId( csarId ); packageData.setDownloadUri( "src\\test\\resources\\" ); @@ -303,25 +301,25 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Huawei" ); packageDataList.add( packageData ); - return packageDataList; + return packageDataList; } - }; + }; - new MockUp<PackageWrapper>() { + new MockUp<PackageWrapper>() { @Mock Response downloadCsarPackagesById(String csarId) throws FileNotFoundException - { + { String fileName="src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; InputStream fis = new BufferedInputStream(new FileInputStream(fileName)); return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build(); - } - }; + } + }; response = PackageWrapper.getInstance().getCsarFileUri("csarId"); - assertEquals( 200, response.getStatus() ); + assertEquals( 200, response.getStatus() ); - } + } - @Test + @Test public void testupdateDwonloadCountSuccess() throws Exception { final List<PackageData> pkgList = new ArrayList<PackageData>(); @@ -330,14 +328,14 @@ public class PackageResourceTest { pkgList.add(pkgDataObj); new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData(String csarId) { + public List<PackageData> getPackageData(String csarId) { return pkgList; //return new ArrayList<PackageData>(); } }; new MockUp<MarketplaceDaoImpl>() { @Mock - public void updatePackageData(PackageData oPackageData){ + public void updatePackageData(PackageData oPackageData){ return ; } @@ -355,7 +353,7 @@ public class PackageResourceTest { public void testReUploadPackage() { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { + public List<PackageData> getPackageData( String csarId ) { List<PackageData> packageDataList = new ArrayList<PackageData>(); PackageData packageData = new PackageData(); packageData = new PackageData(); @@ -366,16 +364,16 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Huawei" ); packageDataList.add( packageData ); - return packageDataList; - } - }; + return packageDataList; + } + }; new MockUp<HttpFileManagerImpl>() { @Mock public boolean delete(String srcPath) { return true; } - }; + }; new MockUp<MarketplaceDaoImpl>() { @Mock @@ -453,7 +451,7 @@ public class PackageResourceTest { assertEquals( 417, response.getStatus() ); try { - fileDetail = FormDataContentDisposition.name( "fileName" ).fileName( "clearwater_ns.csar" ).build(); + fileDetail = FormDataContentDisposition.name( "fileName" ).fileName( "clearwater_ns.csar" ).build(); String fileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "clearwater_ns.csar"; inputStream = new FileInputStream(fileName); response = PackageWrapper.getInstance().reUploadPackage( "csarID", inputStream, fileDetail, null, null ); @@ -461,7 +459,7 @@ public class PackageResourceTest { } catch( Exception e ) { e.printStackTrace(); } - } + } @Test public void testgetOperResultByOperTypeIdFailure() throws Exception @@ -477,15 +475,15 @@ public class PackageResourceTest { }; new MockUp<FunctionTestExceutor>(){ @Mock - String getTestResultsByFuncTestKey(String key) - { + String getTestResultsByFuncTestKey(String key) + { return null; } - }; + }; new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { + public List<PackageData> getPackageData( String csarId ) { List<PackageData> packageDataList = new ArrayList<PackageData>(); PackageData packageData = new PackageData(); packageData = new PackageData(); @@ -496,8 +494,8 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Airtel" ); packageDataList.add( packageData ); - return packageDataList; - } + return packageDataList; + } }; @@ -505,7 +503,7 @@ public class PackageResourceTest { response = PackageWrapper.getInstance().getOperResultByOperTypeId( csarID,operTypeId ); } catch ( Exception e5 ) { e5.printStackTrace(); - } + } assertEquals(500,response.getStatus()); try { @@ -517,10 +515,10 @@ public class PackageResourceTest { } @Test - public void testgetOperResultByOperTypeIdSuccess() { + public void testgetOperResultByOperTypeIdSuccess() { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { + public List<PackageData> getPackageData( String csarId ) { List<PackageData> packageDataList = new ArrayList<PackageData>(); PackageData packageData = new PackageData(); packageData = new PackageData(); @@ -531,9 +529,9 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Airtel" ); packageDataList.add( packageData ); - return packageDataList; - } - }; + return packageDataList; + } + }; new MockUp<ToolUtil>() { @Mock @@ -542,15 +540,15 @@ public class PackageResourceTest { return filena; } }; - new MockUp<PackageWrapper>() { + new MockUp<PackageWrapper>() { @Mock Response downloadCsarPackagesById(String csarId) throws FileNotFoundException { String fileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; InputStream fis = new BufferedInputStream(new FileInputStream(fileName)); return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build(); - } - }; + } + }; new MockUp<FunctionTestHook>() { @Mock @@ -562,17 +560,17 @@ public class PackageResourceTest { }; new MockUp<FunctionTestExceutor>(){ @Mock - String getTestResultsByFuncTestKey(String key) { - return "key"; + String getTestResultsByFuncTestKey(String key) { + return "key"; } }; try { - response = PackageWrapper.getInstance().getOperResultByOperTypeId( csarID, operTypeId ); + response = PackageWrapper.getInstance().getOperResultByOperTypeId( csarID, operTypeId ); } catch( Exception e ) { e.printStackTrace(); - } - } + } + } //@Ignore @Test @@ -586,7 +584,7 @@ public class PackageResourceTest { new MockUp<MarketplaceDaoImpl>() { @Mock - public List<PackageData> getPackageData( String csarId ) { + public List<PackageData> getPackageData( String csarId ) { List<PackageData> packageDataList = new ArrayList<PackageData>(); PackageData packageData = new PackageData(); packageData = new PackageData(); @@ -597,16 +595,16 @@ public class PackageResourceTest { packageData.setVersion( "v1.0" ); packageData.setProvider( "Airtel" ); packageDataList.add( packageData ); - return packageDataList; - } - }; + return packageDataList; + } + }; new MockUp<HttpFileManagerImpl>() { @Mock public boolean delete(String srcPath) { return true; } - }; + }; new MockUp<MarketplaceDaoImpl>() { @Mock @@ -710,14 +708,14 @@ public class PackageResourceTest { @Test - public void testGetOnBoardingStepsSuccess() { + public void testGetOnBoardingStepsSuccess() { new MockUp<org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil>() { @Mock String getAppDeployPath() { String path = "src" + File.separator + "main" + File.separator + "resources"; return path; } - }; + }; try { response = PackageWrapper.getInstance().getOnBoardingSteps(); @@ -729,24 +727,24 @@ public class PackageResourceTest { } @Test - public void testGetOnBoardingStepsFailure() { + public void testGetOnBoardingStepsFailure() { new MockUp<org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil>() { @Mock String getAppDeployPath() { - String path = "src" + File.separator + "main" + File.separator + "resources"+ File.separator + "generalconfig"; + String path = "src" + File.separator + "main" + File.separator + "resources"+ File.separator + "generalconfig"; return path; } - }; + }; try { response = PackageWrapper.getInstance().getOnBoardingSteps(); } catch( Exception e ) { e.printStackTrace(); - } + } assertEquals( 500, response.getStatus() ); } - @Test + @Test public void testRestGetClient() { FunctionTestExceutor.getTestResultsByFuncTestKey("GET"); @@ -779,7 +777,7 @@ public class PackageResourceTest { new MockUp<FunctionTestHook>() { @Mock - String getResultStorePath(){ + String getResultStorePath(){ return "src/test/resources"; } @@ -945,13 +943,6 @@ public class PackageResourceTest { } @Test - public void testgetCataloguePath() - { - String res = ToolUtil.getCataloguePath(); - assertEquals(res,""); - } - - @Test public void testgetCatalogueCsarPath() { String res = ToolUtil.getCatalogueCsarPath(); @@ -974,7 +965,7 @@ public class PackageResourceTest { @Test public void teststoreChunkFileInLocal() - { + { try { inputStream = new FileInputStream("src//test//resources//Test.txt"); String res = ToolUtil.storeChunkFileInLocal("src//test//resources","TestOut.txt",inputStream); @@ -995,7 +986,7 @@ public class PackageResourceTest { assertEquals(res,true); } - + @Test public void testToJson() { @@ -1151,9 +1142,9 @@ public class PackageResourceTest { String res = pkgMetaObj.getCreateTime(); assertEquals(res,"05042017"); res = pkgMetaObj.getCsarId(); - assertEquals(res,"csarid"); + assertEquals(res,"csarid"); res = pkgMetaObj.getDetails(); - assertEquals(res,"details"); + assertEquals(res,"details"); res = pkgMetaObj.getDownloadCount()+""; assertEquals(res,"10"); res = pkgMetaObj.getDownloadUri(); @@ -1176,7 +1167,7 @@ public class PackageResourceTest { assertEquals(res,"1000"); res = pkgMetaObj.getType(); assertEquals(res,"type"); - res = pkgMetaObj.getVersion(); + res = pkgMetaObj.getVersion(); assertEquals(res,"1"); } @@ -1200,3 +1191,4 @@ public class PackageResourceTest { } } + |