Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / ArtifactRestUtils.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.utils.rest;
22
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.io.IOException;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.apache.commons.codec.binary.Base64;
32 import org.json.simple.JSONObject;
33 import org.json.simple.JSONValue;
34 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
35 import org.openecomp.sdc.be.model.ArtifactDefinition;
36 import org.openecomp.sdc.be.model.Component;
37 import org.openecomp.sdc.be.model.ComponentInstance;
38 import org.openecomp.sdc.be.model.Resource;
39 import org.openecomp.sdc.be.model.User;
40 import org.openecomp.sdc.ci.tests.api.Urls;
41 import org.openecomp.sdc.ci.tests.config.Config;
42 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
44 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
45 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
46 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
48 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
49 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
50 import org.openecomp.sdc.ci.tests.utils.Utils;
51 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
52 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
53 import org.openecomp.sdc.common.util.ValidationUtils;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.AssertJUnit;
57
58 import com.google.gson.Gson;
59
60 public class ArtifactRestUtils extends BaseRestUtils {
61         private static Logger logger = LoggerFactory.getLogger(ArtifactRestUtils.class.getName());
62         
63         
64         // External API
65         // Delete Artifact on rI of the asset 
66         public static RestResponse externalAPIDeleteArtifactOfComponentInstanceOnAsset(Component component, User user, ComponentInstance resourceInstance, String artifactUUID) throws IOException {
67                 Config config = Utils.getConfig();
68                 String resourceType = null;
69                 String resourceUUID = component.getUUID();
70                 String resourceInstanceName = resourceInstance.getNormalizedName();
71                 
72                 System.out.println(component.getComponentType());
73                 
74                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
75                         resourceType = "resources";
76                 } else {
77                         resourceType = "services";
78                 }
79                 
80                 String url = String.format(Urls.DELETE_EXTRNAL_API_DELETE_ARTIFACT_OF_COMPONENTINSTANCE_ON_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, resourceInstanceName, artifactUUID);
81                 
82                 return deleteInformationalArtifact(user, url);
83         }
84         
85         // Delete Artifact of the asset 
86         public static RestResponse externalAPIDeleteArtifactOfTheAsset(Component component, User user, String artifactUUID) throws IOException {
87                 Config config = Utils.getConfig();
88                 String resourceType = null;
89                 String resourceUUID = component.getUUID();
90                 
91                 System.out.println(component.getComponentType());
92                 
93                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
94                         resourceType = "resources";
95                 } else {
96                         resourceType = "services";
97                 }
98                 
99                 String url = String.format(Urls.DELETE_EXTRNAL_API_DELETE_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, artifactUUID);
100                 
101                 RestResponse restResponse = deleteInformationalArtifact(user, url);
102                 
103                 return restResponse;
104         }
105         
106         
107         // Update Artifact on rI of the asset 
108         public static RestResponse externalAPIUpdateArtifactOfComponentInstanceOnAsset(Component component, User user, ArtifactReqDetails artifactReqDetails, ComponentInstance resourceInstance, String artifactUUID) throws IOException {
109                 Config config = Utils.getConfig();
110                 String resourceType = null;
111                 String resourceUUID = component.getUUID();
112                 String resourceInstanceName = resourceInstance.getNormalizedName();
113                 
114                 System.out.println(component.getComponentType());
115                 
116                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
117                         resourceType = "resources";
118                 } else {
119                         resourceType = "services";
120                 }
121                 
122                 String url = String.format(Urls.POST_EXTERNAL_API_UPDATE_ARTIFACT_OF_COMPONENTINSTANCE_ON_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, resourceInstanceName, artifactUUID);
123                 
124                 return updateInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails), url);
125         }
126         
127         // Update Artifact of the asset 
128         public static RestResponse externalAPIUpdateArtifactOfTheAsset(Component component, User user, ArtifactReqDetails artifactReqDetails, String artifactUUID) throws IOException {
129                 Config config = Utils.getConfig();
130                 String resourceType = null;
131                 String resourceUUID = component.getUUID();
132                 
133                 System.out.println(component.getComponentType());
134                 
135                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
136                         resourceType = "resources";
137                 } else {
138                         resourceType = "services";
139                 }
140                 
141                 String url = String.format(Urls.POST_EXTERNAL_API_UPDATE_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, artifactUUID);
142                 
143                 return updateInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails), url);
144         }
145         
146         
147         // Upload Artifact on rI of the asset 
148         public static RestResponse externalAPIUploadArtifactOfComponentInstanceOnAsset(Component component, User user, ArtifactReqDetails artifactReqDetails, ComponentInstance resourceInstance) throws IOException {
149                 Config config = Utils.getConfig();
150                 String resourceType = null;
151                 String resourceUUID = component.getUUID();
152                 String resourceInstanceName = resourceInstance.getNormalizedName();
153                 
154                 System.out.println(component.getComponentType());
155                 
156                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
157                         resourceType = "resources";
158                 } else {
159                         resourceType = "services";
160                 }
161                 
162                 String url = String.format(Urls.POST_EXTERNAL_API_UPLOAD_ARTIFACT_OF_COMPONENTINSTANCE_ON_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, resourceInstanceName);
163                 
164                 return uploadInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails), url);
165         }
166         
167         // Upload Artifact of the asset 
168         public static RestResponse externalAPIUploadArtifactOfTheAsset(Component component, User user, ArtifactReqDetails artifactReqDetails) throws IOException {
169                 Config config = Utils.getConfig();
170                 String resourceType = null;
171                 String resourceUUID = component.getUUID();
172                 
173                 System.out.println(component.getComponentType());
174                 
175                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
176                         resourceType = "resources";
177                 } else {
178                         resourceType = "services";
179                 }
180                 
181                 String url = String.format(Urls.POST_EXTERNAL_API_UPLOAD_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID);
182                 
183                 return uploadInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails), url);
184         }
185         
186         
187         // Upload Artifact of the asset with invalid checksum
188         public static RestResponse externalAPIUploadArtifactWithInvalidCheckSumOfComponentInstanceOnAsset(Component component, User user, ArtifactReqDetails artifactReqDetails, ComponentInstance resourceInstance) throws IOException {
189                 Config config = Utils.getConfig();
190                 String resourceType = null;
191                 String resourceUUID = component.getUUID();
192                 String resourceInstanceName = resourceInstance.getNormalizedName();
193                 
194                 System.out.println(component.getComponentType());
195                 
196                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
197                         resourceType = "resources";
198                 } else {
199                         resourceType = "services";
200                 }
201                 
202                 String url = String.format(Urls.POST_EXTERNAL_API_UPLOAD_ARTIFACT_OF_COMPONENTINSTANCE_ON_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID, resourceInstanceName);
203                 
204                 return uploadInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails) + "123", url);
205         }
206                 
207         // Upload Artifact of the asset with invalid checksum
208         public static RestResponse externalAPIUploadArtifactWithInvalidCheckSumOfTheAsset(Component component, User user, ArtifactReqDetails artifactReqDetails) throws IOException {
209                 Config config = Utils.getConfig();
210                 String resourceType = null;
211                 String resourceUUID = component.getUUID();
212                 
213                 System.out.println(component.getComponentType());
214                 
215                 if(component.getComponentType().toString().toLowerCase().equals("resource")) {
216                         resourceType = "resources";
217                 } else {
218                         resourceType = "services";
219                 }
220                 
221                 String url = String.format(Urls.POST_EXTERNAL_API_UPLOAD_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceType, resourceUUID);
222                 
223                 return uploadInformationalArtifact(artifactReqDetails, user, calculateChecksum(artifactReqDetails) + "123", url);
224         }
225         
226         
227         //
228         // Testing
229         //
230         public static RestResponse getResourceDeploymentArtifactExternalAPI(String resourceUUID, String artifactUUID,User sdncModifierDetails, String resourceType) throws IOException {
231                 Config config = Utils.getConfig();
232                 String url = null;
233                 
234                 if (resourceType.toUpperCase().equals("SERVICE")) {
235                         url = String.format(Urls.GET_DOWNLOAD_SERVICE_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, artifactUUID);
236
237                 } else {
238                         url = String.format(Urls.GET_DOWNLOAD_RESOURCE_ARTIFACT_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, artifactUUID);
239                 }
240                 
241                 Map<String, String> headersMap = new HashMap<String,String>();
242                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
243                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
244                 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
245                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
246                 
247                 HttpRequest http = new HttpRequest();
248
249                 logger.debug("Send GET request to get Resource Assets: {}",url);
250                 System.out.println("Send GET request to get Resource Assets: " + url);
251                 
252                 logger.debug("Request headers: {}",headersMap);
253                 System.out.println("Request headers: " + headersMap);
254
255                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
256
257                 return sendGetResourceAssets;
258
259         }
260         
261         
262         
263         public static RestResponse getComponentInstanceDeploymentArtifactExternalAPI(String resourceUUID, String componentNormalizedName, String artifactUUID,User sdncModifierDetails, String resourceType) throws IOException {
264                 Config config = Utils.getConfig();
265                 String url = null;
266                 
267                 if (resourceType.toLowerCase().equals("service")) {
268                         url = String.format(Urls.GET_DOWNLOAD_SERVICE_ARTIFACT_OF_COMPONENT_INSTANCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, componentNormalizedName, artifactUUID);
269
270                 } else {
271                         url = String.format(Urls.GET_DOWNLOAD_RESOURCE_ARTIFACT_OF_COMPONENT_INSTANCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, componentNormalizedName, artifactUUID);
272                 }
273                 
274                 Map<String, String> headersMap = new HashMap<String,String>();
275                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
276                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
277                 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
278                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
279                 
280                 HttpRequest http = new HttpRequest();
281
282                 logger.debug("Send GET request to get Resource Assets: {}",url);
283                 System.out.println("Send GET request to get Resource Assets: " + url);
284                 
285                 logger.debug("Request headers: {}",headersMap);
286                 System.out.println("Request headers: " + headersMap);
287
288                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
289
290                 return sendGetResourceAssets;
291
292         }
293         
294         
295         //***********  SERVICE ****************
296         public static RestResponse getArtifactTypesList() throws IOException {
297                 Config config = Utils.getConfig();
298                 String url = String.format(Urls.GET_ALL_ARTIFACTS, config.getCatalogBeHost(), config.getCatalogBePort());
299
300                 return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
301         }
302
303         public static RestResponse addInformationalArtifactToService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid) throws IOException {
304                 return addInformationalArtifactToService(artifactDetails, sdncModifierDetails, serviceUid, calculateChecksum(artifactDetails));
305         }
306
307         public static RestResponse addInformationalArtifactToService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String checksum) throws IOException {
308                 Config config = Utils.getConfig();
309                 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(), config.getCatalogBePort(), serviceUid);
310
311                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
312         }
313
314         public static RestResponse downloadServiceArtifact(ServiceReqDetails service, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders) throws Exception
315         {
316         
317                 return downloadServiceArtifact( service,  artifact,  user,addionalHeaders,true);
318         }
319         
320         public static RestResponse downloadServiceArtifact(ServiceReqDetails service, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws Exception
321         {
322                 Config config = Utils.getConfig();
323                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL, ValidationUtils.convertToSystemName(service.getName()), service.getVersion(),  ValidationUtils.normalizeFileName(artifact.getArtifactName())));
324                 String fullUrl = String.format(Urls.DOWNLOAD_SERVICE_ARTIFACT_FULL_URL, config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
325                 
326                 return downloadArtifact(fullUrl, user, addionalHeaders,addEcompHeader);
327         }
328         
329         public static RestResponse downloadResourceArtifact(ServiceReqDetails service, ResourceReqDetails resource, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders) throws Exception
330         {       
331                 return downloadResourceArtifact(service, resource,  artifact,  user,addionalHeaders, true);
332         }
333         
334         public static RestResponse downloadResourceArtifact(ServiceReqDetails service,ResourceReqDetails resource, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws Exception
335         {
336                 Config config = Utils.getConfig();
337                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL, ValidationUtils.convertToSystemName(service.getName()),service.getVersion(),ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(),  ValidationUtils.normalizeFileName(artifact.getArtifactName())));
338                 String fullUrl = String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL, config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
339                 
340                 return downloadArtifact(fullUrl, user, addionalHeaders,addEcompHeader);
341         }
342         
343         
344         
345         public static RestResponse downloadResourceInstanceArtifact(String serviceUniqueId,String resourceInstanceId, User user, String artifactUniqeId) throws Exception
346         {
347                 Config config = Utils.getConfig();
348                 String url = String.format(Urls.DOWNLOAD_COMPONENT_INSTANCE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, resourceInstanceId, artifactUniqeId);
349                 RestResponse res =  sendGet(url, user.getUserId(), null);
350                 return res;
351         }
352         
353         ////    
354
355         //update
356         
357         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, String artifactUid, User sdncModifierDetails, String httpMethod) throws IOException {
358                 return updateInformationalArtifactOfServiceByMethod(artifactReqDetails, serviceUid, artifactUid, sdncModifierDetails, httpMethod, calculateChecksum(artifactReqDetails));
359         }
360         
361         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, User sdncModifierDetails, String httpMethod) throws IOException {
362                 return updateInformationalArtifactOfServiceByMethod(artifactReqDetails, serviceUid, artifactReqDetails.getUniqueId(), sdncModifierDetails, httpMethod, calculateChecksum(artifactReqDetails));
363         }
364         
365         public static RestResponse downloadResourceArtifactInternalApi(String resourceId, User user, String artifactUniqeId) throws Exception
366         {
367                 return downloadComponentArtifactInternalApi(resourceId, user, artifactUniqeId, Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT);
368         }
369
370         public static RestResponse downloadServiceArtifactInternalApi(String componentId, User user, String artifactUniqeId) throws Exception
371         {
372                 return downloadComponentArtifactInternalApi(componentId, user, artifactUniqeId, Urls.UI_DOWNLOAD_SERVICE_ARTIFACT);
373         }
374         public static RestResponse downloadComponentArtifactInternalApi(String componentId, User user, String artifactUniqeId, String urlTemplate) throws Exception
375         {
376                 Config config = Utils.getConfig();
377                 String url = String.format(urlTemplate, config.getCatalogBeHost(),config.getCatalogBePort(), componentId, artifactUniqeId);
378                 RestResponse res =  sendGet(url, user.getUserId(), null);
379                 return res;
380         }
381         
382 //      public static RestResponse downloadServiceArtifactInternalApi(String resourceId, User user, String artifactUniqeId) throws Exception
383 //      {
384 //              Config config = Utils.getConfig();
385 //              String url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), resourceId, artifactUniqeId);
386 //              RestResponse res =  sendGet(url, user.getUserId(), null);
387 //              return res;
388 //      }
389         
390         /*
391         public static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum) throws IOException
392         {
393                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, checksum, true);
394         }
395
396         public static RestResponse updateInformationalArtifactMetadataOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid) throws IOException
397         {
398                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, calculateChecksum(artifactDetails), false);
399         }
400
401         public static RestResponse updateInformationalArtifactOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum, boolean isPayloadUpdate) throws IOException
402         {
403                 Config config = Utils.getConfig();
404                 Map<String, String> headersMap = getHeadersMap(sdncModifierDetails);
405
406                 if (isPayloadUpdate){
407                         headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
408                 }
409
410                 Gson gson = new Gson();
411                 String jsonBody = gson.toJson(artifactDetails);
412
413                 HttpRequest http = new HttpRequest();
414
415                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
416                 RestResponse res =  http.httpSendPost(url, jsonBody, headersMap);
417                 System.out.println("update artifact was finished with response: "+ res.getErrorCode());
418                 return res;
419         }*/
420         
421         
422         
423         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, String artifactUid, User sdncModifierDetails, String httpMethod, String checksum) throws IOException 
424         {
425                 Config config = Utils.getConfig();
426
427                 Map<String, String> headersMap = getHeadersMap(sdncModifierDetails);
428                 headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
429
430                 Gson gson = new Gson();
431                 String userBodyJson = gson.toJson(artifactReqDetails);
432
433                 HttpRequest http = new HttpRequest();
434                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
435                 RestResponse updateResourceResponse = http.httpSendByMethod(url, httpMethod, userBodyJson, headersMap);
436 //              System.out.println("update artifact was finished with response: "+ updateResourceResponse.getErrorCode());
437
438                 return updateResourceResponse;
439         }
440         
441         
442         public static Map<String, String> getHeadersMap(User sdncModifierDetails) {
443                 Map<String, String> headersMap = new HashMap<String,String>();  
444                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
445                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptJsonHeader);
446                 
447                 try{
448                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
449                 }
450                 catch(Exception e)
451                 {
452                         
453                 }
454                 
455                 return headersMap;
456         }
457
458         //***********  RESOURCE ****************
459         //add
460         public static RestResponse addInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
461                 return addInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid, calculateChecksum(artifactDetails));
462         }
463         
464         public static RestResponse explicitAddInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
465                 Config config = Utils.getConfig();
466
467
468                 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),config.getCatalogBePort(), resourceUid);
469
470                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
471         }
472
473         
474         public static RestResponse addInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String checksum) throws IOException{
475                 Config config = Utils.getConfig();
476                         
477                         if (artifactDetails.getArtifactGroupType()!=null && artifactDetails.getArtifactGroupType().equals(ArtifactGroupTypeEnum.DEPLOYMENT.getType())){
478                                 //YANG_XML and OTHER deployment artifact should be added through this API, not updated
479                                 String artifactType = artifactDetails.getArtifactType();
480                                 if (!(ArtifactTypeEnum.YANG_XML.getType().equals(artifactType) ||
481                                                 ArtifactTypeEnum.OTHER.getType().equals(artifactType) ||
482                                                 ArtifactTypeEnum.VNF_CATALOG.getType().equals(artifactType) ||
483                                                 ArtifactTypeEnum.VF_LICENSE.getType().equals(artifactType) ||
484                                                 ArtifactTypeEnum.VENDOR_LICENSE.getType().equals(artifactType) ||
485                                                 ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().equals(artifactType) ||
486                                                 ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equals(artifactType) ||
487                                                 ArtifactTypeEnum.APPC_CONFIG.getType().equals(artifactType))){
488                                         //return updateInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid);
489                                 }
490                         }
491                 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),config.getCatalogBePort(), resourceUid);
492                         
493                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
494         }
495         //update
496         public static RestResponse updateInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
497                 return updateInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid, calculateChecksum(artifactDetails));
498         }
499
500         public static RestResponse updateInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String checksum) throws IOException {
501                 Config config = Utils.getConfig();
502                 if (artifactDetails.getArtifactGroupType()!=null && artifactDetails.getArtifactGroupType().equals("DEPLOYMENT")){
503                         RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceUid );
504                         Resource resourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
505                         Map<String, ArtifactDefinition> deploymentArtifacts = resourceRespJavaObject.getDeploymentArtifacts();
506                         ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
507                         artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
508                         artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
509                         
510                 }
511                 
512                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
513
514                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
515         }
516         
517         public static RestResponse uploadArtifactToPlaceholderOnResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String placeHolderLabel) throws IOException {
518                 Config config = Utils.getConfig();
519                 if (artifactDetails.getArtifactLabel() != null && !artifactDetails.getArtifactLabel().isEmpty()){
520                         RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceUid );
521                         Resource resourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
522                         Map<String, ArtifactDefinition> deploymentArtifacts = resourceRespJavaObject.getDeploymentArtifacts();
523                         ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
524                         AssertJUnit.assertNotNull(artifactDefinition);
525                         artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
526                         artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
527                         
528                 }
529                 
530                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
531
532                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
533         }
534         
535         public static RestResponse updateArtifactToResourceInstance(ArtifactDefinition artifactDefinition, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
536                 Config config = Utils.getConfig();
537                 String url = String.format(Urls.UPDATE_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceInstanceId, artifactDefinition.getUniqueId());
538                 return updateDeploymentArtifact(artifactDefinition, sdncModifierDetails, url);
539         }
540         
541         public static RestResponse updateDeploymentArtifactToResource(ArtifactDefinition artifact, User sdncModifierDetails, String resourceUid) throws IOException {
542                 Config config = Utils.getConfig();
543                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifact.getUniqueId());
544         
545                 return updateDeploymentArtifact(artifact, sdncModifierDetails, url);
546         }
547         public static RestResponse updateDeploymentArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException {
548                 Config config = Utils.getConfig();
549                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
550         
551                 return updateDeploymentArtifact(artifactDetails, sdncModifierDetails, url);
552         }
553
554
555         public static RestResponse updateDeploymentArtifactToRI(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
556                 Config config = Utils.getConfig();
557                 String url = String.format(Urls.UPDATE_RESOURCE_INSTANCE_HEAT_ENV_PARAMS, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceInstanceId, artifactDetails.getUniqueId());
558                 return updateDeploymentArtifact(artifactDetails, sdncModifierDetails, url);
559         }
560         public static RestResponse updateDeploymentArtifactToRI(ArtifactDefinition artifactDetails, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
561                 Config config = Utils.getConfig();
562                 String url = String.format(Urls.UPDATE_RESOURCE_INSTANCE_HEAT_ENV_PARAMS, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceInstanceId, artifactDetails.getUniqueId());
563                 return updateDeploymentArtifact(artifactDetails, sdncModifierDetails, url);
564         }
565         
566         //delete
567         public static RestResponse deleteArtifactFromResourceInstance (ArtifactDefinition artifactDefinition, User sdncModifierDetails, String resourceUid, String serviceId) throws IOException{
568                 Config config = Utils.getConfig();
569                 String url = String.format(Urls.DELETE_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceUid, artifactDefinition.getUniqueId());
570                 return sendDelete(url, sdncModifierDetails.getUserId());                
571         }
572         
573         public static RestResponse deleteInformationalArtifactFromResource(String resourceUid, ArtifactReqDetails artifactDetails, User sdncModifierDetails) throws IOException{
574                 return deleteInformationalArtifactFromResource( resourceUid, artifactDetails.getUniqueId(),  sdncModifierDetails);
575         }
576         
577         public static RestResponse deleteInformationalArtifactFromResource( String resourceUid, String artifactId, User sdncModifierDetails) throws IOException{
578                 Config config = Utils.getConfig();
579                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactId);
580                 return sendDelete(url, sdncModifierDetails.getUserId());
581         }
582         
583         public static RestResponse deleteServiceApiArtifact(ArtifactReqDetails artifactDetails, String serviceUniqueId, User user) throws Exception
584         {
585                 Config config = Utils.getConfig();
586                 String url = String.format(Urls.UPDATE_DELETE_SERVICE_API_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, artifactDetails.getUniqueId());
587                 RestResponse res =  sendDelete(url, user.getUserId());
588                 logger.debug("Deleting api artifact was finished with response: {}",res.getErrorCode());
589                 logger.debug("Response body: {}",res.getResponseMessage());
590                 return res;
591         }
592         
593         //*************** RESOURCE INSTANCE **************
594         /**
595          * Add DCAE artifacts to resource instance.
596          * @param artifactDetails
597          * @param sdncModifierDetails
598          * @param resourceInstanceId
599          * @param serviceId
600          * @return
601          * @throws IOException
602          */
603         public static RestResponse addArtifactToResourceInstance(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
604                 Config config = Utils.getConfig();
605                 String url = String.format(Urls.ADD_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId,resourceInstanceId, artifactDetails.getUniqueId());
606                 return addArtifactToInstance(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
607         }
608         
609         //*************** COMPONENT **************
610         
611         public static RestResponse uploadDeploymentArtifact(ArtifactReqDetails artifactDetails, Component component, User sdncModifierDetails) throws IOException {
612                 Config config = Utils.getConfig();
613                 Map<String, String> additionalHeaders = null;
614                 String checksum = ResponseParser.calculateMD5Header(artifactDetails);
615                 additionalHeaders = new HashMap<String, String>();
616                 additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
617                 
618                 ComponentTypeEnum componentType = component.getComponentType();
619                 
620                 String url = null;
621                                 
622                 switch (componentType){
623
624                 case RESOURCE:
625                 {
626                         url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), component.getUniqueId(), artifactDetails.getUniqueId());
627                         
628                         break;
629                 }
630                 case SERVICE: {
631                         
632                         break;
633                 }
634                 
635                 case PRODUCT: {
636                         
637                         break;
638                 }
639                 
640                 default: {//dummy
641                         assertTrue("failed on enum selection", false);
642                         
643                         break;
644                 }
645                 }
646                 
647                 
648                 
649
650                 Gson gson = new Gson();
651                 String jsonBody = gson.toJson(artifactDetails);
652 //              System.out.println("ArtifactDetails: "+ jsonBody);
653
654                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
655                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
656                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
657                 }
658 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
659                 return res;
660         }
661         
662         public static RestResponse uploadArtifact(ArtifactReqDetails artifactDetails, Component component, User sdncModifierDetails) throws IOException {
663                 Config config = Utils.getConfig();
664                 List<String> placeHolderlst = Utils.getListOfResPlaceHoldersDepArtTypes();
665                 Map<String, String> additionalHeaders = null;
666                 String checksum = null; 
667                 String url= null;
668 //
669 //              
670 //              if (artifactDetails.getArtifactGroupType() != null
671 //                              && artifactDetails.getArtifactGroupType().equals("DEPLOYMENT")
672 //                              && placeHolderlst.contains(artifactDetails.getArtifactType())) {
673 //                      Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
674 //                      ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
675 //                      artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
676 //                      artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
677 //                      checksum = ResponseParser.calculateMD5Header(artifactDetails);
678 //                      additionalHeaders = new HashMap<String, String>();
679 //                      additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
680 //                      url = String.format(Urls.UPDATE_ARTIFACT_OF_COMPONENT, config.getCatalogBeHost(),
681 //                                      config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()),
682 //                                      component.getUniqueId(), artifactDetails.getUniqueId());
683 //              }
684 //
685 //              else {
686                         checksum = ResponseParser.calculateMD5Header(artifactDetails);
687                         additionalHeaders = new HashMap<String, String>();
688                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
689                         url = String.format(Urls.UPLOAD_DELETE_ARTIFACT_OF_COMPONENT, config.getCatalogBeHost(),
690                                         config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()),
691                                         component.getUniqueId(), artifactDetails.getUniqueId());
692 //              }
693                 
694                 Gson gson = new Gson();
695                 String jsonBody = gson.toJson(artifactDetails);
696 //              System.out.println("ArtifactDetails: "+ jsonBody);
697
698                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
699                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
700                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
701                 }
702 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
703                 return res;
704         }
705         
706         
707
708         
709         //*************** PRIVATE **************
710         private static RestResponse deleteInformationalArtifact(User sdncModifierDetails, String url) throws IOException {
711                 Map<String, String> additionalHeaders = null;
712
713                         additionalHeaders = new HashMap<String, String>();
714                 
715                 
716                 additionalHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
717                 additionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
718                 
719                 return sendDelete(url, sdncModifierDetails.getUserId(), additionalHeaders);
720
721 //              Gson gson = new Gson();
722 ////            System.out.println("ArtifactDetails: "+ jsonBody);
723 //              String jsonBody = gson.toJson(artifactDetails);
724 //
725 //              RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
726 //              if ((res.getErrorCode() == STATUS_CODE_SUCCESS) || (res.getErrorCode() == STATUS_CODE_CREATED)) {
727 //                      artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
728 //              }
729 ////            System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
730 //              return res;
731         }
732         
733         private static RestResponse updateInformationalArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
734                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
735         }
736         
737         private static RestResponse uploadInformationalArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
738                 Map<String, String> additionalHeaders = null;
739                 if (checksum != null && !checksum.isEmpty()) {
740                         additionalHeaders = new HashMap<String, String>();
741                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
742                 }
743                 
744                 additionalHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
745                 additionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
746
747                 Gson gson = new Gson();
748 //              System.out.println("ArtifactDetails: "+ jsonBody);
749                 String jsonBody = gson.toJson(artifactDetails);
750
751                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
752                 if ((res.getErrorCode() == STATUS_CODE_SUCCESS) || (res.getErrorCode() == STATUS_CODE_CREATED)) {
753                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
754                 }
755 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
756                 return res;
757         }
758         
759         private static RestResponse addArtifactToInstance(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
760                 Map<String, String> additionalHeaders = null;
761                 additionalHeaders = new HashMap<String, String>();
762                 if (checksum != null && !checksum.isEmpty()) {
763                         additionalHeaders = new HashMap<String, String>();
764                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
765                 }
766                 additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
767                 additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
768
769                 Gson gson = new Gson();
770                 String jsonBody = gson.toJson(artifactDetails);
771
772                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
773                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
774                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
775                 }
776                 return res;
777         }
778         
779         private static RestResponse updateDeploymentArtifact(ArtifactDefinition artifactDefinition, User sdncModifierDetails, String url) throws IOException {
780                 Map<String, String> additionalHeaders = null;
781                 additionalHeaders = new HashMap<String, String>();
782                 additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
783                 additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
784                 
785                 Gson gson = new Gson();
786                 String jsonBody = gson.toJson(artifactDefinition);
787
788                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
789                 return res;
790         }
791         
792         private static RestResponse updateDeploymentArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String url) throws IOException {
793                 Map<String, String> additionalHeaders = null;
794                 
795                         additionalHeaders = new HashMap<String, String>();
796                         additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
797                         additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
798 //                      additionalHeaders.put(HttpHeaderEnum..getValue(), "application/json;charset=UTF-8");
799                 
800
801                 Gson gson = new Gson();
802                 String jsonBody = gson.toJson(artifactDetails);
803 //              System.out.println("ArtifactDetails: "+ jsonBody);
804
805                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
806                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
807                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
808                 }
809 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
810                 return res;
811         }
812         
813         private static RestResponse downloadArtifact(String url, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws IOException
814         {       
815                 if(addEcompHeader){
816                         addionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), ecomp);
817                 }
818                 return downloadArtifact(url, user, addionalHeaders, acceptOctetStream);
819         }
820         
821         private static RestResponse downloadArtifact(String url, User user, Map<String, String> addionalHeaders, String accept) throws IOException
822         {
823                 addionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), accept);
824                 
825                 RestResponse res =  sendGet(url, user.getUserId(), addionalHeaders);
826 //              System.out.println("download artifact was finished with response: "+ res.getErrorCode());
827 //              System.out.println("response is: " + res.getResponse());
828                 return res;
829         }
830         
831         private static Map<String,Map<String,Object>> getArtifactsListFromResponse(String jsonResponse, String fieldOfArtifactList){
832                 JSONObject object = (JSONObject)JSONValue.parse(jsonResponse);
833                 Map<String,Map<String,Object>> map = (Map<String,Map<String,Object>>)object.get(fieldOfArtifactList);
834                 return map;
835         }
836
837         public static String calculateChecksum(ArtifactReqDetails artifactDetails) {
838                 String checksum = null;
839                 if (artifactDetails.getPayload() != null) {
840                         checksum = ResponseParser.calculateMD5Header(artifactDetails);
841                 }
842                 return checksum;
843         }
844         
845         public static String encodeUrlForDownload(String url){
846
847                 return url.replaceAll(" ", "%20");
848         }
849         
850         public static String getPartialUrlByArtifactName(ServiceReqDetails serviceDetails,String serviceVersion ,String artifactName){
851                 return encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL, ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceVersion, artifactName));
852         }
853         
854         public static String getUniqueIdOfArtifact(RestResponse createResponse, String artifactField, String requieredArtifactLabel) throws Exception
855         {
856                 Map<String, Object> artifact = getArtifactFromRestResponse(createResponse, artifactField, requieredArtifactLabel);
857                 assertNotNull(artifact);
858                 return artifact.get("uniqueId").toString();
859         }
860         
861         public static Map<String, Object> getArtifactFromRestResponse(RestResponse response, String artifactField, String requieredArtifactLabel)
862         {
863                 Map<String, Map<String, Object>> map = getArtifactsListFromResponse(response.getResponse(), artifactField);
864                 return map.get(requieredArtifactLabel);
865         }
866         
867
868         
869         public static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid) throws IOException
870         {
871                 return updateInformationalArtifactPayloadOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, calculateMD5Header(artifactDetails));
872         }
873         
874         private static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum) throws IOException
875         {
876                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, checksum, true);
877         }
878         
879         private static RestResponse updateInformationalArtifactOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum, boolean isPayloadUpdate) throws IOException
880         {
881                 Config config = Utils.getConfig();
882                 Map<String, String> headersMap = prepareHeadersMap(sdncModifierDetails.getUserId());
883
884                 if (isPayloadUpdate){
885                         headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
886                 }
887
888                 Gson gson = new Gson();
889                 String jsonBody = gson.toJson(artifactDetails);
890
891                 HttpRequest http = new HttpRequest();
892
893                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
894                 RestResponse res =  http.httpSendPost(url, jsonBody, headersMap);
895 //              System.out.println("update artifact was finished with response: "+ res.getErrorCode());
896                 return res;
897         }
898         
899         public static String calculateMD5Header(ArtifactReqDetails artifactDetails)
900         {
901                 Gson gson = new Gson();
902                 String jsonBody = gson.toJson(artifactDetails);
903                 // calculate MD5 for json body
904                 return calculateMD5(jsonBody);
905
906         }
907         
908         public static String calculateMD5 (String data){
909                 String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
910                 // encode base-64 result
911                 byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
912                 String encodeBase64Str = new String(encodeBase64);
913                 return encodeBase64Str;
914
915         }
916
917         
918         
919
920 }