aboutsummaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/LifecycleRestUtils.java
blob: 72cad8c3cae8c05d223259cb8c38b60e0e59d78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.utils.rest;

import org.json.simple.JSONObject;
import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.ci.tests.api.Urls;
import org.openecomp.sdc.ci.tests.config.Config;
import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.Utils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class LifecycleRestUtils extends BaseRestUtils {
	private static Logger logger = LoggerFactory.getLogger(LifecycleRestUtils.class.getName());
	public static final String COMMENT = "comment";
	
	// External APIs
	public static RestResponse checkInResource(String resourceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Chekin resource: " + resourceUUID;
		return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.CHECKIN, sdncModifierDetails, comment);
	}
	
	public static RestResponse checkInService(String serviceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Chekin service: " + serviceUUID;
		return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.CHECKIN, sdncModifierDetails, comment);
	}
	
	public static RestResponse checkOutResource(String resourceUUID, User sdncModifierDetails) throws IOException {
		String comment = "CheckOut resource: " + resourceUUID;
		return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.CHECKOUT, sdncModifierDetails, comment);
	}
	
	public static RestResponse checkOutService(String serviceUUID, User sdncModifierDetails) throws IOException {
		String comment = "CheckOut service: " + serviceUUID;
		return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.CHECKOUT, sdncModifierDetails, comment);
	}
	
	public static RestResponse certificationRequestService(String serviceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Certification request service: " + serviceUUID;
		return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.CERTIFICATIONREQUEST, sdncModifierDetails, comment);
	}
	
	/*public static RestResponse certificationRequestResource(String resourceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Certification request resource: " + resourceUUID;
		return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.CERTIFICATIONREQUEST, sdncModifierDetails, comment);
	}*/
	
	public static RestResponse startTestingService(String serviceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Start testing request service: " + serviceUUID;
		return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.STARTCERTIFICATION, sdncModifierDetails, comment);
	}
	
	public static RestResponse startTestingResource(String resourceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Start testing request resource: " + resourceUUID;
		return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.STARTCERTIFICATION, sdncModifierDetails, comment);
	}
	
	public static RestResponse certifyService(String serviceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Certify request service: " + serviceUUID;
		return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.CERTIFY, sdncModifierDetails, comment);
	}
	
	public static RestResponse certifyResource(String resourceUUID, User sdncModifierDetails) throws IOException {
		String comment = "Certify request resource: " + resourceUUID;
		return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.CERTIFY, sdncModifierDetails, comment);
	}
	
	
	
	
	
	private static RestResponse changeLifeCycleOfAsset(String assetUUID, AssetTypeEnum assetTypeEnum, LifeCycleStatesEnum lifeCycleStatesEnum, User sdncModifierDetails, String comment) throws IOException {
		Config config = Utils.getConfig();
		String url = String.format(Urls.POST_EXTERNAL_API_CHANGE_LIFE_CYCLE_OF_ASSET, config.getCatalogBeHost(), config.getCatalogBePort(), assetTypeEnum.getValue(), assetUUID, lifeCycleStatesEnum.getState());
		
		Map<String, String> additionalHeaders = new HashMap<>();
		
		additionalHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
		additionalHeaders.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);

		String jsonBody = "{\"userRemarks\": \"" + comment + "\"}";

		RestResponse res = sendPost(url, jsonBody, sdncModifierDetails.getUserId(), acceptHeaderData, additionalHeaders);

		return res;
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	public static RestResponse changeResourceState(ResourceReqDetails resourceDetails, User sdncModifierDetails,
			String version, LifeCycleStatesEnum LifeCycleStatesEnum) throws IOException {
		return changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum,
				createLifecycleCommentJson(COMMENT));
	}

	public static RestResponse changeResourceState(ResourceReqDetails resourceDetails, User sdncModifierDetails,
			String version, LifeCycleStatesEnum LifeCycleStatesEnum, String LifecycleChangeInfo) throws IOException {

		return changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum, LifecycleChangeInfo);

	}

	public static RestResponse changeResourceState(ResourceReqDetails resourceDetails, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws IOException {

		return changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum,
				createLifecycleCommentJson(COMMENT));

	}

	public static RestResponse changeResourceState(ResourceReqDetails resourceDetails, String modifierUserId,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws IOException {
		User user = new User();
		user.setUserId(modifierUserId);
		return changeResourceState(resourceDetails, user, LifeCycleStatesEnum, createLifecycleCommentJson(COMMENT));
	}

	private static RestResponse changeResourceState(ResourceReqDetails resourceDetails, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum, String LifecycleChangeInfo) throws IOException {
		Config config = Utils.getConfig();
		String url = String.format(Urls.CHANGE_RESOURCE_LIFECYCLE_STATE, config.getCatalogBeHost(),
				config.getCatalogBePort(), resourceDetails.getUniqueId(), LifeCycleStatesEnum);
		// System.out.println("url: " + url);

		RestResponse LifeCycleStatesEnumResourceResponse = sendPost(url, LifecycleChangeInfo,
				sdncModifierDetails.getUserId(), acceptHeaderData);
		if (LifeCycleStatesEnumResourceResponse.getErrorCode() == STATUS_CODE_SUCCESS) {
			String stateFromJsonResponse = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumResourceResponse.getResponse(), "lifecycleState");
			resourceDetails.setVersion(ResponseParser.getVersionFromResponse(LifeCycleStatesEnumResourceResponse));
			resourceDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(LifeCycleStatesEnumResourceResponse));
			if (stateFromJsonResponse != null) {
				resourceDetails.setLifecycleState(LifecycleStateEnum.valueOf(stateFromJsonResponse));
			}
		}
		return LifeCycleStatesEnumResourceResponse;
	}

	public static RestResponse changeServiceState(ServiceReqDetails serviceDetails, User sdncModifierDetails,
			String version, LifeCycleStatesEnum LifeCycleStatesEnum) throws Exception {
		{
			return changeServiceState(serviceDetails, sdncModifierDetails, version, LifeCycleStatesEnum,
					createLifecycleCommentJson(COMMENT));
		}
	}

	public static RestResponse changeServiceState(ServiceReqDetails serviceDetails, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws Exception {
		{
			return changeServiceState(serviceDetails, sdncModifierDetails, null, LifeCycleStatesEnum,
					createLifecycleCommentJson(COMMENT));
		}
	}

	public static RestResponse changeServiceState(ServiceReqDetails serviceDetails, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum, String lifecycleChangeInfo) throws Exception {
		{
			return changeServiceState(serviceDetails, sdncModifierDetails, null, LifeCycleStatesEnum,
					lifecycleChangeInfo);
		}
	}

	public static RestResponse changeServiceState(ServiceReqDetails serviceDetails, User sdncModifierDetails,
			String version, LifeCycleStatesEnum LifeCycleStatesEnum, String lifecycleChangeInfo) throws Exception {

		Config config = Utils.getConfig();
		Map<String, String> headersMap = prepareHeadersMap(sdncModifierDetails);
		HttpRequest http = new HttpRequest();
		String url = String.format(Urls.CHANGE_SERVICE_LIFECYCLE_STATE, config.getCatalogBeHost(),
				config.getCatalogBePort(), serviceDetails.getUniqueId(), LifeCycleStatesEnum);
		// System.out.println("url: " + url);
		RestResponse LifeCycleStatesEnumServiceResponse = http.httpSendPost(url, lifecycleChangeInfo, headersMap);
		if (LifeCycleStatesEnumServiceResponse.getErrorCode() == STATUS_CODE_SUCCESS) {
			String serviceUniqueId = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "uniqueId");
			serviceDetails.setUniqueId(serviceUniqueId);
			String serviceVersion = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "version");
			serviceDetails.setVersion(serviceVersion);
			String stateFromJsonResponse = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "lifecycleState");
			serviceDetails.setLifecycleState(LifecycleStateEnum.valueOf(stateFromJsonResponse));
		}
		return LifeCycleStatesEnumServiceResponse;
	}

	public static RestResponse changeProductState(Product product, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum, String lifecycleChangeInfo) throws Exception {
		{
			return _changeProductState(product, sdncModifierDetails, LifeCycleStatesEnum, lifecycleChangeInfo);
		}
	}

	public static RestResponse changeProductState(Product product, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws Exception {
		{
			return _changeProductState(product, sdncModifierDetails, LifeCycleStatesEnum, COMMENT);
		}
	}

	public static RestResponse changeProductState(ProductReqDetails productDetails, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws Exception {
		Config config = Utils.getConfig();
		String url = String.format(Urls.CHANGE_PRODUCT_LIFECYCLE_STATE, config.getCatalogBeHost(),
				config.getCatalogBePort(), productDetails.getUniqueId(), LifeCycleStatesEnum);
		RestResponse LifeCycleStatesEnumServiceResponse = sendPost(url, createLifecycleCommentJson(COMMENT),
				sdncModifierDetails.getUserId(), acceptHeaderData);
		if (LifeCycleStatesEnumServiceResponse.getErrorCode() == STATUS_CODE_SUCCESS) {
			String productUniqueId = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "uniqueId");
			productDetails.setUniqueId(productUniqueId);
			String productVersion = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "version");
			productDetails.setVersion(productVersion);
			String newLifecycleState = ResponseParser
					.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "lifecycleState");
			productDetails.setLifecycleState(LifecycleStateEnum.valueOf(newLifecycleState));
		}
		return LifeCycleStatesEnumServiceResponse;

	}

	public static RestResponse changeComponentState(Component component, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum) throws Exception {
		Config config = Utils.getConfig();
		String url = String.format(Urls.CHANGE_COMPONENT_LIFECYCLE_STATE, config.getCatalogBeHost(),
				config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId(), LifeCycleStatesEnum);
		RestResponse LifeCycleStatesEnumServiceResponse = sendPost(url, createLifecycleCommentJson(COMMENT), sdncModifierDetails.getUserId(), acceptHeaderData);
		if (LifeCycleStatesEnumServiceResponse.getErrorCode() == STATUS_CODE_SUCCESS) {
			String productUniqueId = ResponseParser.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "uniqueId");
			component.setUniqueId(productUniqueId);
			String productVersion = ResponseParser.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "version");
			component.setVersion(productVersion);
			String newLifecycleState = ResponseParser.getValueFromJsonResponse(LifeCycleStatesEnumServiceResponse.getResponse(), "lifecycleState");
			component.setLifecycleState(LifecycleStateEnum.valueOf(newLifecycleState));
		}
		return LifeCycleStatesEnumServiceResponse;

	}

	public static RestResponse certifyResource(ResourceReqDetails resourceDetails) throws Exception {

		User designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
		RestResponse restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CHECKIN);
		// if (restResponseResource.getErrorCode() == 200){
/*		restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CERTIFICATIONREQUEST);
		// }else
		// return restResponseResource;
		User testerDetails = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
		if (restResponseResource.getErrorCode() == 200) {
			restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, testerDetails,
					LifeCycleStatesEnum.STARTCERTIFICATION);
		} else
			return restResponseResource;*/
		if (restResponseResource.getErrorCode() == 200) {
			restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, designer,
					LifeCycleStatesEnum.CERTIFY);
			if (restResponseResource.getErrorCode() == 200) {
				String newVersion = ResponseParser.getVersionFromResponse(restResponseResource);
				resourceDetails.setVersion(newVersion);
				resourceDetails.setLifecycleState(LifecycleStateEnum.CERTIFIED);
				resourceDetails.setLastUpdaterUserId(designer.getUserId());
				resourceDetails.setLastUpdaterFullName(designer.getFullName());
				String uniqueIdFromRresponse = ResponseParser.getUniqueIdFromResponse(restResponseResource);
				resourceDetails.setUniqueId(uniqueIdFromRresponse);
			}
		}
		return restResponseResource;
	}

	public static RestResponse certifyService(ServiceReqDetails serviceDetails) throws Exception {
		RestResponse restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CHECKIN);
		// if (restResponseService.getErrorCode() == 200){
		restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CERTIFICATIONREQUEST);
		// }else
		// return restResponseService;
		if (restResponseService.getErrorCode() == 200) {
			restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails,
					ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
		} else
			return restResponseService;
		if (restResponseService.getErrorCode() == 200) {
			User testerDetails = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
			restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails, testerDetails,
					LifeCycleStatesEnum.CERTIFY);
			if (restResponseService.getErrorCode() == 200) {
				String newVersion = ResponseParser.getVersionFromResponse(restResponseService);
				serviceDetails.setVersion(newVersion);
				serviceDetails.setLifecycleState(LifecycleStateEnum.CERTIFIED);
				serviceDetails.setLastUpdaterUserId(testerDetails.getUserId());
				serviceDetails.setLastUpdaterFullName(testerDetails.getFullName());
				String uniqueIdFromRresponse = ResponseParser.getUniqueIdFromResponse(restResponseService);
				serviceDetails.setUniqueId(uniqueIdFromRresponse);
			}
		}
		return restResponseService;
	}

	private static RestResponse _changeProductState(Product product, User sdncModifierDetails,
			LifeCycleStatesEnum LifeCycleStatesEnum, String lifecycleChangeInfo) throws Exception {

		Config config = Utils.getConfig();
		String url = String.format(Urls.CHANGE_PRODUCT_LIFECYCLE_STATE, config.getCatalogBeHost(),
				config.getCatalogBePort(), product.getUniqueId(), LifeCycleStatesEnum);
		RestResponse LifeCycleStatesEnumServiceResponse = sendPost(url, createLifecycleCommentJson(lifecycleChangeInfo),
				sdncModifierDetails.getUserId(), acceptHeaderData);

		return LifeCycleStatesEnumServiceResponse;
	}

	public static String createLifecycleCommentJson(String commentContent) {
		String res = null;
		if (commentContent != null) {
			res = "{\"userRemarks\": \"" + commentContent + "\"}";
		}
		return res;
	}

	public static void checkLCS_Response(RestResponse response) {
		checkStatusCode(response, "change lifecycle request failed", false, STATUS_CODE_SUCCESS);
	}

	private static Map<String, String> prepareHeadersMap(User sdncModifierDetails) {
		Map<String, String> headersMap = new HashMap<>();
		headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
		headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderData);
		headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
		return headersMap;
	}

	public static RestResponse changeDistributionStatus(ServiceReqDetails serviceDetails, String version, User user,
			String userRemarks, DistributionStatusEnum reqDistributionStatus) throws Exception {
		String uniqueId = serviceDetails.getUniqueId();
		Config config = Utils.getConfig();
		String environmentName = "AUTO";
//		String environmentName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
		DistributionStatusEnum distributionStatusEnum = DistributionStatusEnum.findState(reqDistributionStatus.getValue());
		switch(distributionStatusEnum){
			case DISTRIBUTED:
				String url = String.format(Urls.ACTIVATE_DISTRIBUTION, config.getCatalogBeHost(), config.getCatalogBePort(), uniqueId, environmentName);
				return sendDistrState(user, userRemarks, url);
			default:
				return null;	
			
		}
		
//		if (reqDistributionStatus == DistributionStatusEnum.DISTRIBUTION_APPROVED) {
//			return sendApproveDistribution(user, uniqueId, userRemarks);
//		} else if (reqDistributionStatus == DistributionStatusEnum.DISTRIBUTION_REJECTED) {
//			return rejectDistribution(user, userRemarks, uniqueId);
//		} else if (reqDistributionStatus == DistributionStatusEnum.DISTRIBUTED) {
//			Config config = Utils.getConfig();
//			// String url =
//			// String.format("http://%s:%s/sdc2/rest/v1/catalog/services/%s/tempUrlToBeDeleted",
//			// config.getCatalogBeHost(), config.getCatalogBePort(), uniqueId);
//			String url = String.format(Urls.ACTIVATE_DISTRIBUTION, config.getCatalogBeHost(), config.getCatalogBePort(),
//					uniqueId, "PROD");
//			return sendDistrState(user, userRemarks, url);
//		} else
//			return null;

	}

	public static RestResponse sendApproveDistribution(User sdncModifierDetails, String uniqueId, String userRemarks)
			throws FileNotFoundException, IOException {
		Config config = Utils.getConfig();
		String url = String.format(Urls.APPROVE_DISTRIBUTION, config.getCatalogBeHost(), config.getCatalogBePort(),
				uniqueId);
		return sendDistrState(sdncModifierDetails, userRemarks, url);
	}

	public static RestResponse rejectDistribution(ServiceReqDetails serviceDetails, String version, User user,
			String userRemarks) throws Exception {
		return rejectDistribution(user, userRemarks, serviceDetails.getUniqueId());
	}

	public static RestResponse rejectDistribution(User user, String userRemarks, String uniqueId)
			throws FileNotFoundException, IOException {
		Config config = Utils.getConfig();
		String url = String.format(Urls.REJECT_DISTRIBUTION, config.getCatalogBeHost(), config.getCatalogBePort(),
				uniqueId);
		return sendDistrState(user, userRemarks, url);
	}

	private static RestResponse sendDistrState(User user, String userRemarks, String url) throws IOException {
		Map<String, String> headersMap = prepareHeadersMap(user);
		Map<String, String> userRemarksMap = new HashMap<String, String>();
		userRemarksMap.put("userRemarks", userRemarks);

		String serviceBodyJson = new JSONObject().toJSONString(userRemarksMap);

		HttpRequest httpRequest = new HttpRequest();
		logger.debug(url);
		logger.debug("Send POST request to create service: {}", url);
		logger.debug("Service body: {}", serviceBodyJson);
		logger.debug("Service headers: {}", headersMap);
		RestResponse rejectDistributionResponse = httpRequest.httpSendPost(url, serviceBodyJson, headersMap);

		return rejectDistributionResponse;
	}

}