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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdcrests.vsp.rest.controllers;
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;
34 @Controller("packageUploadManagerController")
35 public class OrchestrationTemplateCandidateUploadManagerControllerImpl implements OrchestrationTemplateCandidateUploadManagerController {
37 private final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager;
40 public OrchestrationTemplateCandidateUploadManagerControllerImpl(final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager) {
41 this.orchestrationTemplateCandidateUploadManager = orchestrationTemplateCandidateUploadManager;
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);
50 final Optional<VspUploadStatusDto> vspUploadStatus = orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user);
51 if (vspUploadStatus.isEmpty()) {
52 return Response.status(Status.NOT_FOUND).build();
55 return Response.ok(vspUploadStatus.get()).build();
59 * Builds the string representing the get API url.
61 * @param vspId the vsp id
62 * @param vspVersionId the vsp version id
63 * @return the string representing the get API url
65 public static String buildGetUrl(final String vspId, final String vspVersionId) {
66 return OrchestrationTemplateCandidateUploadManagerController.URL
67 .replace("{vspId}", vspId)
68 .replace("{versionId}", vspVersionId);