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.components.impl.aaf.AafPermission;
46 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
47 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
48 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
49 import org.openecomp.sdc.be.impl.ComponentsUtils;
50 import org.openecomp.sdc.be.model.GroupProperty;
51 import org.openecomp.sdc.common.api.Constants;
52 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
53 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
54 import org.openecomp.sdc.common.log.enums.StatusCode;
55 import org.springframework.stereotype.Controller;
58 * Here new APIs for group will be written in an attempt to gradually clean BL code
60 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
62 @Tags({@Tag(name = "SDCE-2 APIs")})
63 @Servers({@Server(url = "/sdc2/rest")})
65 @Consumes(MediaType.APPLICATION_JSON)
66 @Produces(MediaType.APPLICATION_JSON)
67 public class GroupEndpoint extends BeGenericServlet {
69 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(GroupEndpoint.class.getName());
70 private final GroupBusinessLogicNew groupBusinessLogic;
73 public GroupEndpoint(ComponentsUtils componentsUtils, GroupBusinessLogicNew groupBusinessLogic) {
74 super(componentsUtils);
75 this.groupBusinessLogic = groupBusinessLogic;
79 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
80 @Operation(description = "Update group members ", method = "POST", summary = "Updates list of members and returns it", responses = {
81 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
82 @ApiResponse(responseCode = "200", description = "Group members updated"),
83 @ApiResponse(responseCode = "400", description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
84 @ApiResponse(responseCode = "403", description = "Restricted operation"),
85 @ApiResponse(responseCode = "404", description = "Component not found"), @ApiResponse(responseCode = "500", description = "Internal Error")})
86 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
87 public List<String> updateGroupMembers(@PathParam("containerComponentType") final String containerComponentType,
88 @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
89 @Parameter(description = "List of members unique ids", required = true) List<String> members,
90 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
92 .log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.STARTED, " Starting to update Group Members for component {} ",
94 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
96 .log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.COMPLETE, " Ended update Group Members for component {} ", componentId);
97 return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
101 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
102 @Operation(description = "Get List of properties on a group", method = "GET", summary = "Returns list of properties", responses = {
103 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
104 @ApiResponse(responseCode = "200", description = "Group Updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
105 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
106 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
107 public List<PropertyDataDefinition> getGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
108 @PathParam("componentId") final String componentId,
109 @PathParam("groupUniqueId") final String groupUniqueId,
110 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
111 return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
115 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
116 @Operation(description = "Updates List of properties on a group (only values)", method = "PUT", summary = "Returns updated list of properties", responses = {
117 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
118 @ApiResponse(responseCode = "200", description = "Group Updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
119 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
120 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
121 public List<GroupProperty> updateGroupProperties(@PathParam("containerComponentType") final String containerComponentType,
122 @PathParam("componentId") final String componentId,
123 @PathParam("groupUniqueId") final String groupUniqueId,
124 @Parameter(description = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
125 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
126 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
127 return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);