d3b2ae4e620cc66ce3fa3cbc1bd4b54122ff3ab0
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / GroupTypesEndpoint.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.GroupTypeBusinessLogic;
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.GroupTypeMixin;
46 import org.openecomp.sdc.be.model.GroupTypeDefinition;
47 import org.openecomp.sdc.be.view.ResponseView;
48 import org.openecomp.sdc.common.api.Constants;
49 import org.openecomp.sdc.common.util.ValidationUtils;
50 import org.springframework.stereotype.Controller;
51
52 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
53 @Path("/v1/catalog")
54 @Tags({@Tag(name = "SDCE-2 APIs")})
55 @Servers({@Server(url = "/sdc2/rest")})
56 @Controller
57 @Consumes(MediaType.APPLICATION_JSON)
58 @Produces(MediaType.APPLICATION_JSON)
59 public class GroupTypesEndpoint extends BeGenericServlet {
60
61     private final GroupTypeBusinessLogic groupTypeBusinessLogic;
62
63     public GroupTypesEndpoint(ComponentsUtils componentsUtils, GroupTypeBusinessLogic groupTypeBusinessLogic) {
64         super(componentsUtils);
65         this.groupTypeBusinessLogic = groupTypeBusinessLogic;
66     }
67
68     @GET
69     @Path("/groupTypes")
70     @Operation(description = "Get group types ", method = "GET", summary = "Returns group types", responses = {
71         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupTypeDefinition.class)))),
72         @ApiResponse(responseCode = "200", description = "group types found"),
73         @ApiResponse(responseCode = "400", description = "field name invalid type/length, characters;  mandatory field is absent, already exists (name)"),
74         @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "500", description = "Internal Error")})
75     @ResponseView(mixin = {GroupTypeMixin.class})
76     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
77     public List<GroupTypeDefinition> getGroupTypes(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
78                                                    @Parameter(description =
79                                                        "An optional parameter to indicate the type of the container from where this call is executed")
80                                                    @QueryParam("internalComponentType") String internalComponentType,
81                                                    @QueryParam("componentModel") String internalComponentModel) {
82         if (internalComponentModel != null) {
83             internalComponentModel = ValidationUtils.sanitizeInputString(internalComponentModel.trim());
84         }
85         return groupTypeBusinessLogic
86             .getAllGroupTypes(userId, internalComponentType, internalComponentModel);
87     }
88 }