2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.client.policy;
24 import java.util.UUID;
26 import javax.ws.rs.client.Entity;
27 import javax.ws.rs.core.MediaType;
29 import org.springframework.stereotype.Service;
32 public class PolicyRestClient extends RestClient {
34 private static final String ENDPOINT_KEY = "policy.endpoint";
35 private static final String X_ECOMP_REQUESTID = String.valueOf(UUID.randomUUID());
37 public PolicyRestClient() {
42 protected void initializeHeaderMap(Map<String, String> headerMap) {
43 headerMap.put("ClientAuth", properties.get("policy.client.auth"));
44 headerMap.put("Authorization", properties.get("policy.auth"));
45 headerMap.put("Environment", properties.get("policy.environment"));
46 headerMap.put("X-ECOMP-RequestID", X_ECOMP_REQUESTID);
49 public PolicyDecision getDecision(String serviceType, String vnfType, String bbID, String workStep,
51 DecisionAttributes decisionAttributes = new DecisionAttributes();
52 decisionAttributes.setServiceType(serviceType);
53 decisionAttributes.setVNFType(vnfType);
54 decisionAttributes.setBBID(bbID);
55 decisionAttributes.setWorkStep(workStep);
56 decisionAttributes.setErrorCode(errorCode);
58 return this.getDecision(decisionAttributes);
61 private PolicyDecision getDecision(DecisionAttributes decisionAttributes) {
62 PolicyDecisionRequest decisionRequest = new PolicyDecisionRequest();
63 decisionRequest.setDecisionAttributes(decisionAttributes);
64 decisionRequest.setEcompcomponentName(ECOMP_COMPONENT_NAME);
66 return this.getBuilder().accept(MediaType.APPLICATION_JSON_TYPE)
67 .post(Entity.entity(decisionRequest, MediaType.APPLICATION_JSON)).readEntity(PolicyDecision.class);