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