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.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.Parameter;
26 import io.swagger.v3.oas.annotations.media.ArraySchema;
27 import io.swagger.v3.oas.annotations.media.Content;
28 import io.swagger.v3.oas.annotations.media.Schema;
29 import io.swagger.v3.oas.annotations.responses.ApiResponse;
30 import io.swagger.v3.oas.annotations.servers.Server;
31 import io.swagger.v3.oas.annotations.servers.Servers;
32 import io.swagger.v3.oas.annotations.tags.Tag;
33 import io.swagger.v3.oas.annotations.tags.Tags;
34 import java.util.List;
35 import javax.inject.Inject;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.HeaderParam;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.PUT;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.PathParam;
43 import javax.ws.rs.Produces;
44 import javax.ws.rs.core.MediaType;
45 import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
46 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
47 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
48 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
49 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
50 import org.openecomp.sdc.be.impl.ComponentsUtils;
51 import org.openecomp.sdc.be.model.GroupProperty;
52 import org.openecomp.sdc.be.user.UserBusinessLogic;
53 import org.openecomp.sdc.common.api.Constants;
54 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
55 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
56 import org.openecomp.sdc.common.log.enums.StatusCode;
57 import org.springframework.stereotype.Controller;
60 * Here new APIs for group will be written in an attempt to gradually clean BL code
62 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
64 @Tags({@Tag(name = "SDC Internal APIs")})
65 @Servers({@Server(url = "/sdc2/rest")})
67 @Consumes(MediaType.APPLICATION_JSON)
68 @Produces(MediaType.APPLICATION_JSON)
69 public class GroupEndpoint extends BeGenericServlet{
71 private final GroupBusinessLogicNew groupBusinessLogic;
72 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(GroupEndpoint.class.getName());
75 public GroupEndpoint(UserBusinessLogic userBusinessLogic,
76 ComponentsUtils componentsUtils, GroupBusinessLogicNew groupBusinessLogic) {
77 super(userBusinessLogic, componentsUtils);
78 this.groupBusinessLogic = groupBusinessLogic;
82 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
83 @Operation(description = "Update group members ", method = "POST",
84 summary = "Updates list of members and returns it", responses = {
85 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
86 @ApiResponse(responseCode = "200", description = "Group members updated"),
87 @ApiResponse(responseCode = "400",
88 description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
89 @ApiResponse(responseCode = "403", description = "Restricted operation"),
90 @ApiResponse(responseCode = "404", description = "Component not found"),
91 @ApiResponse(responseCode = "500", description = "Internal Error")})
92 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
93 public List<String> updateGroupMembers(@PathParam("containerComponentType") final String containerComponentType,
94 @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
95 @Parameter(description = "List of members unique ids", required = true) List<String> members,
96 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
97 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.STARTED," Starting to update Group Members for component {} " , componentId );
98 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
99 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.COMPLETE," Ended update Group Members for component {} " , componentId );
100 return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
104 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
105 @Operation(description = "Get List of properties on a group", method = "GET",
106 summary = "Returns list of properties", responses = {@ApiResponse(
107 content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
108 @ApiResponse(responseCode = "200", description = "Group Updated"),
109 @ApiResponse(responseCode = "403", description = "Restricted operation"),
110 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
111 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
112 public List<PropertyDataDefinition> getGroupProperties(
113 @PathParam("containerComponentType") final String containerComponentType,
114 @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
115 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
116 return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
120 @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
121 @Operation(description = "Updates List of properties on a group (only values)", method = "PUT",
122 summary = "Returns updated list of properties", responses = {@ApiResponse(
123 content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))),
124 @ApiResponse(responseCode = "200", description = "Group Updated"),
125 @ApiResponse(responseCode = "403", description = "Restricted operation"),
126 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
127 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
128 public List<GroupProperty> updateGroupProperties(
129 @PathParam("containerComponentType") final String containerComponentType,
130 @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
131 @Parameter(description = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
132 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
133 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
134 return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);