2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
19 package org.openecomp.sdc.be.servlets;
21 import com.jcabi.aspects.Loggable;
22 import io.swagger.v3.oas.annotations.Operation;
23 import io.swagger.v3.oas.annotations.Parameter;
24 import io.swagger.v3.oas.annotations.media.Content;
25 import io.swagger.v3.oas.annotations.media.Schema;
26 import io.swagger.v3.oas.annotations.responses.ApiResponse;
27 import io.swagger.v3.oas.annotations.servers.Server;
28 import io.swagger.v3.oas.annotations.tags.Tag;
29 import java.util.Arrays;
30 import javax.inject.Inject;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.ws.rs.Consumes;
33 import javax.ws.rs.HeaderParam;
34 import javax.ws.rs.POST;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.Produces;
37 import javax.ws.rs.core.Context;
38 import javax.ws.rs.core.MediaType;
39 import javax.ws.rs.core.Response;
40 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
41 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
42 import org.openecomp.sdc.be.components.validation.UserValidations;
43 import org.openecomp.sdc.be.impl.ComponentsUtils;
44 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
45 import org.openecomp.sdc.be.user.Role;
46 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
47 import org.openecomp.sdc.common.log.wrappers.Logger;
48 import org.springframework.stereotype.Controller;
51 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
53 @Tag(name = "SDCE-2 APIs")
54 @Server(url = "/sdc2/rest")
56 public class LockServlet extends BeGenericServlet {
58 private static final Logger log = Logger.getLogger(LockServlet.class);
59 private final UserValidations userValidations;
60 private final IGraphLockOperation graphLockOperation;
63 public LockServlet(final ComponentsUtils componentsUtils,
64 final UserValidations userValidations, IGraphLockOperation graphLockOperation) {
65 super(componentsUtils);
66 this.userValidations = userValidations;
67 this.graphLockOperation = graphLockOperation;
72 @Consumes(MediaType.APPLICATION_JSON)
73 @Produces(MediaType.APPLICATION_JSON)
74 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
75 @Operation(description = "Toggle disable locking", method = "POST", responses = {
76 @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))),
77 @ApiResponse(responseCode = "200", description = "Disable locking successfully updated"),
78 @ApiResponse(responseCode = "500", description = "Update disable locking failed")
80 public Response toggleDisableLocking(@Context final HttpServletRequest request, @HeaderParam("USER_ID") String userId,
81 @Parameter(description = "Disable Locking") boolean disable) {
82 log.info("User {} attempting to set disable locking with value {}", userId, disable);
83 userValidations.validateUserRole(userValidations.validateUserExists(userId), Arrays.asList(Role.DESIGNER, Role.ADMIN));
85 return Response.ok().entity(graphLockOperation.disableLocking(disable)).build();
86 } catch (final Exception e) {
87 log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, LockServlet.class.getName(), "Failed to set disable locking", e);
88 return Response.serverError().build();