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