Sync Integ to Master
[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 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;
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;
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;
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;
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;
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;
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;
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;
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;
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<>();
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(), BaseRestUtils.xEcompInstanceId);
246                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(),acceptMultipartHeader);
247                 
248                 HttpRequest http = new HttpRequest();
249
250                 logger.debug("Send GET request to get Resource Assets: {}", url);
251                 System.out.println("Send GET request to get Resource Assets: " + url);
252                 
253                 logger.debug("Request headers: {}", headersMap);
254                 System.out.println("Request headers: " + headersMap);
255
256                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
257
258                 return sendGetResourceAssets;
259
260         }
261         
262         
263         
264         public static RestResponse getComponentInstanceDeploymentArtifactExternalAPI(String resourceUUID, String componentNormalizedName, String artifactUUID,User sdncModifierDetails, String resourceType) throws IOException {
265                 Config config = Utils.getConfig();
266                 String url;
267                 
268                 if (resourceType.toLowerCase().equals("service")) {
269                         url = String.format(Urls.GET_DOWNLOAD_SERVICE_ARTIFACT_OF_COMPONENT_INSTANCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, componentNormalizedName, artifactUUID);
270
271                 } else {
272                         url = String.format(Urls.GET_DOWNLOAD_RESOURCE_ARTIFACT_OF_COMPONENT_INSTANCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUUID, componentNormalizedName, artifactUUID);
273                 }
274                 
275                 Map<String, String> headersMap = new HashMap<>();
276                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
277                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
278                 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
279                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
280                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(),acceptMultipartHeader);
281                 
282                 HttpRequest http = new HttpRequest();
283
284                 logger.debug("Send GET request to get Resource Assets: {}", url);
285                 System.out.println("Send GET request to get Resource Assets: " + url);
286                 
287                 logger.debug("Request headers: {}", headersMap);
288                 System.out.println("Request headers: " + headersMap);
289
290                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
291
292                 return sendGetResourceAssets;
293
294         }
295         
296         
297         //***********  SERVICE ****************
298         public static RestResponse getArtifactTypesList() throws IOException {
299                 Config config = Utils.getConfig();
300                 String url = String.format(Urls.GET_ALL_ARTIFACTS, config.getCatalogBeHost(), config.getCatalogBePort());
301
302                 return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
303         }
304
305         public static RestResponse addInformationalArtifactToService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid) throws IOException {
306                 return addInformationalArtifactToService(artifactDetails, sdncModifierDetails, serviceUid, calculateChecksum(artifactDetails));
307         }
308
309         public static RestResponse addInformationalArtifactToService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String checksum) throws IOException {
310                 Config config = Utils.getConfig();
311                 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(), config.getCatalogBePort(), serviceUid);
312
313                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
314         }
315
316         public static RestResponse downloadServiceArtifact(ServiceReqDetails service, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders) throws Exception
317         {
318         
319                 return downloadServiceArtifact( service,  artifact,  user,addionalHeaders,true);
320         }
321         
322         public static RestResponse downloadServiceArtifact(ServiceReqDetails service, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws Exception
323         {
324                 Config config = Utils.getConfig();
325                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL, ValidationUtils.convertToSystemName(service.getName()), service.getVersion(),  ValidationUtils.normalizeFileName(artifact.getArtifactName())));
326                 String fullUrl = String.format(Urls.DOWNLOAD_SERVICE_ARTIFACT_FULL_URL, config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
327                 
328                 return downloadArtifact(fullUrl, user, addionalHeaders,addEcompHeader);
329         }
330         
331         public static RestResponse downloadResourceArtifact(ServiceReqDetails service, ResourceReqDetails resource, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders) throws Exception
332         {       
333                 return downloadResourceArtifact(service, resource,  artifact,  user,addionalHeaders, true);
334         }
335         
336         public static RestResponse downloadResourceArtifact(ServiceReqDetails service,ResourceReqDetails resource, ArtifactReqDetails artifact, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws Exception
337         {
338                 Config config = Utils.getConfig();
339                 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())));
340                 String fullUrl = String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL, config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
341                 
342                 return downloadArtifact(fullUrl, user, addionalHeaders,addEcompHeader);
343         }
344         
345         
346         
347         public static RestResponse downloadResourceInstanceArtifact(String serviceUniqueId,String resourceInstanceId, User user, String artifactUniqeId) throws Exception
348         {
349                 Config config = Utils.getConfig();
350                 String url = String.format(Urls.DOWNLOAD_COMPONENT_INSTANCE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, resourceInstanceId, artifactUniqeId);
351                 RestResponse res =  sendGet(url, user.getUserId(), null);
352                 return res;
353         }
354         
355         ////    
356
357         //update
358         
359         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, String artifactUid, User sdncModifierDetails, String httpMethod) throws IOException {
360                 return updateInformationalArtifactOfServiceByMethod(artifactReqDetails, serviceUid, artifactUid, sdncModifierDetails, httpMethod, calculateChecksum(artifactReqDetails));
361         }
362         
363         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, User sdncModifierDetails, String httpMethod) throws IOException {
364                 return updateInformationalArtifactOfServiceByMethod(artifactReqDetails, serviceUid, artifactReqDetails.getUniqueId(), sdncModifierDetails, httpMethod, calculateChecksum(artifactReqDetails));
365         }
366         
367         public static RestResponse downloadResourceArtifactInternalApi(String resourceId, User user, String artifactUniqeId) throws Exception
368         {
369                 return downloadComponentArtifactInternalApi(resourceId, user, artifactUniqeId, Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT);
370         }
371
372         public static RestResponse downloadServiceArtifactInternalApi(String componentId, User user, String artifactUniqeId) throws Exception
373         {
374                 return downloadComponentArtifactInternalApi(componentId, user, artifactUniqeId, Urls.UI_DOWNLOAD_SERVICE_ARTIFACT);
375         }
376         public static RestResponse downloadComponentArtifactInternalApi(String componentId, User user, String artifactUniqeId, String urlTemplate) throws Exception
377         {
378                 Config config = Utils.getConfig();
379                 String url = String.format(urlTemplate, config.getCatalogBeHost(),config.getCatalogBePort(), componentId, artifactUniqeId);
380                 RestResponse res =  sendGet(url, user.getUserId(), null);
381                 return res;
382         }
383         
384 //      public static RestResponse downloadServiceArtifactInternalApi(String resourceId, User user, String artifactUniqeId) throws Exception
385 //      {
386 //              Config config = Utils.getConfig();
387 //              String url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), resourceId, artifactUniqeId);
388 //              RestResponse res =  sendGet(url, user.getUserId(), null);
389 //              return res;
390 //      }
391         
392         /*
393         public static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum) throws IOException
394         {
395                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, checksum, true);
396         }
397
398         public static RestResponse updateInformationalArtifactMetadataOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid) throws IOException
399         {
400                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, calculateChecksum(artifactDetails), false);
401         }
402
403         public static RestResponse updateInformationalArtifactOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum, boolean isPayloadUpdate) throws IOException
404         {
405                 Config config = Utils.getConfig();
406                 Map<String, String> headersMap = getHeadersMap(sdncModifierDetails);
407
408                 if (isPayloadUpdate){
409                         headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
410                 }
411
412                 Gson gson = new Gson();
413                 String jsonBody = gson.toJson(artifactDetails);
414
415                 HttpRequest http = new HttpRequest();
416
417                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
418                 RestResponse res =  http.httpSendPost(url, jsonBody, headersMap);
419                 System.out.println("update artifact was finished with response: "+ res.getErrorCode());
420                 return res;
421         }*/
422         
423         
424         
425         public static RestResponse updateInformationalArtifactOfServiceByMethod(ArtifactReqDetails artifactReqDetails, String serviceUid, String artifactUid, User sdncModifierDetails, String httpMethod, String checksum) throws IOException 
426         {
427                 Config config = Utils.getConfig();
428
429                 Map<String, String> headersMap = getHeadersMap(sdncModifierDetails);
430                 headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
431
432                 Gson gson = new Gson();
433                 String userBodyJson = gson.toJson(artifactReqDetails);
434
435                 HttpRequest http = new HttpRequest();
436                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
437                 RestResponse updateResourceResponse = http.httpSendByMethod(url, httpMethod, userBodyJson, headersMap);
438 //              System.out.println("update artifact was finished with response: "+ updateResourceResponse.getErrorCode());
439
440                 return updateResourceResponse;
441         }
442         
443         
444         public static Map<String, String> getHeadersMap(User sdncModifierDetails) {
445                 Map<String, String> headersMap = new HashMap<>();
446                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
447                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptJsonHeader);
448                 
449                 try{
450                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
451                 }
452                 catch(Exception e)
453                 {
454                         
455                 }
456                 
457                 return headersMap;
458         }
459
460         //***********  RESOURCE ****************
461         //add
462         public static RestResponse addInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
463                 return addInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid, calculateChecksum(artifactDetails));
464         }
465         
466         public static RestResponse explicitAddInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
467                 Config config = Utils.getConfig();
468
469
470                 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),config.getCatalogBePort(), resourceUid);
471
472                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
473         }
474
475         
476         public static RestResponse addInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String checksum) throws IOException{
477                 Config config = Utils.getConfig();
478                         
479                         if (artifactDetails.getArtifactGroupType()!=null && artifactDetails.getArtifactGroupType().equals(ArtifactGroupTypeEnum.DEPLOYMENT.getType())){
480                                 //YANG_XML and OTHER deployment artifact should be added through this API, not updated
481                                 String artifactType = artifactDetails.getArtifactType();
482                                 if (!(ArtifactTypeEnum.YANG_XML.getType().equals(artifactType) ||
483                                                 ArtifactTypeEnum.OTHER.getType().equals(artifactType) ||
484                                                 ArtifactTypeEnum.VNF_CATALOG.getType().equals(artifactType) ||
485                                                 ArtifactTypeEnum.VF_LICENSE.getType().equals(artifactType) ||
486                                                 ArtifactTypeEnum.VENDOR_LICENSE.getType().equals(artifactType) ||
487                                                 ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().equals(artifactType) ||
488                                                 ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equals(artifactType) ||
489                                                 ArtifactTypeEnum.APPC_CONFIG.getType().equals(artifactType))){
490                                         //return updateInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid);
491                                 }
492                         }
493                 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),config.getCatalogBePort(), resourceUid);
494                         
495                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
496         }
497         //update
498         public static RestResponse updateInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException{
499                 return updateInformationalArtifactToResource(artifactDetails, sdncModifierDetails, resourceUid, calculateChecksum(artifactDetails));
500         }
501
502         public static RestResponse updateInformationalArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String checksum) throws IOException {
503                 Config config = Utils.getConfig();
504                 if (artifactDetails.getArtifactGroupType()!=null && artifactDetails.getArtifactGroupType().equals("DEPLOYMENT")){
505                         RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceUid );
506                         Resource resourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
507                         Map<String, ArtifactDefinition> deploymentArtifacts = resourceRespJavaObject.getDeploymentArtifacts();
508                         ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
509                         artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
510                         artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
511                         
512                 }
513                 
514                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
515
516                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
517         }
518         
519         public static RestResponse uploadArtifactToPlaceholderOnResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid, String placeHolderLabel) throws IOException {
520                 Config config = Utils.getConfig();
521                 if (artifactDetails.getArtifactLabel() != null && !artifactDetails.getArtifactLabel().isEmpty()){
522                         RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceUid );
523                         Resource resourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
524                         Map<String, ArtifactDefinition> deploymentArtifacts = resourceRespJavaObject.getDeploymentArtifacts();
525                         ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
526                         AssertJUnit.assertNotNull(artifactDefinition);
527                         artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
528                         artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
529                         
530                 }
531                 
532                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
533
534                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
535         }
536         
537         public static RestResponse updateArtifactToResourceInstance(ArtifactDefinition artifactDefinition, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
538                 Config config = Utils.getConfig();
539                 String url = String.format(Urls.UPDATE_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceInstanceId, artifactDefinition.getUniqueId());
540                 return updateDeploymentArtifact(artifactDefinition, sdncModifierDetails, url);
541         }
542         
543         public static RestResponse updateDeploymentArtifactToResource(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceUid) throws IOException {
544                 Config config = Utils.getConfig();
545                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactDetails.getUniqueId());
546         
547                 return updateDeploymentArtifact(artifactDetails, sdncModifierDetails, url);
548         }
549
550
551         public static RestResponse updateDeploymentArtifactToRI(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
552                 Config config = Utils.getConfig();
553                 String url = String.format(Urls.UPDATE_RESOURCE_INSTANCE_HEAT_ENV_PARAMS, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceInstanceId, artifactDetails.getUniqueId());
554                 return updateDeploymentArtifact(artifactDetails, sdncModifierDetails, url);
555         }
556         
557         //delete
558         public static RestResponse deleteArtifactFromResourceInstance (ArtifactDefinition artifactDefinition, User sdncModifierDetails, String resourceUid, String serviceId) throws IOException{
559                 Config config = Utils.getConfig();
560                 String url = String.format(Urls.DELETE_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId, resourceUid, artifactDefinition.getUniqueId());
561                 return sendDelete(url, sdncModifierDetails.getUserId());                
562         }
563         
564         public static RestResponse deleteInformationalArtifactFromResource(String resourceUid, ArtifactReqDetails artifactDetails, User sdncModifierDetails) throws IOException{
565                 return deleteInformationalArtifactFromResource( resourceUid, artifactDetails.getUniqueId(),  sdncModifierDetails);
566         }
567         
568         public static RestResponse deleteInformationalArtifactFromResource( String resourceUid, String artifactId, User sdncModifierDetails) throws IOException{
569                 Config config = Utils.getConfig();
570                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceUid, artifactId);
571                 return sendDelete(url, sdncModifierDetails.getUserId());
572         }
573         
574         public static RestResponse deleteServiceApiArtifact(ArtifactReqDetails artifactDetails, String serviceUniqueId, User user) throws Exception
575         {
576                 Config config = Utils.getConfig();
577                 String url = String.format(Urls.UPDATE_DELETE_SERVICE_API_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, artifactDetails.getUniqueId());
578                 RestResponse res =  sendDelete(url, user.getUserId());
579                 logger.debug("Deleting api artifact was finished with response: {}", res.getErrorCode());
580                 logger.debug("Response body: {}", res.getResponseMessage());
581                 return res;
582         }
583         
584         //*************** RESOURCE INSTANCE **************
585         /**
586          * Add DCAE artifacts to resource instance.
587          * @param artifactDetails
588          * @param sdncModifierDetails
589          * @param resourceInstanceId
590          * @param serviceId
591          * @return
592          * @throws IOException
593          */
594         public static RestResponse addArtifactToResourceInstance(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String resourceInstanceId, String serviceId) throws IOException {
595                 Config config = Utils.getConfig();
596                 String url = String.format(Urls.ADD_RESOURCE_INSTANCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceId,resourceInstanceId, artifactDetails.getUniqueId());
597                 return addArtifactToInstance(artifactDetails, sdncModifierDetails, calculateChecksum(artifactDetails), url);
598         }
599         
600         //*************** COMPONENT **************
601         
602         public static RestResponse uploadDeploymentArtifact(ArtifactReqDetails artifactDetails, Component component, User sdncModifierDetails) throws IOException {
603                 Config config = Utils.getConfig();
604                 Map<String, String> additionalHeaders;
605                 String checksum = ResponseParser.calculateMD5Header(artifactDetails);
606                 additionalHeaders = new HashMap<>();
607                 additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
608                 
609                 ComponentTypeEnum componentType = component.getComponentType();
610                 
611                 String url = null;
612                                 
613                 switch (componentType){
614
615                 case RESOURCE:
616                         {
617                                 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), component.getUniqueId(), artifactDetails.getUniqueId());
618
619                                 break;
620                         }
621                         case SERVICE: {
622
623                                 break;
624                         }
625
626                         case PRODUCT: {
627
628                                 break;
629                         }
630
631                         default: {//dummy
632                                 assertTrue("failed on enum selection", false);
633
634                                 break;
635                         }
636                 }
637                 
638                 
639                 
640
641                 Gson gson = new Gson();
642                 String jsonBody = gson.toJson(artifactDetails);
643 //              System.out.println("ArtifactDetails: "+ jsonBody);
644
645                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
646                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
647                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
648                 }
649 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
650                 return res;
651         }
652         
653         public static RestResponse uploadArtifact(ArtifactReqDetails artifactDetails, Component component, User sdncModifierDetails) throws IOException {
654                 Config config = Utils.getConfig();
655                 List<String> placeHolderlst = Utils.getListOfResPlaceHoldersDepArtTypes();
656                 Map<String, String> additionalHeaders;
657                 String checksum;
658                 String url;
659 //
660 //              
661 //              if (artifactDetails.getArtifactGroupType() != null
662 //                              && artifactDetails.getArtifactGroupType().equals("DEPLOYMENT")
663 //                              && placeHolderlst.contains(artifactDetails.getArtifactType())) {
664 //                      Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
665 //                      ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactDetails.getArtifactLabel());
666 //                      artifactDetails.setUniqueId(artifactDefinition.getUniqueId());
667 //                      artifactDetails.setArtifactLabel(artifactDefinition.getArtifactLabel());
668 //                      checksum = ResponseParser.calculateMD5Header(artifactDetails);
669 //                      additionalHeaders = new HashMap<String, String>();
670 //                      additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
671 //                      url = String.format(Urls.UPDATE_ARTIFACT_OF_COMPONENT, config.getCatalogBeHost(),
672 //                                      config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()),
673 //                                      component.getUniqueId(), artifactDetails.getUniqueId());
674 //              }
675 //
676 //              else {
677                         checksum = ResponseParser.calculateMD5Header(artifactDetails);
678                         additionalHeaders = new HashMap<>();
679                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
680                         url = String.format(Urls.UPLOAD_DELETE_ARTIFACT_OF_COMPONENT, config.getCatalogBeHost(),
681                                         config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()),
682                                         component.getUniqueId(), artifactDetails.getUniqueId());
683 //              }
684                 
685                 Gson gson = new Gson();
686                 String jsonBody = gson.toJson(artifactDetails);
687 //              System.out.println("ArtifactDetails: "+ jsonBody);
688
689                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
690                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
691                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
692                 }
693 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
694                 return res;
695         }
696         
697         
698
699         
700         //*************** PRIVATE **************
701         private static RestResponse deleteInformationalArtifact(User sdncModifierDetails, String url) throws IOException {
702                 Map<String, String> additionalHeaders;
703
704                         additionalHeaders = new HashMap<>();
705                 
706                 
707                 additionalHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
708                 additionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
709                 
710                 return sendDelete(url, sdncModifierDetails.getUserId(), additionalHeaders);
711
712 //              Gson gson = new Gson();
713 ////            System.out.println("ArtifactDetails: "+ jsonBody);
714 //              String jsonBody = gson.toJson(artifactDetails);
715 //
716 //              RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
717 //              if ((res.getErrorCode() == STATUS_CODE_SUCCESS) || (res.getErrorCode() == STATUS_CODE_CREATED)) {
718 //                      artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
719 //              }
720 ////            System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
721 //              return res;
722         }
723         
724         private static RestResponse updateInformationalArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
725                 return uploadInformationalArtifact(artifactDetails, sdncModifierDetails, checksum, url);
726         }
727         
728         private static RestResponse uploadInformationalArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
729                 Map<String, String> additionalHeaders = null;
730                 if (checksum != null && !checksum.isEmpty()) {
731                         additionalHeaders = new HashMap<>();
732                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
733                 }
734                 
735                 additionalHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
736                 additionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
737
738                 Gson gson = new Gson();
739 //              System.out.println("ArtifactDetails: "+ jsonBody);
740                 String jsonBody = gson.toJson(artifactDetails);
741
742                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);
743                 if ((res.getErrorCode() == STATUS_CODE_SUCCESS) || (res.getErrorCode() == STATUS_CODE_CREATED)) {
744                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
745                 }
746 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
747                 return res;
748         }
749         
750         private static RestResponse addArtifactToInstance(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String checksum, String url) throws IOException {
751                 Map<String, String> additionalHeaders;
752                 additionalHeaders = new HashMap<>();
753                 if (checksum != null && !checksum.isEmpty()) {
754                         additionalHeaders = new HashMap<>();
755                         additionalHeaders.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
756                 }
757                 additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
758                 additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
759
760                 Gson gson = new Gson();
761                 String jsonBody = gson.toJson(artifactDetails);
762
763                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
764                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
765                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
766                 }
767                 return res;
768         }
769         
770         private static RestResponse updateDeploymentArtifact(ArtifactDefinition artifactDefinition, User sdncModifierDetails, String url) throws IOException {
771                 Map<String, String> additionalHeaders;
772                 additionalHeaders = new HashMap<>();
773                 additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
774                 additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
775                 
776                 Gson gson = new Gson();
777                 String jsonBody = gson.toJson(artifactDefinition);
778
779                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
780                 return res;
781         }
782         
783         private static RestResponse updateDeploymentArtifact(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String url) throws IOException {
784                 Map<String, String> additionalHeaders;
785                 
786                         additionalHeaders = new HashMap<>();
787                         additionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json, text/plain, */*");
788                         additionalHeaders.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json;charset=UTF-8");
789 //                      additionalHeaders.put(HttpHeaderEnum..getValue(), "application/json;charset=UTF-8");
790                 
791
792                 Gson gson = new Gson();
793                 String jsonBody = gson.toJson(artifactDetails);
794 //              System.out.println("ArtifactDetails: "+ jsonBody);
795
796                 RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), "application/json, text/plain, */*", additionalHeaders);
797                 if (res.getErrorCode() == STATUS_CODE_SUCCESS) {
798                         artifactDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(res));
799                 }
800 //              System.out.println("Add artifact was finished with response: "+ res.getErrorCode());
801                 return res;
802         }
803         
804         private static RestResponse downloadArtifact(String url, User user, Map<String, String> addionalHeaders,boolean addEcompHeader) throws IOException
805         {       
806                 if(addEcompHeader){
807                         addionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
808                 }
809                 return downloadArtifact(url, user, addionalHeaders, acceptOctetStream);
810         }
811         
812         private static RestResponse downloadArtifact(String url, User user, Map<String, String> addionalHeaders, String accept) throws IOException
813         {
814                 addionalHeaders.put(HttpHeaderEnum.ACCEPT.getValue(), accept);
815                 
816                 RestResponse res =  sendGet(url, user.getUserId(), addionalHeaders);
817 //              System.out.println("download artifact was finished with response: "+ res.getErrorCode());
818 //              System.out.println("response is: " + res.getResponse());
819                 return res;
820         }
821         
822         private static Map<String,Map<String,Object>> getArtifactsListFromResponse(String jsonResponse, String fieldOfArtifactList){
823                 JSONObject object = (JSONObject)JSONValue.parse(jsonResponse);
824                 Map<String,Map<String,Object>> map = (Map<String,Map<String,Object>>)object.get(fieldOfArtifactList);
825                 return map;
826         }
827
828         public static String calculateChecksum(ArtifactReqDetails artifactDetails) {
829                 String checksum = null;
830                 if (artifactDetails.getPayload() != null) {
831                         checksum = ResponseParser.calculateMD5Header(artifactDetails);
832                 }
833                 return checksum;
834         }
835         
836         public static String encodeUrlForDownload(String url){
837
838                 return url.replaceAll(" ", "%20");
839         }
840         
841         public static String getPartialUrlByArtifactName(ServiceReqDetails serviceDetails,String serviceVersion ,String artifactName){
842                 return encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL, ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceVersion, artifactName));
843         }
844         
845         public static String getUniqueIdOfArtifact(RestResponse createResponse, String artifactField, String requieredArtifactLabel) throws Exception
846         {
847                 Map<String, Object> artifact = getArtifactFromRestResponse(createResponse, artifactField, requieredArtifactLabel);
848                 assertNotNull(artifact);
849                 return artifact.get("uniqueId").toString();
850         }
851         
852         public static Map<String, Object> getArtifactFromRestResponse(RestResponse response, String artifactField, String requieredArtifactLabel)
853         {
854                 Map<String, Map<String, Object>> map = getArtifactsListFromResponse(response.getResponse(), artifactField);
855                 return map.get(requieredArtifactLabel);
856         }
857         
858
859         
860         public static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid) throws IOException
861         {
862                 return updateInformationalArtifactPayloadOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, calculateMD5Header(artifactDetails));
863         }
864         
865         private static RestResponse updateInformationalArtifactPayloadOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum) throws IOException
866         {
867                 return updateInformationalArtifactOfService(artifactDetails, sdncModifierDetails, serviceUid, artifactUid, checksum, true);
868         }
869         
870         private static RestResponse updateInformationalArtifactOfService(ArtifactReqDetails artifactDetails, User sdncModifierDetails, String serviceUid, String artifactUid, String checksum, boolean isPayloadUpdate) throws IOException
871         {
872                 Config config = Utils.getConfig();
873                 Map<String, String> headersMap = prepareHeadersMap(sdncModifierDetails.getUserId());
874
875                 if (isPayloadUpdate){
876                         headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), checksum);
877                 }
878
879                 Gson gson = new Gson();
880                 String jsonBody = gson.toJson(artifactDetails);
881
882                 HttpRequest http = new HttpRequest();
883
884                 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUid, artifactUid);
885                 RestResponse res =  http.httpSendPost(url, jsonBody, headersMap);
886 //              System.out.println("update artifact was finished with response: "+ res.getErrorCode());
887                 return res;
888         }
889         
890         public static String calculateMD5Header(ArtifactReqDetails artifactDetails)
891         {
892                 Gson gson = new Gson();
893                 String jsonBody = gson.toJson(artifactDetails);
894                 // calculate MD5 for json body
895                 return calculateMD5(jsonBody);
896
897         }
898         
899         public static String calculateMD5 (String data){
900                 String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
901                 // encode base-64 result
902                 byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
903                 String encodeBase64Str = new String(encodeBase64);
904                 return encodeBase64Str;
905
906         }
907
908
909 }