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