2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.servlets;
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;
34 import javax.ws.rs.core.MediaType;
35 import java.util.List;
38 * Here new APIs for group will be written in an attempt to gradually clean BL code
40 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
42 @Api(value = "Group Servlet")
44 @Consumes(MediaType.APPLICATION_JSON)
45 @Produces(MediaType.APPLICATION_JSON)
46 public class GroupEndpoint {
48 private final GroupBusinessLogicNew groupBusinessLogic;
51 public GroupEndpoint(GroupBusinessLogicNew groupBusinessLogic) {
52 this.groupBusinessLogic = groupBusinessLogic;
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")
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);
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);
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);