Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / LockServlet.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19 package org.openecomp.sdc.be.servlets;
20
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.validation.UserValidations;
41 import org.openecomp.sdc.be.impl.ComponentsUtils;
42 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
43 import org.openecomp.sdc.be.user.Role;
44 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
45 import org.openecomp.sdc.common.log.wrappers.Logger;
46 import org.springframework.stereotype.Controller;
47
48
49 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
50 @Path("/v1/catalog")
51 @Tag(name = "SDCE-2 APIs")
52 @Server(url = "/sdc2/rest")
53 @Controller
54 public class LockServlet extends BeGenericServlet {
55
56     private static final Logger log = Logger.getLogger(LockServlet.class);
57     private final UserValidations userValidations;
58     private final IGraphLockOperation graphLockOperation;
59
60     @Inject
61     public LockServlet(final ComponentsUtils componentsUtils,
62                        final UserValidations userValidations, IGraphLockOperation graphLockOperation) {
63         super(componentsUtils);
64         this.userValidations = userValidations;
65         this.graphLockOperation = graphLockOperation;
66     }
67
68     @POST
69     @Path("/lock")
70     @Consumes(MediaType.APPLICATION_JSON)
71     @Produces(MediaType.APPLICATION_JSON)
72     @Operation(description = "Toggle disable locking", method = "POST", responses = {
73         @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))),
74         @ApiResponse(responseCode = "200", description = "Disable locking successfully updated"),
75         @ApiResponse(responseCode = "500", description = "Update disable locking failed")
76     })
77     public Response toggleDisableLocking(@Context final HttpServletRequest request, @HeaderParam("USER_ID") String userId,
78                                          @Parameter(description = "Disable Locking") boolean disable) {
79         log.info("User {} attempting to set disable locking with value {}", userId, disable);
80         userValidations.validateUserRole(userValidations.validateUserExists(userId), Arrays.asList(Role.DESIGNER, Role.ADMIN));
81         try {
82             return Response.ok().entity(graphLockOperation.disableLocking(disable)).build();
83         } catch (final Exception e) {
84             log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, LockServlet.class.getName(), "Failed to set disable locking", e);
85             return Response.serverError().build();
86         }
87     }
88 }