Refactoring Consolidation Service
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / OnboardingUtillViaApis.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utilities;
22
23 public class OnboardingUtillViaApis {
24
25 //      protected static Map<String, String> prepareHeadersMap(String userId) {
26 //              Map<String, String> headersMap = new HashMap<String, String>();
27 //              headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
28 //              headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
29 //              headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
30 //              return headersMap;
31 //      }
32         
33 //      public static Pair<String, VendorSoftwareProductObject> createVspViaApis(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user, Boolean skipReport) throws Exception {
34 //
35 //              VendorSoftwareProductObject vendorSoftwareProductObject = new VendorSoftwareProductObject();
36 //
37 //              AmdocsLicenseMembers amdocsLicenseMembers = OnboardingUiUtils.createVendorLicense(user);
38 //              Pair<String, Map<String, String>> createVendorSoftwareProduct = OnboardingUiUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user, amdocsLicenseMembers);
39 //              Map<String, String> map = createVendorSoftwareProduct.right;
40 //              vendorSoftwareProductObject.setAttContact(map.get("attContact"));
41 //              vendorSoftwareProductObject.setCategory(map.get("category"));
42 //              vendorSoftwareProductObject.setComponentId(map.get("componentId"));
43 //              vendorSoftwareProductObject.setDescription(map.get("description"));
44 //              vendorSoftwareProductObject.setSubCategory(map.get("subCategory"));
45 //              vendorSoftwareProductObject.setVendorName(map.get("vendorName"));
46 //              vendorSoftwareProductObject.setVspId(map.get("vspId"));
47 //              Pair<String, VendorSoftwareProductObject> pair = new Pair<String, VendorSoftwareProductObject>(createVendorSoftwareProduct.left, vendorSoftwareProductObject);
48 //              return pair;
49 //      }
50         
51 /*      public static Resource createResourceFromVSP(Pair<String, Map<String, String>> createVendorSoftwareProduct, String vspName) throws Exception {
52                 List<String> tags = new ArrayList<>();
53                 tags.add(vspName);
54                 Map<String, String> map = createVendorSoftwareProduct.right;
55                 ResourceReqDetails resourceDetails = new ResourceReqDetails();
56                 resourceDetails.setCsarUUID(map.get("vspId"));
57                 resourceDetails.setCsarVersion("1.0");
58                 resourceDetails.setName(vspName);
59                 resourceDetails.setTags(tags);
60                 resourceDetails.setDescription(map.get("description"));
61                 resourceDetails.setResourceType(map.get("componentType"));
62                 resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory());
63                 resourceDetails.setVendorName(map.get("vendorName"));
64                 resourceDetails.setVendorRelease("1.0");
65                 resourceDetails.setResourceType("VF");
66                 resourceDetails.setResourceVendorModelNumber("666");
67                 resourceDetails.setContactId(map.get("attContact"));
68                 resourceDetails.setIcon("defaulticon");
69                 Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
70                 
71                 return resource; 
72         }*/
73
74 //      public static Resource createResourceFromVSP(ResourceReqDetails resourceDetails) throws Exception {
75 //              Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
76 //              return resource;
77 //      }
78         
79 //      public static void downloadToscaCsarToDirectory(Component component, File file) {
80 //              try {
81 //                      Either<String, RestResponse> componentToscaArtifactPayload = AtomicOperationUtils.getComponenetArtifactPayload(component, "assettoscacsar");
82 //                      if(componentToscaArtifactPayload.left().value() != null){
83 //                              convertPayloadToFile(componentToscaArtifactPayload.left().value(), file);
84 //                      }
85 //              } catch (Exception e) {
86 //                      e.printStackTrace();
87 //              }
88 //      }
89         
90 //      public static void convertPayloadToFile(String payload, File file, boolean isBased64, boolean isSdcFormat) throws IOException{
91 //              
92 //              Gson gson = new Gson();
93 //              byte[] byteArray = null;
94 //              Map<String, String> fromJson;
95 //              @SuppressWarnings("unchecked")
96 //              String string = null;// = fromJson.get("base64Contents").toString();
97 //              if(isSdcFormat){
98 //                      fromJson = gson.fromJson(payload, Map.class);
99 //                      string = fromJson.get("base64Contents").toString();
100 //              }else if (isBased64) {
101 //                      byteArray = Base64.decode(string.getBytes(StandardCharsets.UTF_8));
102 //              }else{
103 //                      byteArray = payload.getBytes(StandardCharsets.UTF_8);
104 //              }
105 //              File downloadedFile = new File(file.getAbsolutePath());
106 //              FileOutputStream fos = new FileOutputStream(downloadedFile);
107 //              fos.write(byteArray);
108 //              fos.flush();
109 //              fos.close();
110 //              
111 //      }
112
113 //      public static void convertPayloadToFile(String payload, File file) throws IOException{
114 //
115 //              Gson gson = new Gson();
116 //              @SuppressWarnings("unchecked")
117 //              Map<String, String> fromJson = gson.fromJson(payload, Map.class);
118 //              String string = fromJson.get("base64Contents").toString();
119 //              byte[] byteArray = Base64.decode(string.getBytes(StandardCharsets.UTF_8));
120 //              File downloadedFile = new File(file.getAbsolutePath());
121 //              FileOutputStream fos = new FileOutputStream(downloadedFile);
122 //              fos.write(byteArray);
123 //              fos.flush();
124 //              fos.close();
125 //      }
126         
127         
128 //      public static void convertPayloadToZipFile(String payload, File file) throws IOException{
129 //
130 //              byte[] byteArray = payload.getBytes(StandardCharsets.ISO_8859_1);
131 //              File downloadedFile = new File(file.getAbsolutePath());
132 //              FileOutputStream fos = new FileOutputStream(downloadedFile);
133 //              fos.write(byteArray);
134 //              fos.flush();
135 //              fos.close();
136 //
137 //
138 ////            ZipOutputStream fos = null;
139 ////
140 ////
141 ////            for (Charset charset : Charset.availableCharsets().values()) {
142 ////                    try{
143 ////            //              System.out.println("How to do it???");
144 ////                            File downloadedFile = new File(file.getAbsolutePath() + "_" + charset +".csar");
145 ////                            fos = new ZipOutputStream(new FileOutputStream(downloadedFile));
146 ////                            byte[] byteArray = payload.getBytes(charset);
147 ////                            fos.write(byteArray);
148 ////                            fos.flush();
149 ////
150 ////                    }
151 ////                    catch(Exception e){
152 ////                            fos.close();
153 ////                    }
154 ////            }
155 //              System.out.println("");
156 //
157 ////            ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(byteArray));
158 ////            ZipEntry entry = null;
159 ////            while ((entry = zipStream.getNextEntry()) != null) {
160 ////
161 ////                String entryName = entry.getName();
162 ////
163 ////                FileOutputStream out = new FileOutputStream(file+"/"+entryName);
164 ////
165 ////                byte[] byteBuff = new byte[4096];
166 ////                int bytesRead = 0;
167 ////                while ((bytesRead = zipStream.read(byteBuff)) != -1)
168 ////                {
169 ////                    out.write(byteBuff, 0, bytesRead);
170 ////                }
171 ////
172 ////                out.close();
173 ////                zipStream.closeEntry();
174 ////            }
175 ////            zipStream.close();
176 ////
177 //
178 //
179 //
180 //              BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(payload.getBytes(StandardCharsets.ISO_8859_1)));
181 //              String filePath = file.toString();
182 //              BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
183 //              int inByte;
184 //              while((inByte = bis.read()) != -1) bos.write(inByte);
185 //              bis.close();
186 //              bos.close();
187 //      }
188         
189 //      public static Either<String, RestResponse> getVendorSoftwareProduct(String vspId, User user, Boolean validateState) throws Exception {
190 //
191 //              Config config = Utils.getConfig();
192 //              String url = String.format(Urls.GET_VENDOR_SOFTWARE_PRODUCT, config.getCatalogBeHost(), config.getCatalogBePort(), vspId);
193 //              String userId = user.getUserId();
194 //              Map<String, String> headersMap = prepareHeadersMap(userId);
195 //              headersMap.put(HttpHeaderEnum.X_ECOMP_REQUEST_ID_HEADER.getValue(), "123456");
196 //              headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "*/*");
197 //              headersMap.put("Accept-Encoding", "gzip, deflate, br");
198 //              HttpRequest http = new HttpRequest();
199 //              RestResponse response = http.httpSendGet(url, headersMap);
200 //              if (validateState) {
201 //                      assertTrue("add property to resource failed: " + response.getResponseMessage(), response.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
202 //              }
203 //              if (response.getErrorCode() != BaseRestUtils.STATUS_CODE_SUCCESS && response.getResponse().getBytes() == null && response.getResponse().getBytes().length == 0) {
204 //                      return Either.right(response);
205 //              }
206 //              return Either.left(response.getResponse());
207 //
208 //      }
209         
210 //      public static ResourceReqDetails prepareOnboardedResourceDetailsBeforeCreate(ResourceReqDetails resourceDetails, VendorSoftwareProductObject vendorSoftwareProductObject) {
211 //
212 //              List<String> tags = new ArrayList<>();
213 //              tags.add(vendorSoftwareProductObject.getName());
214 ////            ResourceReqDetails resourceDetails = new ResourceReqDetails();
215 //              resourceDetails.setCsarUUID(vendorSoftwareProductObject.getVspId());
216 //              resourceDetails.setCsarVersion(vendorSoftwareProductObject.getVersion());
217 //              resourceDetails.setName(vendorSoftwareProductObject.getName());
218 //              resourceDetails.setTags(tags);
219 //              resourceDetails.setDescription(vendorSoftwareProductObject.getDescription());
220 ////            resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory());
221 //              resourceDetails.setVendorName(vendorSoftwareProductObject.getVendorName());
222 ////            resourceDetails.setVendorRelease("1.0");
223 //              resourceDetails.setResourceType("VF");
224 //              resourceDetails.setResourceVendorModelNumber("666");
225 //              resourceDetails.setContactId(vendorSoftwareProductObject.getAttContact());
226 ////            resourceDetails.setIcon("defaulticon");
227 //
228 //              return resourceDetails;
229 //      }
230         
231         /*public static ServiceReqDetails prepareServiceDetailsBeforeCreate(ServiceReqDetails serviceDetails, User user) {
232
233                 serviceDetails.setServiceType("MyServiceType");
234                 serviceDetails.setServiceRole("MyServiceRole");
235                 serviceDetails.setNamingPolicy("MyServiceNamingPolicy");
236                 serviceDetails.setEcompGeneratedNaming(true);
237                 
238                 return serviceDetails;
239         }*/
240 }