summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2017-09-27 18:28:54 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2017-10-09 14:21:39 +0800
commita77402ac4a7878b65937acac419c8ad21ad5124d (patch)
tree9258c552b8b89ebd2814d1feae7c159e18e952a9
parentd5633dd617cb6d5992b65c0d1135ec20bfa2b451 (diff)
Remove instantiation of CsarValidator
major: L198 L236 L238 critical: L244 Change-Id: I4fb8a7a230643ec5c598d34c00e11ca5a1ee9327 Signed-off-by: Harry Huang <huangxiangyu5@huawei.com> Issue-Id: VNFSDK-85
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java125
1 files changed, 67 insertions, 58 deletions
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 7cc3ccc4..ce0be720 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
@@ -34,6 +34,7 @@ import javax.ws.rs.core.Response.Status;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.onap.validation.csar.CsarValidator;
import org.onap.vnfsdk.marketplace.common.CommonConstant;
import org.onap.vnfsdk.marketplace.common.FileUtil;
import org.onap.vnfsdk.marketplace.common.JsonUtil;
@@ -58,8 +59,6 @@ import org.onap.vnfsdk.marketplace.onboarding.onboardmanager.OnBoardingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.onap.validation.csar.CsarValidator;
-
import net.sf.json.JSONObject;
public class PackageWrapper {
@@ -184,6 +183,57 @@ public class PackageWrapper {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
+ private UploadPackageResponse manageUpload(String packageId, String fileName, String fileLocation,
+ String details, String contentRange) throws IOException, MarketplaceResourceException
+ {
+ String localDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
+ PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
+ UploadPackageResponse result = new UploadPackageResponse();
+ Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange);
+ if (isEnd)
+ {
+ PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId, fileName, fileLocation, basicInfo, details);
+ 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 null;
+ }
+ }
+ return result;
+ }
+
/**
* Interface for Uploading package
* @param packageId
@@ -232,66 +282,25 @@ public class PackageWrapper {
uploadedInputStream.close();
- try {
- CsarValidator cv = new CsarValidator(packageId, fileLocation);
-
- if (!cv.validateCsar()) {
- LOG.error("Could not validate failed");
- return Response.status(Status.EXPECTATION_FAILED).build();
- }
-
+ try {
+ CsarValidator cv = new CsarValidator(packageId, fileLocation);
- } catch (Exception e) {
- LOG.error("CSAR validation panicked", e);
- return Response.status(Status.EXPECTATION_FAILED).build();
- }
-
+ if (!cv.validateCsar()) {
+ LOG.error("Could not validate failed");
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
+ } catch (Exception e) {
+ LOG.error("CSAR validation panicked", e);
+ return Response.status(Status.EXPECTATION_FAILED).build();
+ }
- PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
- UploadPackageResponse result = new UploadPackageResponse();
- Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange);
- if (isEnd)
+ UploadPackageResponse result = manageUpload(packageId, fileName, fileLocation, details, contentRange);
+ if (null != result)
{
- PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId,fileName, fileLocation, basicInfo, details);
- 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();
+ } else {
+ return Response.serverError().build();
}
- return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
}
/**