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