Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / DistributionServiceServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import fj.data.Either;
24 import io.swagger.v3.oas.annotations.Operation;
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 javax.inject.Inject;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.ws.rs.Consumes;
36 import javax.ws.rs.GET;
37 import javax.ws.rs.HeaderParam;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.PathParam;
40 import javax.ws.rs.Produces;
41 import javax.ws.rs.core.Context;
42 import javax.ws.rs.core.MediaType;
43 import javax.ws.rs.core.Response;
44 import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
45 import org.openecomp.sdc.be.config.BeEcompErrorManager;
46 import org.openecomp.sdc.be.dao.api.ActionStatus;
47 import org.openecomp.sdc.be.impl.ComponentsUtils;
48 import org.openecomp.sdc.be.info.DistributionStatusListResponse;
49 import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
50 import org.openecomp.sdc.common.api.Constants;
51 import org.openecomp.sdc.common.log.wrappers.Logger;
52 import org.openecomp.sdc.exception.ResponseFormat;
53 import org.springframework.stereotype.Controller;
54
55 /**
56  * Root resource (exposed at "/" path)
57  */
58 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
59 @Path("/v1/catalog")
60 @Tags({@Tag(name = "SDCE-5 APIs")})
61 @Servers({@Server(url = "/sdc2/rest")})
62 @Controller
63 public class DistributionServiceServlet extends BeGenericServlet {
64
65     private static final Logger log = Logger.getLogger(DistributionServiceServlet.class);
66     private DistributionMonitoringBusinessLogic distributionMonitoringLogic;
67
68     @Inject
69     public DistributionServiceServlet(ComponentsUtils componentsUtils,
70                                       DistributionMonitoringBusinessLogic distributionMonitoringLogic) {
71         super(componentsUtils);
72         this.distributionMonitoringLogic = distributionMonitoringLogic;
73     }
74
75     @GET
76     @Path("/services/{serviceUUID}/distribution")
77     @Consumes(MediaType.APPLICATION_JSON)
78     @Produces(MediaType.APPLICATION_JSON)
79     @Operation(description = "Retrieve Distributions", method = "GET", summary = "Returns list  bases on the  information extracted from  Auditing Records according to service uuid", responses = {
80         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))),
81         @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
82         @ApiResponse(responseCode = "404", description = "Service not found")})
83     public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID, @Context final HttpServletRequest request,
84                                    @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
85         String url = request.getMethod() + " " + request.getRequestURI();
86         log.debug("Start handle request of {}", url);
87         try {
88             Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic
89                 .getListOfDistributionServiceStatus(serviceUUID, userId);
90             if (actionResponse.isRight()) {
91                 return buildErrorResponse(actionResponse.right().value());
92             } else {
93                 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
94             }
95         } catch (Exception e) {
96             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service");
97             log.debug("failed to get service distribution statuses", e);
98             throw e;
99         }
100     }
101
102     @GET
103     @Path("/services/distribution/{did}")
104     @Consumes(MediaType.APPLICATION_JSON)
105     @Produces(MediaType.APPLICATION_JSON)
106     @Operation(description = "Retrieve Distributions", method = "GET", summary = "Return  the  list  of  distribution status objects", responses = {
107         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))),
108         @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
109         @ApiResponse(responseCode = "404", description = "Status not found")})
110     public Response getListOfDistributionStatuses(@PathParam("did") final String did, @Context final HttpServletRequest request,
111                                                   @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
112         String url = request.getMethod() + " " + request.getRequestURI();
113         log.debug("Start handle request of {}", url);
114         try {
115             Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic
116                 .getListOfDistributionStatus(did, userId);
117             if (actionResponse.isRight()) {
118                 ResponseFormat responseFormat = actionResponse.right().value();
119                 log.debug("failed to fount statuses for did {} {}", did, responseFormat);
120                 return buildErrorResponse(responseFormat);
121             } else {
122                 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
123                 log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value());
124                 return buildOkResponse(responseFormat, actionResponse.left().value());
125             }
126         } catch (Exception e) {
127             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status");
128             log.debug("failed to get distribution status ", e);
129             throw e;
130         }
131     }
132 }