31bdf21884a0862f5f04ccbcfca9a4116e18d073
[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
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
26 import org.openecomp.sdc.datatypes.error.ErrorLevel;
27 import org.openecomp.sdc.datatypes.error.ErrorMessage;
28
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 /**
35  * Created by TALIO on 4/27/2016.
36  */
37 public class UploadFileResponse {
38   private Map<String, List<ErrorMessage>> errors = new HashMap<>();
39   private UploadFileStatus status = UploadFileStatus.Success;
40   private OnboardingTypesEnum onboardingType;
41   private String networkPackageName;
42
43   public UploadFileStatus getStatus() {
44     return status;
45   }
46
47   public void setStatus(UploadFileStatus status) {
48     this.status = status;
49   }
50
51   public OnboardingTypesEnum getOnboardingType() {
52     return onboardingType;
53   }
54
55   public void setOnboardingType(OnboardingTypesEnum onboardingTypesEnum) {
56     this.onboardingType = onboardingTypesEnum;
57   }
58
59   public String getNetworkPackageName() {
60     return networkPackageName;
61   }
62
63   public void setNetworkPackageName(String networkPackageName) {
64     this.networkPackageName = networkPackageName;
65   }
66
67   /**
68    * Add structure error.
69    *
70    * @param fileName     the file name
71    * @param errorMessage the error message
72    */
73   public void addStructureError(String fileName, ErrorMessage errorMessage) {
74     List<ErrorMessage> errorList = errors.get(fileName);
75     if (errorList == null) {
76       errorList = new ArrayList<>();
77       errors.put(fileName, errorList);
78     }
79     errorList.add(errorMessage);
80     if (ErrorLevel.ERROR.equals(errorMessage.getLevel())) {
81       status = UploadFileStatus.Failure;
82     }
83   }
84
85   /**
86    * Add structure errors.
87    *
88    * @param errorsByFileName the errors by file name
89    */
90   public void addStructureErrors(Map<String, List<ErrorMessage>> errorsByFileName) {
91     if (errorsByFileName == null) {
92       return;
93     }
94
95     errors.putAll(errorsByFileName);
96
97     if (status == UploadFileStatus.Failure) {
98       return;
99     }
100     for (Map.Entry<String, List<ErrorMessage>> entry : errorsByFileName.entrySet()) {
101       for (ErrorMessage errorMessage : entry.getValue()) {
102         if (errorMessage.getLevel() == ErrorLevel.ERROR) {
103           status = UploadFileStatus.Failure;
104           return;
105         }
106       }
107     }
108   }
109
110   public Map<String, List<ErrorMessage>> getErrors() {
111     return errors;
112   }
113
114   public boolean hasErrors() {
115     return !MapUtils.isEmpty(errors);
116   }
117 }