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.vendorlicense.dao.types.VendorLicenseModelEntity;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
26 import org.openecomp.sdc.versioning.dao.types.Version;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.util.List;
33 import java.util.zip.ZipEntry;
34 import java.util.zip.ZipOutputStream;
36 public class VSPCommon {
38 public static VspDetails createVspDetails(String id, Version version, String name, String desc,
39 String vendorName, String vlm, String icon,
40 String category, String subCategory,
41 String licenseAgreement, List<String> featureGroups) {
42 VspDetails vspDetails = new VspDetails(id, version);
43 vspDetails.setName(name);
44 vspDetails.setDescription(desc);
45 vspDetails.setIcon(icon);
46 vspDetails.setCategory(category);
47 vspDetails.setSubCategory(subCategory);
48 vspDetails.setVendorName(vendorName);
49 vspDetails.setVendorId(vlm);
50 vspDetails.setVlmVersion(new Version(1, 0));
51 vspDetails.setLicenseAgreement(licenseAgreement);
52 vspDetails.setFeatureGroups(featureGroups);
57 public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc,
59 VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity();
60 vendorLicenseModel.setVendorName(name);
61 vendorLicenseModel.setDescription(desc);
62 vendorLicenseModel.setIconRef(icon);
63 return vendorLicenseModel;
66 public static void zipDir(File file, String path, ZipOutputStream zos) {
67 zipDir(file, path, zos, false);
70 public static void zipDir(File file, String path, ZipOutputStream zos, boolean isRootDir) {
71 if (file.isDirectory()) {
72 path += File.separator + file.getName();
73 File[] files = file.listFiles();
75 for (File innerFile : files) {
77 zipDir(innerFile, "", zos, false);
79 zipDir(innerFile, path, zos, false);
86 if (!path.isEmpty()) {
87 path += File.separator;
89 zos.putNextEntry(new ZipEntry(path + file.getName()));
90 InputStream is = new FileInputStream(file);
91 byte[] data = FileUtils.toByteArray(is);
94 } catch (IOException exception) {
95 exception.printStackTrace();