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.datatypes.error.ErrorLevel;
25 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
26 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
27 import org.openecomp.sdc.logging.types.LoggerConstants;
28 import org.openecomp.sdc.logging.types.LoggerErrorCode;
29 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
30 import org.openecomp.sdc.logging.types.LoggerServiceName;
31 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
32 import org.openecomp.sdc.validation.UploadValidationManager;
33 import org.openecomp.sdc.validation.types.ValidationFileResponse;
34 import org.openecomp.sdcrests.validation.rest.Validation;
35 import org.openecomp.sdcrests.validation.rest.mapping.MapValidationFileResponseToValidationFileResponseDto;
36 import org.openecomp.sdcrests.validation.types.ValidationFileResponseDto;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Scope;
40 import org.springframework.stereotype.Service;
42 import javax.inject.Named;
43 import javax.ws.rs.core.Response;
44 import java.io.IOException;
45 import java.io.InputStream;
48 @Service("validation")
49 @Scope(value = "prototype")
50 public class ValidationImpl implements Validation {
52 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
54 private UploadValidationManager uploadValidationManager;
57 public Response validateFile(String type, InputStream fileToValidate) {
59 mdcDataDebugMessage.debugEntryMessage(null, null);
61 MDC.put(LoggerConstants.SERVICE_NAME,
62 LoggerServiceName.Validate.toString());
63 ValidationFileResponse validationFileResponse = null;
65 validationFileResponse = uploadValidationManager.validateFile(type, fileToValidate);
66 } catch (IOException exception) {
67 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
68 LoggerTragetServiceName.VALIDATE_FILE, ErrorLevel.ERROR.name(),
69 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.VALIDATE_FILE);
70 throw new RuntimeException(exception);
73 ValidationFileResponseDto validationFileResponseDto =
74 new MapValidationFileResponseToValidationFileResponseDto()
75 .applyMapping(validationFileResponse, ValidationFileResponseDto.class);
77 mdcDataDebugMessage.debugExitMessage(null, null);
79 return Response.ok(validationFileResponseDto).build();