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.sdc.validation.impl;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.openecomp.core.validation.api.ValidationManager;
25 import org.openecomp.core.validation.interfaces.Validator;
26 import org.openecomp.core.validation.types.GlobalValidationContext;
27 import org.openecomp.core.validation.types.MessageContainer;
28 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import org.openecomp.sdc.validation.utils.ValidationConfigurationManager;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import java.util.HashMap;
34 import java.util.List;
37 public class ValidationManagerImpl implements ValidationManager {
39 private static Logger logger = LoggerFactory.getLogger(ValidationManagerImpl.class);
40 private GlobalValidationContext globalContext;
41 private List<Validator> validators;
43 public ValidationManagerImpl() {
44 globalContext = new GlobalValidationContext();
45 validators = ValidationConfigurationManager.initValidators();
49 public void addFile(String fileName, byte[] fileContent) {
50 globalContext.addFileContext(fileName, fileContent);
54 public Map<String, List<ErrorMessage>> validate() {
55 for (Validator validator : validators) {
56 validator.validate(globalContext);
58 return convertMessageContainsToErrorMessage(globalContext.getContextMessageContainers());
61 private Map<String, List<ErrorMessage>> convertMessageContainsToErrorMessage(
62 Map<String, MessageContainer> contextMessageContainers) {
63 Map<String, List<ErrorMessage>> errors = new HashMap<>();
64 contextMessageContainers.entrySet().stream()
65 .filter(entry -> CollectionUtils.isNotEmpty(entry.getValue().getErrorMessageList()))
66 .forEach(entry -> errors.put(entry.getKey(), entry.getValue().getErrorMessageList()));