re base code
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / GroupEndpoint.java
1 package org.openecomp.sdc.be.servlets;
2
3 import com.jcabi.aspects.Loggable;
4 import io.swagger.annotations.*;
5 import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
6 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
7 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
8 import org.openecomp.sdc.be.model.GroupProperty;
9 import org.openecomp.sdc.common.api.Constants;
10 import org.springframework.stereotype.Controller;
11
12 import javax.ws.rs.*;
13 import javax.ws.rs.core.MediaType;
14 import java.util.List;
15
16 /**
17  * Here new APIs for group will be written in an attempt to gradually clean BL code
18  */
19 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
20 @Path("/v1/catalog")
21 @Api(value = "Group Servlet")
22 @Controller
23 @Consumes(MediaType.APPLICATION_JSON)
24 @Produces(MediaType.APPLICATION_JSON)
25 public class GroupEndpoint {
26
27     private final GroupBusinessLogicNew groupBusinessLogic;
28
29     public GroupEndpoint(GroupBusinessLogicNew groupBusinessLogic) {
30         this.groupBusinessLogic = groupBusinessLogic;
31     }
32
33     @POST
34     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
35     @ApiOperation(value = "Update group members ", httpMethod = "POST", notes = "Updates list of members and returns it", response = String.class, responseContainer = "List")
36     @ApiResponses(value = {
37             @ApiResponse(code = 200, message = "Group members updated"),
38             @ApiResponse(code = 400, message = "field name invalid type/length, characters;  mandatory field is absent, already exists (name)"),
39             @ApiResponse(code = 403, message = "Restricted operation"),
40             @ApiResponse(code = 404, message = "Component not found"),
41             @ApiResponse(code = 500, message = "Internal Error")
42     })
43     public List<String> updateGroupMembers(
44             @PathParam("containerComponentType") final String containerComponentType,
45             @PathParam("componentId") final String componentId,
46             @PathParam("groupUniqueId") final String groupUniqueId,
47             @ApiParam(value = "List of members unique ids", required = true) List<String> members,
48             @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
49         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
50         return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
51     }
52
53     @GET
54     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
55     @ApiOperation(value = "Get List of properties on a group", httpMethod = "GET", notes = "Returns list of properties", response = GroupProperty.class, responseContainer="List")
56     @ApiResponses(value = {
57             @ApiResponse(code = 200, message = "Group Updated"),
58             @ApiResponse(code = 403, message = "Restricted operation"),
59             @ApiResponse(code = 400, message = "Invalid content / Missing content") })
60     public List<PropertyDataDefinition> getGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
61                                                            @PathParam("componentId") final String componentId,
62                                                            @PathParam("groupUniqueId") final String groupUniqueId,
63                                                            @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
64         return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
65     }
66
67     @PUT
68     @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
69     @ApiOperation(value = "Updates List of properties on a group (only values)", httpMethod = "PUT", notes = "Returns updated list of properties", response = GroupProperty.class, responseContainer="List")
70     @ApiResponses(value = {
71             @ApiResponse(code = 200, message = "Group Updated"),
72             @ApiResponse(code = 403, message = "Restricted operation"),
73             @ApiResponse(code = 400, message = "Invalid content / Missing content") })
74     public List<GroupProperty> updateGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
75                                                      @PathParam("componentId") final String componentId,
76                                                      @PathParam("groupUniqueId") final String groupUniqueId,
77                                                      @ApiParam(value = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
78                                                      @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
79         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
80         return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);
81     }
82
83 }