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