b0de1e7c55439258731b0da761e85737815da365
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PolicyStatusControllerV1.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
4  * ================================================================================
5  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2021 Nordix Foundation.
7  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pap.main.rest;
24
25 import com.google.re2j.PatternSyntaxException;
26 import io.swagger.annotations.ApiOperation;
27 import io.swagger.annotations.ApiParam;
28 import io.swagger.annotations.ApiResponse;
29 import io.swagger.annotations.ApiResponses;
30 import io.swagger.annotations.Authorization;
31 import io.swagger.annotations.Extension;
32 import io.swagger.annotations.ExtensionProperty;
33 import io.swagger.annotations.ResponseHeader;
34 import java.util.Collection;
35 import java.util.UUID;
36 import lombok.RequiredArgsConstructor;
37 import org.onap.policy.models.base.PfModelRuntimeException;
38 import org.onap.policy.models.pap.concepts.PolicyStatus;
39 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.http.HttpStatus;
44 import org.springframework.http.ResponseEntity;
45 import org.springframework.web.bind.annotation.GetMapping;
46 import org.springframework.web.bind.annotation.PathVariable;
47 import org.springframework.web.bind.annotation.RequestHeader;
48 import org.springframework.web.bind.annotation.RequestMapping;
49 import org.springframework.web.bind.annotation.RequestParam;
50 import org.springframework.web.bind.annotation.RestController;
51
52 /**
53  * Class to provide REST end points for PAP component to retrieve the status of deployed
54  * policies.
55  */
56 @RestController
57 @RequestMapping(path = "/policy/pap/v1")
58 @RequiredArgsConstructor
59 public class PolicyStatusControllerV1 extends PapRestControllerV1 {
60     private static final String EMPTY_REGEX_ERROR_MESSAGE = "An empty string passed as a regex is not allowed";
61     private static final String EMPTY_REGEX_WARNING = ". Empty string passed as Regex.";
62     private static final String GET_DEPLOYMENTS_FAILED = "get deployments failed";
63
64     private static final Logger logger = LoggerFactory.getLogger(PolicyStatusControllerV1.class);
65
66     private final PolicyStatusProvider provider;
67
68     /**
69      * Queries status of all deployed policies. If regex is not null or empty, the function will only return
70      * policies that match regex
71      *
72      * @param requestId request ID used in ONAP logging
73      * @param regex regex for a policy name
74      * @return a response
75      */
76     // @formatter:off
77     @GetMapping("policies/deployed")
78     @ApiOperation(value = "Queries status of all deployed policies",
79         notes = "Queries status of all deployed policies, returning success and failure counts of the PDPs",
80         responseContainer = "List", response = PolicyStatus.class,
81         tags = {"Policy Deployment Status"},
82         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
83         responseHeaders = {
84             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
85                             response = String.class),
86             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
87                             response = String.class),
88             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
89                             response = String.class),
90             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
91                             response = UUID.class)},
92         extensions = {
93             @Extension(name = EXTENSION_NAME,
94                 properties = {
95                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
96                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
97                 })
98             })
99     @ApiResponses(value = {
100         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
101         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
102         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
103     })
104     // @formatter:on
105
106     public ResponseEntity<Object> queryAllDeployedPolicies(
107         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
108             required = false,
109             value = REQUEST_ID_NAME) final UUID requestId,
110         @ApiParam(value = "Regex for a policy name") @RequestParam(required = false, value = "regex") String regex) {
111         try {
112             final Collection<PolicyStatus> result;
113             if (regex == null) {
114                 result = provider.getStatus();
115             } else if (regex.isBlank()) {
116                 return makeRegexNotFoundResponse(requestId);
117             } else {
118                 result = provider.getByRegex(regex);
119             }
120             return makeListOrNotFoundResponse(requestId, result);
121
122         } catch (PfModelRuntimeException e) {
123             logger.warn(GET_DEPLOYMENTS_FAILED, e);
124             return addLoggingHeaders(
125                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
126                 requestId).body(e.getErrorResponse().getErrorMessage());
127         } catch (PatternSyntaxException e) {
128             logger.warn(GET_DEPLOYMENTS_FAILED, e);
129             return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(HttpStatus.BAD_REQUEST)), requestId)
130                 .body(e.getMessage());
131         }
132     }
133
134     /**
135      * Queries status of specific deployed policies.
136      *
137      * @param requestId request ID used in ONAP logging
138      * @return a response
139      */
140     // @formatter:off
141     @GetMapping("policies/deployed/{name}")
142     @ApiOperation(value = "Queries status of specific deployed policies",
143         notes = "Queries status of specific deployed policies, returning success and failure counts of the PDPs",
144         responseContainer = "List", response = PolicyStatus.class,
145         tags = {"Policy Deployment Status"},
146         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
147         responseHeaders = {
148             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
149                             response = String.class),
150             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
151                             response = String.class),
152             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
153                             response = String.class),
154             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
155                             response = UUID.class)},
156         extensions = {
157             @Extension(name = EXTENSION_NAME,
158                 properties = {
159                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
160                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
161                 })
162             })
163     @ApiResponses(value = {
164         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
165         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
166         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
167     })
168     // @formatter:on
169
170     public ResponseEntity<Object> queryDeployedPolicies(
171                     @ApiParam(value = "Policy Id") @PathVariable("name") String name,
172                     @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
173                         required = false,
174                         value = REQUEST_ID_NAME) final UUID requestId) {
175
176         try {
177             Collection<PolicyStatus> result = provider.getStatus(new ToscaConceptIdentifierOptVersion(name, null));
178             if (result.isEmpty()) {
179                 return makeNotFoundResponse(requestId);
180
181             } else {
182                 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(result);
183             }
184
185         } catch (PfModelRuntimeException e) {
186             logger.warn(GET_DEPLOYMENTS_FAILED, e);
187             return addLoggingHeaders(
188                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
189                 requestId).body(e.getErrorResponse().getErrorMessage());
190         }
191     }
192
193
194     /**
195      * Queries status of a specific deployed policy.
196      *
197      * @param requestId request ID used in ONAP logging
198      * @return a response
199      */
200     // @formatter:off
201     @GetMapping("policies/deployed/{name}/{version}")
202     @ApiOperation(value = "Queries status of a specific deployed policy",
203         notes = "Queries status of a specific deployed policy, returning success and failure counts of the PDPs",
204         response = PolicyStatus.class,
205         tags = {"Policy Deployment Status"},
206         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
207         responseHeaders = {
208             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
209                             response = String.class),
210             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
211                             response = String.class),
212             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
213                             response = String.class),
214             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
215                             response = UUID.class)},
216         extensions = {
217             @Extension(name = EXTENSION_NAME,
218                 properties = {
219                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
220                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
221                 })
222             })
223     @ApiResponses(value = {
224         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
225         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
226         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
227     })
228     // @formatter:on
229
230     public ResponseEntity<Object> queryDeployedPolicy(@ApiParam(value = "Policy Id") @PathVariable("name") String name,
231                     @ApiParam(value = "Policy Version") @PathVariable("version") String version,
232                     @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
233                         required = false,
234                         value = REQUEST_ID_NAME) final UUID requestId) {
235
236         try {
237             Collection<PolicyStatus> result = provider.getStatus(new ToscaConceptIdentifierOptVersion(name, version));
238             if (result.isEmpty()) {
239                 return makeNotFoundResponse(requestId);
240
241             } else {
242                 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
243                     .body(result.iterator().next());
244             }
245
246         } catch (PfModelRuntimeException e) {
247             logger.warn(GET_DEPLOYMENTS_FAILED, e);
248             return addLoggingHeaders(
249                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
250                 requestId).body(e.getErrorResponse().getErrorMessage());
251         }
252     }
253
254
255     /**
256      * Queries status of all policies.
257      *
258      * @param requestId request ID used in ONAP logging
259      * @return a response
260      */
261     // @formatter:off
262     @GetMapping("policies/status")
263     @ApiOperation(value = "Queries status of policies in all PdpGroups",
264         notes = "Queries status of policies in all PdpGroups, "
265             + "returning status of policies in all the PDPs belonging to all PdpGroups",
266         responseContainer = "List", response = PdpPolicyStatus.class,
267         tags = {"Policy Status"},
268         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
269         responseHeaders = {
270             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
271                             response = String.class),
272             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
273                             response = String.class),
274             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
275                             response = String.class),
276             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
277                             response = UUID.class)},
278         extensions = {
279             @Extension(name = EXTENSION_NAME,
280                 properties = {
281                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
282                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
283                 })
284             })
285     @ApiResponses(value = {
286         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
287         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
288         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
289     })
290     // @formatter:on
291
292     public ResponseEntity<Object> getStatusOfAllPolicies(
293         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
294             required = false,
295             value = REQUEST_ID_NAME) final UUID requestId) {
296
297         try {
298             return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
299                 .body(provider.getPolicyStatus());
300
301         } catch (PfModelRuntimeException e) {
302             logger.warn(GET_DEPLOYMENTS_FAILED, e);
303             return addLoggingHeaders(
304                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
305                 requestId).body(e.getErrorResponse().getErrorMessage());
306         }
307     }
308
309     /**
310      * Queries status of policies in a specific PdpGroup. if regex is not null or empty, the function will only return
311      * policies that match regex
312      *
313      * @param pdpGroupName name of the PdpGroup
314      * @param requestId request ID used in ONAP logging
315      * @param regex regex for a policy name
316      * @return a response
317      */
318     // @formatter:off
319     @GetMapping("policies/status/{pdpGroupName}")
320     @ApiOperation(value = "Queries status of policies in a specific PdpGroup",
321         notes = "Queries status of policies in a specific PdpGroup, "
322             + "returning status of policies in all the PDPs belonging to the PdpGroup",
323         responseContainer = "List", response = PdpPolicyStatus.class,
324         tags = {"Policy Status"},
325         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
326         responseHeaders = {
327             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
328                             response = String.class),
329             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
330                             response = String.class),
331             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
332                             response = String.class),
333             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
334                             response = UUID.class)},
335         extensions = {
336             @Extension(name = EXTENSION_NAME,
337                 properties = {
338                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
339                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
340                 })
341             })
342     @ApiResponses(value = {
343         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
344         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
345         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
346     })
347     // @formatter:on
348
349     public ResponseEntity<Object> getStatusOfPoliciesByGroup(
350         @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName,
351         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
352             required = false,
353             value = REQUEST_ID_NAME) final UUID requestId,
354         @ApiParam(value = "Regex for a policy name") @RequestParam(required = false, value = "regex") String regex) {
355
356         try {
357             final Collection<PdpPolicyStatus> result;
358             if (regex == null) {
359                 result = provider.getPolicyStatus(pdpGroupName);
360             } else if (regex.isBlank()) {
361                 return makeRegexNotFoundResponse(requestId);
362             } else {
363                 result = provider.getPolicyStatusByRegex(pdpGroupName, regex);
364             }
365             return makeListOrNotFoundResponse(requestId, result);
366
367         } catch (PfModelRuntimeException e) {
368             logger.warn(GET_DEPLOYMENTS_FAILED, e);
369             return addLoggingHeaders(
370                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
371                 requestId).body(e.getErrorResponse().getErrorMessage());
372         } catch (PatternSyntaxException e) {
373             logger.warn(GET_DEPLOYMENTS_FAILED, e);
374             return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(HttpStatus.BAD_REQUEST)), requestId)
375                 .body(e.getMessage());
376         }
377     }
378
379     /**
380      * Queries status of all versions of a specific policy in a specific PdpGroup.
381      *
382      * @param pdpGroupName name of the PdpGroup
383      * @param policyName name of the Policy
384      * @param requestId request ID used in ONAP logging
385      * @return a response
386      */
387     // @formatter:off
388     @GetMapping("policies/status/{pdpGroupName}/{policyName}")
389     @ApiOperation(value = "Queries status of all versions of a specific policy in a specific PdpGroup",
390         notes = "Queries status of all versions of a specific policy in a specific PdpGroup,"
391             + " returning status of all versions of the policy in the PDPs belonging to the PdpGroup",
392         responseContainer = "List", response = PdpPolicyStatus.class,
393         tags = {"Policy Administration (PAP) API"},
394         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
395         responseHeaders = {
396             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
397                             response = String.class),
398             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
399                             response = String.class),
400             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
401                             response = String.class),
402             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
403                             response = UUID.class)},
404         extensions = {
405             @Extension(name = EXTENSION_NAME,
406                 properties = {
407                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
408                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
409                 })
410             })
411     @ApiResponses(value = {
412         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
413         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
414         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
415     })
416     // @formatter:on
417
418     public ResponseEntity<Object> getStatusOfPolicies(
419         @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName,
420         @ApiParam(value = "Policy Id") @PathVariable("policyName") String policyName,
421         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
422             required = false,
423             value = REQUEST_ID_NAME) final UUID requestId) {
424
425         try {
426             Collection<PdpPolicyStatus> result =
427                 provider.getPolicyStatus(pdpGroupName, new ToscaConceptIdentifierOptVersion(policyName, null));
428             if (result.isEmpty()) {
429                 return makeNotFoundResponse(requestId);
430
431             } else {
432                 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
433                     .body(result);
434             }
435
436         } catch (PfModelRuntimeException e) {
437             logger.warn(GET_DEPLOYMENTS_FAILED, e);
438             return addLoggingHeaders(
439                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
440                 requestId).body(e.getErrorResponse().getErrorMessage());
441         }
442     }
443
444
445     /**
446      * Queries status of a specific version of a specific policy in a specific PdpGroup.
447      *
448      * @param pdpGroupName name of the PdpGroup
449      * @param policyName name of the Policy
450      * @param policyVersion version of the Policy
451      * @param requestId request ID used in ONAP logging
452      * @return a response
453      */
454     // @formatter:off
455     @GetMapping("policies/status/{pdpGroupName}/{policyName}/{policyVersion}")
456     @ApiOperation(value = "Queries status of a specific version of a specific policy in a specific PdpGroup",
457         notes = "Queries status of a specific version of a specific policy in a specific PdpGroup,"
458             + " returning status of the policy in the PDPs belonging to the PdpGroup",
459         response = PdpPolicyStatus.class,
460         tags = {"Policy Administration (PAP) API"},
461         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
462         responseHeaders = {
463             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
464                             response = String.class),
465             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
466                             response = String.class),
467             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
468                             response = String.class),
469             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
470                             response = UUID.class)},
471         extensions = {
472             @Extension(name = EXTENSION_NAME,
473                 properties = {
474                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
475                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
476                 })
477             })
478     @ApiResponses(value = {
479         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
480         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
481         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
482     })
483     // @formatter:on
484
485     public ResponseEntity<Object> getStatusOfPolicy(
486         @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName,
487         @ApiParam(value = "Policy Id") @PathVariable("policyName") String policyName,
488         @ApiParam(value = "Policy Version") @PathVariable("policyVersion") String policyVersion,
489         @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
490             required = false,
491             value = REQUEST_ID_NAME) final UUID requestId) {
492
493         try {
494             Collection<PdpPolicyStatus> result = provider.getPolicyStatus(pdpGroupName,
495                 new ToscaConceptIdentifierOptVersion(policyName, policyVersion));
496             if (result.isEmpty()) {
497                 return makeNotFoundResponse(requestId);
498
499             } else {
500                 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
501                     .body(result.iterator().next());
502             }
503
504         } catch (PfModelRuntimeException e) {
505             logger.warn(GET_DEPLOYMENTS_FAILED, e);
506             return addLoggingHeaders(
507                 addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
508                 requestId).body(e.getErrorResponse().getErrorMessage());
509         }
510     }
511
512     /**
513      * Makes a "not found" response.
514      *
515      * @param requestId request ID
516      * @return a "not found" response
517      */
518     private ResponseEntity<Object> makeNotFoundResponse(final UUID requestId) {
519         return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(HttpStatus.NOT_FOUND)), requestId)
520                         .build();
521     }
522
523     private ResponseEntity<Object> makeRegexNotFoundResponse(UUID requestId) {
524         logger.warn(GET_DEPLOYMENTS_FAILED + EMPTY_REGEX_WARNING);
525         return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(HttpStatus.BAD_REQUEST)),
526             requestId).body(EMPTY_REGEX_ERROR_MESSAGE);
527     }
528
529     private ResponseEntity<Object> makeListOrNotFoundResponse(UUID requestId, Collection<?> result) {
530         if (result.isEmpty()) {
531             return makeNotFoundResponse(requestId);
532         } else {
533             return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(result);
534         }
535     }
536 }