2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.utils;
23 import org.openecomp.core.utilities.file.FileUtils;
24 import org.openecomp.sdc.logging.api.Logger;
25 import org.openecomp.sdc.logging.api.LoggerFactory;
26 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
27 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
28 import org.openecomp.sdc.versioning.dao.types.Version;
31 import java.io.FileInputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.util.List;
35 import java.util.zip.ZipEntry;
36 import java.util.zip.ZipOutputStream;
38 public class VSPCommon {
40 private static final Logger log = (Logger) LoggerFactory.getLogger(VSPCommon.class.getName());
42 public static VspDetails createVspDetails(String id, Version version, String name, String desc,
43 String vendorName, String vlm, String icon,
44 String category, String subCategory,
45 String licenseAgreement, List<String> featureGroups) {
46 VspDetails vspDetails = new VspDetails(id, version);
47 vspDetails.setName(name);
48 vspDetails.setDescription(desc);
49 vspDetails.setIcon(icon);
50 vspDetails.setCategory(category);
51 vspDetails.setSubCategory(subCategory);
52 vspDetails.setVendorName(vendorName);
53 vspDetails.setVendorId(vlm);
54 vspDetails.setVlmVersion(new Version(1, 0));
55 vspDetails.setLicenseAgreement(licenseAgreement);
56 vspDetails.setFeatureGroups(featureGroups);
61 public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc,
63 VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity();
64 vendorLicenseModel.setVendorName(name);
65 vendorLicenseModel.setDescription(desc);
66 vendorLicenseModel.setIconRef(icon);
67 return vendorLicenseModel;
70 public static void zipDir(File file, String path, ZipOutputStream zos) {
71 zipDir(file, path, zos, false);
74 public static void zipDir(File file, String path, ZipOutputStream zos, boolean isRootDir) {
75 if (file.isDirectory()) {
76 path += File.separator + file.getName();
77 File[] files = file.listFiles();
79 for (File innerFile : files) {
81 zipDir(innerFile, "", zos, false);
83 zipDir(innerFile, path, zos, false);
90 if (!path.isEmpty()) {
91 path += File.separator;
93 zos.putNextEntry(new ZipEntry(path + file.getName()));
94 InputStream is = new FileInputStream(file);
95 byte[] data = FileUtils.toByteArray(is);
98 } catch (IOException exception) {
99 log.debug("",exception);