Implement Attributes/Outputs BE (part 2)
[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 COMPONENT_INSTANCE_OUTPUTS:
155                     this.setIgnoreComponentInstances(false);
156                     this.setIgnoreComponentInstancesOutputs(false);
157                     break;
158                 case INSTANCE_CAPABILTY_PROPERTIES:
159                     this.setIgnoreCapabiltyProperties(false);
160                     break;
161                 case FORWARDING_PATHS:
162                     this.setIgnoreServicePath(false);
163                     break;
164                 case POLICIES:
165                 case NON_EXCLUDED_POLICIES:
166                     this.setIgnorePolicies(false);
167                     break;
168                 case NODE_FILTER:
169                     this.setIgnoreNodeFilterRequirements(false);
170                     this.setIgnoreNodeFilter(false);
171                     break;
172                 case SUBSTITUTION_FILTER:
173                     this.setIgnoreSubstitutionFilter(false);
174                     break;
175                 case COMPONENT_INSTANCES_INTERFACES:
176                     this.setIgnoreComponentInstances(false);
177                     this.setIgnoreInterfaces(false);
178                     this.setIgnoreComponentInstancesInterfaces(false);
179                     break;
180                 case DATA_TYPES:
181                     this.setIgnoreDataType(false);
182                     break;
183                 default:
184                     break;
185             }
186
187         }
188     }
189
190     ///////////////////////////////////////////////////////////////
191     // When adding new member, please update the filter method.
192     ///////////////////////////////////////////////////////////////
193     public Component filter(Component component, ComponentTypeEnum componentType) {
194
195         if (ignoreUsers) {
196             component.setCreatorUserId(null);
197             component.setCreatorFullName(null);
198             component.setLastUpdaterUserId(null);
199             component.setLastUpdaterFullName(null);
200         }
201         if (ignoreGroups) {
202             component.setGroups(null);
203         }
204         if (ignoreComponentInstances) {
205             component.setComponentInstances(null);
206             component.setComponentInstancesRelations(null);
207         }
208         if (ignoreComponentInstancesProperties) {
209             component.setComponentInstancesProperties(null);
210         }
211         if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
212             ((Resource) component).setProperties(null);
213         }
214         if (ignoreAttributes) {
215             component.setAttributes(null);
216         }
217         if (ignoreCapabilities) {
218             component.setCapabilities(null);
219         }
220         if (ignoreRequirements) {
221             component.setRequirements(null);
222         }
223         if (ignoreCategories) {
224             component.setCategories(null);
225         }
226         if (ignoreAllVersions) {
227             component.setAllVersions(null);
228         }
229         if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
230             ((Resource) component).setAdditionalInformation(null);
231         }
232         if (ignoreArtifacts) {
233             component.setArtifacts(null);
234             component.setSpecificComponetTypeArtifacts(null);
235             component.setDeploymentArtifacts(null);
236             component.setToscaArtifacts(null);
237         }
238         if (ignoreNodeFilterRequirements) {
239             component.setNodeFilterComponents(null);
240         }
241         if (ignoreInterfaces && ignoreInterfaceInstances &&
242             componentType == ComponentTypeEnum.RESOURCE) {
243             component.setInterfaces(null);
244         }
245         if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
246             ((Resource) component).setDerivedFrom(null);
247         }
248         if (ignoreComponentInstancesAttributes) {
249             component.setComponentInstancesAttributes(null);
250         }
251         if (ignoreInputs) {
252             component.setInputs(null);
253         }
254         if (ignoreOutputs) {
255             component.setOutputs(null);
256         }
257         if (ignoreComponentInstancesInputs) {
258             component.setComponentInstancesInputs(null);
259         }
260         if (ignoreComponentInstancesOutputs) {
261             component.setComponentInstancesOutputs(null);
262         }
263         if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
264             ((Service) component).setForwardingPaths(null);
265         }
266         if (ignoreNodeFilter) {
267             component.setNodeFilterComponents(null);
268         }
269         if (ignoreSubstitutionFilter) {
270             component.setSubstitutionFilterComponents(null);
271         }
272         if (ignoreDataType) {
273             component.setDataTypes(null);
274         }
275         return component;
276     }
277
278     public void disableAll() {
279         ignoreUsers = true;
280         ignoreGroups = true;
281         ignorePolicies = true;
282         ignoreComponentInstances = true;
283         ignoreComponentInstancesProperties = true;
284         ignoreProperties = true;
285         ignoreAttributes = true;
286         ignoreCapabilities = true;
287         ignoreRequirements = true;
288         ignoreCategories = true;
289         ignoreAllVersions = true;
290         ignoreAdditionalInformation = true;
291         ignoreArtifacts = true;
292         ignoreInterfaces = true;
293         ignoreInterfaceInstances = true;
294         ignoreDerivedFrom = true;
295         ignoreInputs = true;
296         ignoreOutputs = true;
297         ignoreComponentInstancesAttributes = true;
298         ignoreComponentInstancesInputs = true;
299         ignoreComponentInstancesOutputs = true;
300         ignoreCapabiltyProperties = true;
301         ignoreServicePath = true;
302         ignoreNodeFilterRequirements = true;
303         ignoreNodeFilter = true;
304         ignoreSubstitutionFilter = true;
305         ignoreDataType = true;
306     }
307
308     public void setIgnoreGroups(boolean ignoreGroups) {
309         this.ignoreGroups = ignoreGroups;
310         if (!ignoreGroups) {
311             this.ignoreCapabiltyProperties = ignoreGroups;
312             this.ignoreCapabilities = ignoreGroups;
313         }
314     }
315
316     public JsonParseFlagEnum detectParseFlag() {
317         JsonParseFlagEnum parseFlag;
318         if (isIgnoreComponentInstances()) {
319             parseFlag = JsonParseFlagEnum.ParseMetadata;
320         } else {
321             parseFlag = JsonParseFlagEnum.ParseAll;
322         }
323         return parseFlag;
324     }
325
326 }