eb03ba62b44203f0e19e051465f9a4dd6281043e
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / types / ValidationResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.types;
22
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.sdc.logging.api.Logger;
26 import org.openecomp.sdc.logging.api.LoggerFactory;
27 import org.openecomp.sdc.common.errors.ErrorCode;
28 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import org.openecomp.sdc.logging.types.LoggerServiceName;
30 import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils;
31
32 import java.util.Collection;
33 import java.util.List;
34 import java.util.Map;
35
36 public class ValidationResponse {
37   protected static Logger logger = (Logger) LoggerFactory.getLogger(ValidationResponse.class);
38   private boolean valid = true;
39   private Collection<ErrorCode> vspErrors;
40   private Collection<ErrorCode> licensingDataErrors;
41   private Map<String, List<ErrorMessage>> uploadDataErrors;
42   private Map<String, List<ErrorMessage>> compilationErrors;
43   private QuestionnaireValidationResult questionnaireValidationResult;
44
45   public boolean isValid() {
46     return valid;
47   }
48
49   public Collection<ErrorCode> getVspErrors() {
50     return vspErrors;
51   }
52
53   /**
54    * Sets vsp errors.
55    *
56    * @param vspErrors         the vsp errors
57    * @param serviceName       the service name
58    * @param targetServiceName the target service name
59    */
60   public void setVspErrors(Collection<ErrorCode> vspErrors, LoggerServiceName serviceName,
61                            String targetServiceName) {
62     this.vspErrors = vspErrors;
63     if (CollectionUtils.isNotEmpty(vspErrors)) {
64       valid = false;
65     }
66
67     VendorSoftwareProductUtils.setErrorsIntoLogger(vspErrors, serviceName, targetServiceName);
68   }
69
70   public Collection<ErrorCode> getLicensingDataErrors() {
71     return licensingDataErrors;
72   }
73
74   /**
75    * Sets licensing data errors.
76    *
77    * @param licensingDataErrors the licensing data errors
78    */
79   public void setLicensingDataErrors(Collection<ErrorCode> licensingDataErrors) {
80     this.licensingDataErrors = licensingDataErrors;
81     if (CollectionUtils.isNotEmpty(licensingDataErrors)) {
82       valid = false;
83     }
84   }
85
86   public Map<String, List<ErrorMessage>> getUploadDataErrors() {
87     return uploadDataErrors;
88   }
89
90   /**
91    * Sets upload data errors.
92    *
93    * @param uploadDataErrors  the upload data errors
94    * @param serviceName       the service name
95    * @param targetServiceName the target service name
96    */
97   public void setUploadDataErrors(Map<String, List<ErrorMessage>> uploadDataErrors,
98                                   LoggerServiceName serviceName, String targetServiceName) {
99     this.uploadDataErrors = uploadDataErrors;
100     if (MapUtils.isNotEmpty(uploadDataErrors)) {
101       valid = false;
102     }
103
104     VendorSoftwareProductUtils
105         .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName);
106   }
107
108   public Map<String, List<ErrorMessage>> getCompilationErrors() {
109     return compilationErrors;
110   }
111
112   /**
113    * Sets compilation errors.
114    *
115    * @param compilationErrors the compilation errors
116    * @param serviceName       the service name
117    * @param targetServiceName the target service name
118    */
119   public void setCompilationErrors(Map<String, List<ErrorMessage>> compilationErrors,
120                                    LoggerServiceName serviceName, String targetServiceName) {
121     this.compilationErrors = compilationErrors;
122     if (MapUtils.isNotEmpty(compilationErrors)) {
123       valid = false;
124     }
125
126     VendorSoftwareProductUtils
127         .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName);
128   }
129
130   public QuestionnaireValidationResult getQuestionnaireValidationResult() {
131     return questionnaireValidationResult;
132   }
133
134   /**
135    * Sets questionnaire validation result.
136    *
137    * @param questionnaireValidationResult the questionnaire validation result
138    */
139   public void setQuestionnaireValidationResult(
140       QuestionnaireValidationResult questionnaireValidationResult) {
141     this.questionnaireValidationResult = questionnaireValidationResult;
142     if (questionnaireValidationResult != null && !questionnaireValidationResult.isValid()) {
143       valid = false;
144     }
145   }
146
147
148 }