push addional code
[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 java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 public class UploadFileResponse {
30   private List<String> fileNames;
31   private Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> errors =
32       new HashMap<>();
33   private UploadFileStatus status = UploadFileStatus.Success;
34
35   /**
36    * Gets status.
37    *
38    * @return the status
39    */
40   public UploadFileStatus getStatus() {
41     return status;
42   }
43
44   /**
45    * Sets status.
46    *
47    * @param status the status
48    */
49   public void setStatus(UploadFileStatus status) {
50     this.status = status;
51   }
52
53   /**
54    * Gets file names.
55    *
56    * @return the file names
57    */
58   public List<String> getFileNames() {
59     return fileNames;
60   }
61
62   /**
63    * Sets file names.
64    *
65    * @param fileNames the file names
66    */
67   public void setFileNames(List<String> fileNames) {
68     this.fileNames = fileNames;
69   }
70
71   /**
72    * Add new file to list.
73    *
74    * @param filename the filename
75    */
76   public void addNewFileToList(String filename) {
77     this.fileNames.add(filename);
78   }
79
80   /**
81    * Remove file from list.
82    *
83    * @param toRemove the to remove
84    */
85   public void removeFileFromList(String toRemove) {
86     this.fileNames.remove(toRemove);
87   }
88
89   /**
90    * Add structure error.
91    *
92    * @param fileName     the file name
93    * @param errorMessage the error message
94    */
95   public void addStructureError(String fileName,
96                                 org.openecomp.sdc.datatypes.error.ErrorMessage errorMessage) {
97     List<org.openecomp.sdc.datatypes.error.ErrorMessage> errorList = errors.get(fileName);
98     if (errorList == null) {
99       errorList = new ArrayList<>();
100       errors.put(fileName, errorList);
101     }
102     errorList.add(errorMessage);
103     if (org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR.equals(errorMessage.getLevel())) {
104       status = UploadFileStatus.Failure;
105     }
106   }
107
108   /**
109    * Add structure errors.
110    *
111    * @param errorsByFileName the errors by file name
112    */
113   public void addStructureErrors(
114       Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> errorsByFileName) {
115     if (errorsByFileName == null) {
116       return;
117     }
118
119     errors.putAll(errorsByFileName);
120
121     if (status == UploadFileStatus.Failure) {
122       return;
123     }
124     for (Map.Entry<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> entry
125         : errorsByFileName.entrySet()) {
126       for (org.openecomp.sdc.datatypes.error.ErrorMessage errorMessage : entry.getValue()) {
127         if (errorMessage.getLevel() == org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR) {
128           status = UploadFileStatus.Failure;
129           return;
130         }
131       }
132     }
133   }
134
135   /**
136    * Gets errors.
137    *
138    * @return the errors
139    */
140   public Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> getErrors() {
141     return errors;
142   }
143 }