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;
35 * Created by Talio on 12/6/2016.
37 public class CandidateServiceValidator {
38 public Optional<List<ErrorMessage>> validateFileDataStructure(
39 FilesDataStructure filesDataStructure) {
40 if (Objects.isNull(filesDataStructure)) {
41 return Optional.empty();
43 if (validateAtLeaseOneModuleExist(filesDataStructure)) {
44 return Optional.of(Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, Messages
45 .NO_MODULES_IN_MANIFEST.getErrorMessage())));
48 List<ErrorMessage> errors = new ArrayList<>();
49 for (Module module : filesDataStructure.getModules()) {
50 validateModuleHaveYaml(errors, module);
51 validateNoVolEnvWithoutVol(errors, module);
53 return Optional.of(errors);
57 private boolean validateAtLeaseOneModuleExist(FilesDataStructure filesDataStructure) {
58 return CollectionUtils.isEmpty(filesDataStructure.getModules());
61 private void validateNoVolEnvWithoutVol(List<ErrorMessage> errors, Module module) {
62 if (StringUtils.isEmpty(module.getVol()) && StringUtils.isNotEmpty(module.getVolEnv())) {
63 errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder
64 .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_VOL_ENV_NO_VOL.getErrorMessage(),
69 private void validateModuleHaveYaml(List<ErrorMessage> errors, Module module) {
70 if (StringUtils.isEmpty(module.getYaml())) {
71 errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder
72 .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_NO_YAML.getErrorMessage(),