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=========================================================
21 package org.openecomp.sdcrests.validation.rest.services;
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;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.Scope;
41 import org.springframework.stereotype.Service;
43 import java.io.IOException;
44 import java.io.InputStream;
45 import javax.inject.Named;
46 import javax.ws.rs.core.Response;
49 @Service("validation")
50 @Scope(value = "prototype")
51 public class ValidationImpl implements Validation {
53 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
55 private UploadValidationManager uploadValidationManager;
58 public Response validateFile(String type, InputStream fileToValidate) {
60 mdcDataDebugMessage.debugEntryMessage(null, null);
62 MDC.put(LoggerConstants.SERVICE_NAME,
63 LoggerServiceName.Validate.toString());
64 ValidationFileResponse validationFileResponse = null;
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);
74 ValidationFileResponseDto validationFileResponseDto =
75 new MapValidationFileResponseToValidationFileResponseDto()
76 .applyMapping(validationFileResponse, ValidationFileResponseDto.class);
78 mdcDataDebugMessage.debugExitMessage(null, null);
80 return Response.ok(validationFileResponseDto).build();