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=========================================================
20 package org.openecomp.sdc.be.servlets;
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.inject.Inject;
35 import javax.ws.rs.Consumes;
36 import javax.ws.rs.GET;
37 import javax.ws.rs.HeaderParam;
38 import javax.ws.rs.POST;
39 import javax.ws.rs.PUT;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.PathParam;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.MediaType;
44 import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
45 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
46 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
47 import org.openecomp.sdc.be.impl.ComponentsUtils;
48 import org.openecomp.sdc.be.model.GroupProperty;
49 import org.openecomp.sdc.common.api.Constants;
50 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
51 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
52 import org.openecomp.sdc.common.log.enums.StatusCode;
53 import org.springframework.stereotype.Controller;
56 * Here new APIs for group will be written in an attempt to gradually clean BL code
58 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
60 @Tags({@Tag(name = "SDCE-2 APIs")})
61 @Servers({@Server(url = "/sdc2/rest")})
63 @Consumes(MediaType.APPLICATION_JSON)
64 @Produces(MediaType.APPLICATION_JSON)
65 public class GroupEndpoint extends BeGenericServlet {
67 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(GroupEndpoint.class.getName());
68 private final GroupBusinessLogicNew groupBusinessLogic;
71 public GroupEndpoint(ComponentsUtils componentsUtils, GroupBusinessLogicNew groupBusinessLogic) {
72 super(componentsUtils);
73 this.groupBusinessLogic = groupBusinessLogic;
77 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
78 @Operation(description = "Update group members ", method = "POST", summary = "Updates list of members and returns it", responses = {
79 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
80 @ApiResponse(responseCode = "200", description = "Group members updated"),
81 @ApiResponse(responseCode = "400", description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
82 @ApiResponse(responseCode = "403", description = "Restricted operation"),
83 @ApiResponse(responseCode = "404", description = "Component not found"), @ApiResponse(responseCode = "500", description = "Internal Error")})
84 public List<String> updateGroupMembers(@PathParam("containerComponentType") final String containerComponentType,
85 @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
86 @Parameter(description = "List of members unique ids", required = true) List<String> members,
87 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
89 .log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.STARTED, " Starting to update Group Members for component {} ",
91 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
93 .log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.COMPLETE, " Ended update Group Members for component {} ", componentId);
94 return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
98 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
99 @Operation(description = "Get List of properties on a group", method = "GET", summary = "Returns list of properties", responses = {
100 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
101 @ApiResponse(responseCode = "200", description = "Group Updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
102 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
103 public List<PropertyDataDefinition> getGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
104 @PathParam("componentId") final String componentId,
105 @PathParam("groupUniqueId") final String groupUniqueId,
106 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
107 return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
111 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
112 @Operation(description = "Updates List of properties on a group (only values)", method = "PUT", summary = "Returns updated list of properties", responses = {
113 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
114 @ApiResponse(responseCode = "200", description = "Group Updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
115 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
116 public List<GroupProperty> updateGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
117 @PathParam("componentId") final String componentId,
118 @PathParam("groupUniqueId") final String groupUniqueId,
119 @Parameter(description = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
120 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
121 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
122 return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);