2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 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.onap.policy.controlloop.actor.xacml;
23 import java.util.Collections;
25 import java.util.concurrent.CompletableFuture;
26 import javax.ws.rs.core.Response;
27 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
28 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
31 import org.onap.policy.models.decisions.concepts.DecisionRequest;
32 import org.onap.policy.models.decisions.concepts.DecisionResponse;
34 public class ConfigureOperation extends DecisionOperation {
37 public static final String NAME = "Configure";
40 * Constructs the object.
42 * @param params operation parameters
43 * @param config configuration for this operation
45 public ConfigureOperation(ControlLoopOperationParams params, HttpConfig config) {
46 super(params, config, Collections.emptyList());
50 protected DecisionRequest makeRequest() {
51 if (params.getPayload() == null) {
52 throw new IllegalArgumentException("missing payload");
55 DecisionRequest req = config.makeRequest();
56 req.setRequestId(getSubRequestId());
57 req.setResource(params.getPayload());
63 protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
64 Response rawResponse, DecisionResponse response) {
66 outcome.setResponse(response);
69 Map<String, Object> policies = response.getPolicies();
70 if (policies == null || policies.isEmpty()) {
71 outcome.setResult(OperationResult.FAILURE);
72 outcome.setMessage("response contains no policies");
73 return CompletableFuture.completedFuture(outcome);
76 outcome.setResult(OperationResult.SUCCESS);
79 outcome.setMessage(response.getMessage());
81 return CompletableFuture.completedFuture(outcome);