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