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