catalog-be servlets refactoring
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / GroupEndpoint.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 javax.inject.Inject;
26 import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
28 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
29 import org.openecomp.sdc.be.model.GroupProperty;
30 import org.openecomp.sdc.common.api.Constants;
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 /**
38  * Here new APIs for group will be written in an attempt to gradually clean BL code
39  */
40 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
41 @Path("/v1/catalog")
42 @Api(value = "Group Servlet")
43 @Controller
44 @Consumes(MediaType.APPLICATION_JSON)
45 @Produces(MediaType.APPLICATION_JSON)
46 public class GroupEndpoint {
47
48     private final GroupBusinessLogicNew groupBusinessLogic;
49
50     @Inject
51     public GroupEndpoint(GroupBusinessLogicNew groupBusinessLogic) {
52         this.groupBusinessLogic = groupBusinessLogic;
53     }
54
55     @POST
56     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
57     @ApiOperation(value = "Update group members ", httpMethod = "POST", notes = "Updates list of members and returns it", response = String.class, responseContainer = "List")
58     @ApiResponses(value = {
59             @ApiResponse(code = 200, message = "Group members updated"),
60             @ApiResponse(code = 400, message = "field name invalid type/length, characters;  mandatory field is absent, already exists (name)"),
61             @ApiResponse(code = 403, message = "Restricted operation"),
62             @ApiResponse(code = 404, message = "Component not found"),
63             @ApiResponse(code = 500, message = "Internal Error")
64     })
65     public List<String> updateGroupMembers(
66             @PathParam("containerComponentType") final String containerComponentType,
67             @PathParam("componentId") final String componentId,
68             @PathParam("groupUniqueId") final String groupUniqueId,
69             @ApiParam(value = "List of members unique ids", required = true) List<String> members,
70             @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
71         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
72         return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
73     }
74
75     @GET
76     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
77     @ApiOperation(value = "Get List of properties on a group", httpMethod = "GET", notes = "Returns list of properties", response = GroupProperty.class, responseContainer="List")
78     @ApiResponses(value = {
79             @ApiResponse(code = 200, message = "Group Updated"),
80             @ApiResponse(code = 403, message = "Restricted operation"),
81             @ApiResponse(code = 400, message = "Invalid content / Missing content") })
82     public List<PropertyDataDefinition> getGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
83                                                            @PathParam("componentId") final String componentId,
84                                                            @PathParam("groupUniqueId") final String groupUniqueId,
85                                                            @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
86         return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
87     }
88
89     @PUT
90     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
91     @ApiOperation(value = "Updates List of properties on a group (only values)", httpMethod = "PUT", notes = "Returns updated list of properties", response = GroupProperty.class, responseContainer="List")
92     @ApiResponses(value = {
93             @ApiResponse(code = 200, message = "Group Updated"),
94             @ApiResponse(code = 403, message = "Restricted operation"),
95             @ApiResponse(code = 400, message = "Invalid content / Missing content") })
96     public List<GroupProperty> updateGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
97                                                      @PathParam("componentId") final String componentId,
98                                                      @PathParam("groupUniqueId") final String groupUniqueId,
99                                                      @ApiParam(value = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
100                                                      @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
101         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
102         return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);
103     }
104
105 }