Implement Attributes/Outputs BE (part 1)
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / ComponentParametersView.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.be.model;
22
23 import java.util.List;
24 import lombok.Getter;
25 import lombok.NoArgsConstructor;
26 import lombok.Setter;
27 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
28 import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
29 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
30
31 @Getter
32 @Setter
33 @NoArgsConstructor
34 public class ComponentParametersView {
35
36     private boolean ignoreUsers = false;
37     private boolean ignoreGroups = false;
38     private boolean ignoreComponentInstances = false;
39     private boolean ignoreComponentInstancesProperties = false;
40     private boolean ignoreComponentInstancesAttributes = false;
41     private boolean ignoreProperties = false;
42     private boolean ignoreAttributes = false;
43     private boolean ignoreCapabilities = false;
44     private boolean ignoreRequirements = false;
45     private boolean ignoreCategories = false;
46     private boolean ignoreAllVersions = false;
47     private boolean ignoreAdditionalInformation = false;
48     private boolean ignoreArtifacts = false;
49     private boolean ignoreInterfaces = false;
50     private boolean ignoreInterfaceInstances = false;
51     private boolean ignoreComponentInstancesInterfaces = false;
52     private boolean ignoreDerivedFrom = false;
53     private boolean ignoreInputs = false;
54     private boolean ignoreOutputs = false;
55     private boolean ignoreComponentInstancesInputs = false;
56     private boolean ignoreComponentInstancesOutputs = false;
57     private boolean ignoreCapabiltyProperties = false;
58     private boolean ignoreServicePath = true;
59     private boolean ignorePolicies = false;
60     private boolean ignoreNodeFilterRequirements = false;
61     private boolean ignoreNodeFilter = false;
62     private boolean ignoreSubstitutionFilter = false;
63     private boolean ignoreDataType = false;
64
65     public ComponentParametersView(boolean setAllToIgnore) {
66         this();
67         if (setAllToIgnore) {
68             this.disableAll();
69         }
70     }
71
72     public ComponentParametersView(List<String> filters) {
73         this(true);
74
75         for (String fieldName : filters) {
76             switch (ComponentFieldsEnum.findByValue(fieldName)) {
77                 case PROPERTIES:
78                     this.setIgnoreProperties(false);
79                     break;
80                 case INPUTS:
81                     this.setIgnoreInputs(false);
82                     break;
83                 case OUTPUTS:
84                     this.setIgnoreOutputs(false);
85                     break;
86                 case USERS:
87                     this.setIgnoreUsers(false);
88                     break;
89                 case CATEGORIES:
90                     this.setIgnoreCategories(false);
91                     break;
92                 case METADATA:
93                     this.setIgnoreUsers(false);
94                     this.setIgnoreCategories(false);
95                     this.setIgnoreAllVersions(false);
96                     this.setIgnoreDerivedFrom(false);
97                     break;
98                 case GROUPS:
99                 case NON_EXCLUDED_GROUPS:
100                     this.setIgnoreGroups(false);
101                     break;
102                 case COMPONENT_INSTANCES:
103                     this.setIgnoreComponentInstances(false);
104                     this.setIgnoreCapabilities(false);
105                     this.setIgnoreRequirements(false);
106                     this.setIgnoreNodeFilter(false);
107                     this.setIgnoreSubstitutionFilter(false);
108                     this.setIgnoreCapabiltyProperties(false);
109                     this.setIgnoreInterfaces(false);
110                     this.setIgnoreComponentInstancesInterfaces(false);
111                     break;
112                 case COMPONENT_INSTANCES_PROPERTIES:
113                     this.setIgnoreComponentInstances(false); //we need this in order to get the calculate capabilities requirements
114                     this.setIgnoreComponentInstancesProperties(false);
115                     break;
116                 case CAPABILITIES:
117                     this.setIgnoreComponentInstances(false);//we need this in order to get the calculate capabilities requirements
118                     this.setIgnoreCapabilities(false);
119                     this.setIgnoreCapabiltyProperties(false);
120                     break;
121                 case REQUIREMENTS:
122                     this.setIgnoreComponentInstances(false);
123                     this.setIgnoreRequirements(false);
124                     break;
125                 case ALL_VERSIONS:
126                     this.setIgnoreAllVersions(false);
127                     break;
128                 case ADDITIONAL_INFORMATION:
129                     this.setIgnoreAdditionalInformation(false);
130                     break;
131                 case ARTIFACTS:
132                 case DEPLOYMENT_ARTIFACTS:
133                 case TOSCA_ARTIFACTS:
134                 case SERVICE_API_ARTIFACTS:
135                     this.setIgnoreArtifacts(false);
136                     break;
137                 case INTERFACES:
138                     this.setIgnoreInterfaces(false);
139                     break;
140                 case DERIVED_FROM:
141                     this.setIgnoreDerivedFrom(false);
142                     break;
143                 case ATTRIBUTES:
144                     this.setIgnoreAttributes(false);
145                     break;
146                 case COMPONENT_INSTANCES_ATTRIBUTES:
147                     this.setIgnoreComponentInstances(false);
148                     this.setIgnoreComponentInstancesAttributes(false);
149                     break;
150                 case COMPONENT_INSTANCE_INPUTS:
151                     this.setIgnoreComponentInstances(false);
152                     this.setIgnoreComponentInstancesInputs(false);
153                     break;
154                 case INSTANCE_CAPABILTY_PROPERTIES:
155                     this.setIgnoreCapabiltyProperties(false);
156                     break;
157                 case FORWARDING_PATHS:
158                     this.setIgnoreServicePath(false);
159                     break;
160                 case POLICIES:
161                 case NON_EXCLUDED_POLICIES:
162                     this.setIgnorePolicies(false);
163                     break;
164                 case NODE_FILTER:
165                     this.setIgnoreNodeFilterRequirements(false);
166                     this.setIgnoreNodeFilter(false);
167                     break;
168                 case SUBSTITUTION_FILTER:
169                     this.setIgnoreSubstitutionFilter(false);
170                     break;
171                 case COMPONENT_INSTANCES_INTERFACES:
172                     this.setIgnoreComponentInstances(false);
173                     this.setIgnoreInterfaces(false);
174                     this.setIgnoreComponentInstancesInterfaces(false);
175                     break;
176                 case DATA_TYPES:
177                     this.setIgnoreDataType(false);
178                     break;
179                 default:
180                     break;
181             }
182
183         }
184     }
185
186     ///////////////////////////////////////////////////////////////
187     // When adding new member, please update the filter method.
188     ///////////////////////////////////////////////////////////////
189     public Component filter(Component component, ComponentTypeEnum componentType) {
190
191         if (ignoreUsers) {
192             component.setCreatorUserId(null);
193             component.setCreatorFullName(null);
194             component.setLastUpdaterUserId(null);
195             component.setLastUpdaterFullName(null);
196         }
197         if (ignoreGroups) {
198             component.setGroups(null);
199         }
200         if (ignoreComponentInstances) {
201             component.setComponentInstances(null);
202             component.setComponentInstancesRelations(null);
203         }
204         if (ignoreComponentInstancesProperties) {
205             component.setComponentInstancesProperties(null);
206         }
207         if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
208             ((Resource) component).setProperties(null);
209         }
210         if (ignoreAttributes) {
211             component.setAttributes(null);
212         }
213         if (ignoreCapabilities) {
214             component.setCapabilities(null);
215         }
216         if (ignoreRequirements) {
217             component.setRequirements(null);
218         }
219         if (ignoreCategories) {
220             component.setCategories(null);
221         }
222         if (ignoreAllVersions) {
223             component.setAllVersions(null);
224         }
225         if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
226             ((Resource) component).setAdditionalInformation(null);
227         }
228         if (ignoreArtifacts) {
229             component.setArtifacts(null);
230             component.setSpecificComponetTypeArtifacts(null);
231             component.setDeploymentArtifacts(null);
232             component.setToscaArtifacts(null);
233         }
234         if (ignoreNodeFilterRequirements) {
235             component.setNodeFilterComponents(null);
236         }
237         if (ignoreInterfaces && ignoreInterfaceInstances &&
238             componentType == ComponentTypeEnum.RESOURCE) {
239             component.setInterfaces(null);
240         }
241         if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
242             ((Resource) component).setDerivedFrom(null);
243         }
244         if (ignoreComponentInstancesAttributes) {
245             component.setComponentInstancesAttributes(null);
246         }
247         if (ignoreInputs) {
248             component.setInputs(null);
249         }
250         if (ignoreOutputs) {
251             component.setOutputs(null);
252         }
253         if (ignoreComponentInstancesInputs) {
254             component.setComponentInstancesInputs(null);
255         }
256         if (ignoreComponentInstancesOutputs) {
257             component.setComponentInstancesOutputs(null);
258         }
259         if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
260             ((Service) component).setForwardingPaths(null);
261         }
262         if (ignoreNodeFilter) {
263             component.setNodeFilterComponents(null);
264         }
265         if (ignoreSubstitutionFilter) {
266             component.setSubstitutionFilterComponents(null);
267         }
268         if (ignoreDataType) {
269             component.setDataTypes(null);
270         }
271         return component;
272     }
273
274     public void disableAll() {
275         ignoreUsers = true;
276         ignoreGroups = true;
277         ignorePolicies = true;
278         ignoreComponentInstances = true;
279         ignoreComponentInstancesProperties = true;
280         ignoreProperties = true;
281         ignoreAttributes = true;
282         ignoreCapabilities = true;
283         ignoreRequirements = true;
284         ignoreCategories = true;
285         ignoreAllVersions = true;
286         ignoreAdditionalInformation = true;
287         ignoreArtifacts = true;
288         ignoreInterfaces = true;
289         ignoreInterfaceInstances = true;
290         ignoreDerivedFrom = true;
291         ignoreInputs = true;
292         ignoreOutputs = true;
293         ignoreComponentInstancesAttributes = true;
294         ignoreComponentInstancesInputs = true;
295         ignoreComponentInstancesOutputs = true;
296         ignoreCapabiltyProperties = true;
297         ignoreServicePath = true;
298         ignoreNodeFilterRequirements = true;
299         ignoreNodeFilter = true;
300         ignoreSubstitutionFilter = true;
301         ignoreDataType = true;
302     }
303
304     public void setIgnoreGroups(boolean ignoreGroups) {
305         this.ignoreGroups = ignoreGroups;
306         if (!ignoreGroups) {
307             this.ignoreCapabiltyProperties = ignoreGroups;
308             this.ignoreCapabilities = ignoreGroups;
309         }
310     }
311
312     public JsonParseFlagEnum detectParseFlag() {
313         JsonParseFlagEnum parseFlag;
314         if (isIgnoreComponentInstances()) {
315             parseFlag = JsonParseFlagEnum.ParseMetadata;
316         } else {
317             parseFlag = JsonParseFlagEnum.ParseAll;
318         }
319         return parseFlag;
320     }
321
322 }