2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 package org.openecomp.sdcrests.validation.rest.services;
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;
35 import javax.inject.Named;
36 import javax.ws.rs.core.Response;
37 import java.io.IOException;
38 import java.io.InputStream;
41 @Service("validation")
42 @Scope(value = "prototype")
43 public class ValidationImpl implements Validation {
45 private final UploadValidationManager uploadValidationManager;
48 public ValidationImpl(UploadValidationManager uploadValidationManager) {
49 this.uploadValidationManager = uploadValidationManager;
53 public Response validateFile(String type, InputStream fileToValidate) {
54 ValidationFileResponse validationFileResponse;
56 validationFileResponse = uploadValidationManager.validateFile(type, fileToValidate);
57 } catch (IOException exception) {
58 throw new RuntimeException(exception);
61 ValidationFileResponseDto validationFileResponseDto =
62 new MapValidationFileResponseToValidationFileResponseDto()
63 .applyMapping(validationFileResponse, ValidationFileResponseDto.class);
64 return Response.ok(validationFileResponseDto).build();