[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / validation-rest / validation-rest-services / src / main / java / org / openecomp / sdcrests / validation / rest / services / ValidationImpl.java
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.common.utils.CommonUtil;
25 import org.openecomp.sdc.datatypes.error.ErrorLevel;
26 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
27 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
28 import org.openecomp.sdc.logging.types.LoggerConstants;
29 import org.openecomp.sdc.logging.types.LoggerErrorCode;
30 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
31 import org.openecomp.sdc.logging.types.LoggerServiceName;
32 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
33 import org.openecomp.sdc.validation.UploadValidationManager;
34 import org.openecomp.sdc.validation.types.ValidationFileResponse;
35 import org.openecomp.sdcrests.validation.rest.Validation;
36 import org.openecomp.sdcrests.validation.rest.mapping.MapValidationFileResponseToValidationFileResponseDto;
37 import org.openecomp.sdcrests.validation.types.ValidationFileResponseDto;
38 import org.slf4j.MDC;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.Scope;
41 import org.springframework.stereotype.Service;
42
43 import java.io.IOException;
44 import java.io.InputStream;
45 import javax.inject.Named;
46 import javax.ws.rs.core.Response;
47
48 @Named
49 @Service("validation")
50 @Scope(value = "prototype")
51 public class ValidationImpl implements Validation {
52
53   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
54   @Autowired
55   private UploadValidationManager uploadValidationManager;
56
57   @Override
58   public Response validateFile(String type, InputStream fileToValidate) {
59
60     mdcDataDebugMessage.debugEntryMessage(null, null);
61
62     MDC.put(LoggerConstants.SERVICE_NAME,
63         LoggerServiceName.Validate.toString());
64     ValidationFileResponse validationFileResponse = null;
65     try {
66       validationFileResponse = uploadValidationManager.validateFile(type, fileToValidate);
67     } catch (IOException exception) {
68       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
69           LoggerTragetServiceName.VALIDATE_FILE, ErrorLevel.ERROR.name(),
70           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.VALIDATE_FILE);
71       throw new RuntimeException(exception);
72     }
73
74     ValidationFileResponseDto validationFileResponseDto =
75         new MapValidationFileResponseToValidationFileResponseDto()
76             .applyMapping(validationFileResponse, ValidationFileResponseDto.class);
77
78     mdcDataDebugMessage.debugExitMessage(null, null);
79
80     return Response.ok(validationFileResponseDto).build();
81   }
82
83
84 }