[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / types / UploadFileResponse.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
24 import org.openecomp.sdc.datatypes.error.ErrorLevel;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 /**
33  * Created by TALIO on 4/27/2016.
34  */
35 public class UploadFileResponse {
36   private Map<String, List<ErrorMessage>> errors = new HashMap<>();
37   private UploadFileStatus status = UploadFileStatus.Success;
38
39   public UploadFileStatus getStatus() {
40     return status;
41   }
42
43   public void setStatus(UploadFileStatus status) {
44     this.status = status;
45   }
46
47   /**
48    * Add structure error.
49    *
50    * @param fileName     the file name
51    * @param errorMessage the error message
52    */
53   public void addStructureError(String fileName, ErrorMessage errorMessage) {
54     List<ErrorMessage> errorList = errors.get(fileName);
55     if (errorList == null) {
56       errorList = new ArrayList<>();
57       errors.put(fileName, errorList);
58     }
59     errorList.add(errorMessage);
60     if (ErrorLevel.ERROR.equals(errorMessage.getLevel())) {
61       status = UploadFileStatus.Failure;
62     }
63   }
64
65   /**
66    * Add structure errors.
67    *
68    * @param errorsByFileName the errors by file name
69    */
70   public void addStructureErrors(Map<String, List<ErrorMessage>> errorsByFileName) {
71     if (errorsByFileName == null) {
72       return;
73     }
74
75     errors.putAll(errorsByFileName);
76
77     if (status == UploadFileStatus.Failure) {
78       return;
79     }
80     for (Map.Entry<String, List<ErrorMessage>> entry : errorsByFileName.entrySet()) {
81       for (ErrorMessage errorMessage : entry.getValue()) {
82         if (errorMessage.getLevel() == ErrorLevel.ERROR) {
83           status = UploadFileStatus.Failure;
84           return;
85         }
86       }
87     }
88   }
89
90   public Map<String, List<ErrorMessage>> getErrors() {
91     return errors;
92   }
93 }