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