Onboarding upload control
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / vendor-software-products-rest / vendor-software-products-rest-services / src / main / java / org / openecomp / sdcrests / vsp / rest / controllers / OrchestrationTemplateCandidateUploadManagerControllerImpl.java
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2022 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdcrests.vsp.rest.controllers;
23
24 import java.util.Optional;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.Response.Status;
27 import org.openecomp.sdc.common.util.ValidationUtils;
28 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspUploadStatusDto;
29 import org.openecomp.sdcrests.vsp.rest.OrchestrationTemplateCandidateUploadManagerController;
30 import org.openecomp.sdcrests.vsp.rest.services.OrchestrationTemplateCandidateUploadManager;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Controller;
33
34 @Controller("packageUploadManagerController")
35 public class OrchestrationTemplateCandidateUploadManagerControllerImpl implements OrchestrationTemplateCandidateUploadManagerController {
36
37     private final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager;
38
39     @Autowired
40     public OrchestrationTemplateCandidateUploadManagerControllerImpl(final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager) {
41         this.orchestrationTemplateCandidateUploadManager = orchestrationTemplateCandidateUploadManager;
42     }
43
44     @Override
45     public Response getLatestStatus(String vspId, String versionId, String user) {
46         vspId = ValidationUtils.sanitizeInputString(vspId);
47         versionId = ValidationUtils.sanitizeInputString(versionId);
48         user = ValidationUtils.sanitizeInputString(user);
49
50         final Optional<VspUploadStatusDto> vspUploadStatus = orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user);
51         if (vspUploadStatus.isEmpty()) {
52             return Response.status(Status.NOT_FOUND).build();
53         }
54
55         return Response.ok(vspUploadStatus.get()).build();
56     }
57
58     /**
59      * Builds the string representing the get API url.
60      *
61      * @param vspId the vsp id
62      * @param vspVersionId the vsp version id
63      * @return the string representing the get API url
64      */
65     public static String buildGetUrl(final String vspId, final String vspVersionId) {
66         return OrchestrationTemplateCandidateUploadManagerController.URL
67             .replace("{vspId}", vspId)
68             .replace("{versionId}", vspVersionId);
69     }
70
71 }