Added oparent to sdc main
[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.annotations.*;
25 import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
26 import org.openecomp.sdc.be.mixin.PolicyTypeMixin;
27 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
28 import org.openecomp.sdc.be.view.ResponseView;
29 import org.openecomp.sdc.common.api.Constants;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import org.springframework.stereotype.Controller;
32
33 import javax.ws.rs.*;
34 import javax.ws.rs.core.MediaType;
35 import java.util.List;
36
37 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
38 @Path("/v1/catalog")
39 @Api(value = "policy types resource")
40 @Controller
41 @Consumes(MediaType.APPLICATION_JSON)
42 @Produces(MediaType.APPLICATION_JSON)
43 public class PolicyTypesEndpoint {
44
45     private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
46
47     private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
48
49     public PolicyTypesEndpoint(PolicyTypeBusinessLogic policyTypeBusinessLogic) {
50         this.policyTypeBusinessLogic = policyTypeBusinessLogic;
51     }
52
53     @GET
54     @Path("/policyTypes")
55     @ApiOperation(value = "Get policy types ", httpMethod = "GET", notes = "Returns policy types", response = PolicyTypeDefinition.class, responseContainer="List")
56     @ApiResponses(value = { @ApiResponse(code = 200, message = "policy types found"),
57                             @ApiResponse(code = 403, message = "Restricted operation"),
58                             @ApiResponse(code = 500, message = "The GET request failed due to internal SDC problem.")})
59     @ResponseView(mixin = {PolicyTypeMixin.class})
60     public List<PolicyTypeDefinition> getPolicyTypes(@ApiParam(value = "An optional parameter to indicate the type of the container from where this call is executed")
61                                    @QueryParam("internalComponentType") String internalComponentType,
62                                                      @ApiParam(value = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
63         log.debug("(get) Start handle request of GET policyTypes");
64         return policyTypeBusinessLogic.getAllPolicyTypes(userId, internalComponentType);
65     }
66
67 }