a978a5358210dc32f175f239b12151fbe31b0e0d
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / PolicyTypesEndpoint.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.Parameter;
25 import io.swagger.v3.oas.annotations.media.ArraySchema;
26 import io.swagger.v3.oas.annotations.media.Content;
27 import io.swagger.v3.oas.annotations.media.Schema;
28 import io.swagger.v3.oas.annotations.responses.ApiResponse;
29 import io.swagger.v3.oas.annotations.servers.Server;
30 import io.swagger.v3.oas.annotations.servers.Servers;
31 import io.swagger.v3.oas.annotations.tags.Tag;
32 import io.swagger.v3.oas.annotations.tags.Tags;
33 import java.util.List;
34 import javax.ws.rs.Consumes;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.HeaderParam;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.QueryParam;
40 import javax.ws.rs.core.MediaType;
41 import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
42 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
43 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
44 import org.openecomp.sdc.be.impl.ComponentsUtils;
45 import org.openecomp.sdc.be.mixin.PolicyTypeMixin;
46 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
47 import org.openecomp.sdc.be.view.ResponseView;
48 import org.openecomp.sdc.common.api.Constants;
49 import org.openecomp.sdc.common.log.wrappers.Logger;
50 import org.openecomp.sdc.common.util.ValidationUtils;
51 import org.springframework.stereotype.Controller;
52
53 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
54 @Path("/v1/catalog")
55 @Tags({@Tag(name = "SDCE-2 APIs")})
56 @Servers({@Server(url = "/sdc2/rest")})
57 @Controller
58 @Consumes(MediaType.APPLICATION_JSON)
59 @Produces(MediaType.APPLICATION_JSON)
60 public class PolicyTypesEndpoint extends BeGenericServlet {
61
62     private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
63     private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
64
65     public PolicyTypesEndpoint(ComponentsUtils componentsUtils,
66                                PolicyTypeBusinessLogic policyTypeBusinessLogic) {
67         super(componentsUtils);
68         this.policyTypeBusinessLogic = policyTypeBusinessLogic;
69     }
70
71     @GET
72     @Path("/policyTypes")
73     @Operation(description = "Get policy types ", method = "GET", summary = "Returns policy types", responses = {
74         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = PolicyTypeDefinition.class)))),
75         @ApiResponse(responseCode = "200", description = "policy types found"),
76         @ApiResponse(responseCode = "403", description = "Restricted operation"),
77         @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})
78     @ResponseView(mixin = {PolicyTypeMixin.class})
79     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
80     public List<PolicyTypeDefinition> getPolicyTypes(
81         @Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed")
82         @QueryParam("internalComponentType") String internalComponentType,
83         @QueryParam("componentModel") String internalComponentModel,
84         @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
85         log.debug("(get) Start handle request of GET policyTypes");
86         if (internalComponentModel != null) {
87             internalComponentModel = ValidationUtils.sanitizeInputString(internalComponentModel.trim());
88         }
89         return policyTypeBusinessLogic
90             .getAllPolicyTypes(userId, internalComponentType, internalComponentModel);
91     }
92 }