X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fmain%2Frest%2FPolicyAuditControllerV1.java;h=81681ff8bd558901d908d0dbeb61204567a9f4ee;hb=09191f108632a46862ea7c60023ea5d012a81823;hp=9eeef2be82d9ede7dff799a295237a9aec48c1e0;hpb=7c48007486d0d1ee47a5eea81135e49737677155;p=policy%2Fpap.git diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java index 9eeef2be..81681ff8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +19,9 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.time.Instant; import java.util.Collection; +import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfModelException; @@ -35,11 +29,6 @@ import org.onap.policy.models.pap.concepts.PolicyAudit; import org.onap.policy.pap.main.service.PolicyAuditService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -47,9 +36,8 @@ import org.springframework.web.bind.annotation.RestController; * various operations on policies. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PolicyAuditControllerV1 extends PapRestControllerV1 { +public class PolicyAuditControllerV1 extends PapRestControllerV1 implements PolicyAuditControllerV1Api { public static final String NO_AUDIT_RECORD_FOUND = "No records found matching the input parameters"; @@ -65,51 +53,12 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit") - @ApiOperation(value = "Queries audit information for all the policies", - notes = "Queries audit information for all the policies, " - + "returning audit information for all the policies in the database", - responseContainer = "List", response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity> getAllAuditRecords( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) - throws PfModelException { + @Override + public ResponseEntity> getAllAuditRecords( + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(policyAuditService .getAuditRecords(recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -126,51 +75,13 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{pdpGroupName}") - @ApiOperation(value = "Queries audit information for all the policies in a PdpGroup", - notes = "Queries audit information for all the policies in a PdpGroup, " - + "returning audit information for all the policies belonging to the PdpGroup", - responseContainer = "List", response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on + @Override public ResponseEntity getAuditRecordsByGroup( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName) throws PfModelException { + String pdpGroupName, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(pdpGroupName, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -189,55 +100,15 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{pdpGroupName}/{policyName}/{policyVersion}") - @ApiOperation(value = "Queries audit information for a specific version of a policy in a PdpGroup", - notes = "Queries audit information for a specific version of a policy in a PdpGroup," - + " returning audit information for the policy belonging to the PdpGroup", - response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity getAuditRecordsOfPolicy( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100", required = false) @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp", required = false) @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName, - @ApiParam(value = "Policy Name") @PathVariable("policyName") String policyName, - @ApiParam(value = "Policy Version") @PathVariable(value = "policyVersion") String policyVersion) - throws PfModelException { + @Override + public ResponseEntity getAuditRecordsOfPolicyinPdpGroup( + String pdpGroupName, + String policyName, + String policyVersion, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(pdpGroupName, policyName, policyVersion, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -255,55 +126,14 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{policyName}/{policyVersion}") - @ApiOperation(value = "Queries audit information for a specific version of a policy", - notes = "Queries audit information for a specific version of a policy," - + " returning audit information for the policy", - response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - + @Override public ResponseEntity getAuditRecordsOfPolicy( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "Policy Name") @PathVariable(required = true, value = "policyName") String policyName, - @ApiParam( - value = "Policy Version") @PathVariable(required = true, value = "policyVersion") String policyVersion) - throws PfModelException { + String policyName, + String policyVersion, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(policyName, policyVersion, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime)));