09e7a40ec53425e9f380efc91fd289a6d6025cc6
[sdc.git] /
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.common.errors.ErrorCode;
26 import org.openecomp.sdc.datatypes.error.ErrorMessage;
27 import org.openecomp.sdc.logging.api.Logger;
28 import org.openecomp.sdc.logging.api.LoggerFactory;
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
71   public Collection<ErrorCode> getLicensingDataErrors() {
72     return licensingDataErrors;
73   }
74
75   /**
76    * Sets licensing data errors.
77    *
78    * @param licensingDataErrors the licensing data errors
79    */
80   public void setLicensingDataErrors(Collection<ErrorCode> licensingDataErrors) {
81     this.licensingDataErrors = licensingDataErrors;
82     if (CollectionUtils.isNotEmpty(licensingDataErrors)) {
83       valid = false;
84     }
85   }
86
87   public Map<String, List<ErrorMessage>> getUploadDataErrors() {
88     return uploadDataErrors;
89   }
90
91   /**
92    * Sets upload data errors.
93    *
94    * @param uploadDataErrors  the upload data errors
95    * @param serviceName       the service name
96    * @param targetServiceName the target service name
97    */
98   public void setUploadDataErrors(Map<String, List<ErrorMessage>> uploadDataErrors,
99                                   LoggerServiceName serviceName, String targetServiceName) {
100     this.uploadDataErrors = uploadDataErrors;
101     if (MapUtils.isNotEmpty(uploadDataErrors)) {
102       valid = false;
103     }
104
105     VendorSoftwareProductUtils
106             .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName);
107   }
108
109   public Map<String, List<ErrorMessage>> getCompilationErrors() {
110     return compilationErrors;
111   }
112
113   /**
114    * Sets compilation errors.
115    *
116    * @param compilationErrors the compilation errors
117    * @param serviceName       the service name
118    * @param targetServiceName the target service name
119    */
120   public void setCompilationErrors(Map<String, List<ErrorMessage>> compilationErrors,
121                                    LoggerServiceName serviceName, String targetServiceName) {
122     this.compilationErrors = compilationErrors;
123     if (MapUtils.isNotEmpty(compilationErrors)) {
124       valid = false;
125     }
126
127     VendorSoftwareProductUtils
128             .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName);
129   }
130
131   public QuestionnaireValidationResult getQuestionnaireValidationResult() {
132     return questionnaireValidationResult;
133   }
134
135   /**
136    * Sets questionnaire validation result.
137    *
138    * @param questionnaireValidationResult the questionnaire validation result
139    */
140   public void setQuestionnaireValidationResult(
141           QuestionnaireValidationResult questionnaireValidationResult) {
142     this.questionnaireValidationResult = questionnaireValidationResult;
143     if (questionnaireValidationResult != null && !questionnaireValidationResult.isValid()) {
144       valid = false;
145     }
146   }
147 }