1ece6f75f879d77bd133c272ebf4e3601b47e18c
[sdc.git] /
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  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdcrests.validation.rest.services;
24
25
26 import org.openecomp.sdc.validation.UploadValidationManager;
27 import org.openecomp.sdc.validation.types.ValidationFileResponse;
28 import org.openecomp.sdcrests.validation.rest.Validation;
29 import org.openecomp.sdcrests.validation.rest.mapping.MapValidationFileResponseToValidationFileResponseDto;
30 import org.openecomp.sdcrests.validation.types.ValidationFileResponseDto;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.annotation.Scope;
33 import org.springframework.stereotype.Service;
34
35 import javax.inject.Named;
36 import javax.ws.rs.core.Response;
37 import java.io.IOException;
38 import java.io.InputStream;
39
40 @Named
41 @Service("validation")
42 @Scope(value = "prototype")
43 public class ValidationImpl implements Validation {
44
45   private final UploadValidationManager uploadValidationManager;
46
47   @Autowired
48   public ValidationImpl(UploadValidationManager uploadValidationManager) {
49     this.uploadValidationManager = uploadValidationManager;
50   }
51
52   @Override
53   public Response validateFile(String type, InputStream fileToValidate) {
54     ValidationFileResponse validationFileResponse;
55     try {
56       validationFileResponse = uploadValidationManager.validateFile(type, fileToValidate);
57     } catch (IOException exception) {
58       throw new RuntimeException(exception);
59     }
60
61     ValidationFileResponseDto validationFileResponseDto =
62         new MapValidationFileResponseToValidationFileResponseDto()
63             .applyMapping(validationFileResponse, ValidationFileResponseDto.class);
64     return Response.ok(validationFileResponseDto).build();
65   }
66
67
68 }