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.vendorsoftwareproduct.services.utils;
23 import org.apache.commons.collections.CollectionUtils;
24 import org.apache.commons.lang.StringUtils;
25 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
26 import org.openecomp.sdc.common.errors.Messages;
27 import org.openecomp.sdc.datatypes.error.ErrorLevel;
28 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.List;
35 import java.util.Objects;
36 import java.util.Optional;
39 * Created by Talio on 12/6/2016.
41 public class CandidateServiceValidator {
42 public Optional<List<ErrorMessage>> validateFileDataStructure(
43 FilesDataStructure filesDataStructure) {
44 if (Objects.isNull(filesDataStructure)) {
45 return Optional.empty();
47 if (validateAtLeaseOneModuleExist(filesDataStructure)) {
48 return Optional.of(Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, Messages
49 .NO_MODULES_IN_MANIFEST.getErrorMessage())));
52 List<ErrorMessage> errors = new ArrayList<>();
53 for (Module module : filesDataStructure.getModules()) {
54 validateModuleHaveYaml(errors, module);
55 validateNoVolEnvWithoutVol(errors, module);
57 return Optional.of(errors);
61 private boolean validateAtLeaseOneModuleExist(FilesDataStructure filesDataStructure) {
62 return CollectionUtils.isEmpty(filesDataStructure.getModules());
65 private void validateNoVolEnvWithoutVol(List<ErrorMessage> errors, Module module) {
66 if (StringUtils.isEmpty(module.getVol()) && StringUtils.isNotEmpty(module.getVolEnv())) {
67 errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder
68 .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_VOL_ENV_NO_VOL.getErrorMessage(),
73 private void validateModuleHaveYaml(List<ErrorMessage> errors, Module module) {
74 if (StringUtils.isEmpty(module.getYaml())) {
75 errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder
76 .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_NO_YAML.getErrorMessage(),