Reformat catalog-model
[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 package org.openecomp.sdc.be.model;
21
22 import java.util.List;
23 import lombok.Getter;
24 import lombok.NoArgsConstructor;
25 import lombok.Setter;
26 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
27 import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
28 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
29
30 @Getter
31 @Setter
32 @NoArgsConstructor
33 public class ComponentParametersView {
34
35     private boolean ignoreUsers = false;
36     private boolean ignoreGroups = false;
37     private boolean ignoreComponentInstances = false;
38     private boolean ignoreComponentInstancesProperties = false;
39     private boolean ignoreComponentInstancesAttributes = false;
40     private boolean ignoreProperties = false;
41     private boolean ignoreAttributes = false;
42     private boolean ignoreCapabilities = false;
43     private boolean ignoreRequirements = false;
44     private boolean ignoreCategories = false;
45     private boolean ignoreAllVersions = false;
46     private boolean ignoreAdditionalInformation = false;
47     private boolean ignoreArtifacts = false;
48     private boolean ignoreInterfaces = false;
49     private boolean ignoreInterfaceInstances = false;
50     private boolean ignoreComponentInstancesInterfaces = false;
51     private boolean ignoreDerivedFrom = false;
52     private boolean ignoreInputs = false;
53     private boolean ignoreOutputs = false;
54     private boolean ignoreComponentInstancesInputs = false;
55     private boolean ignoreComponentInstancesOutputs = false;
56     private boolean ignoreCapabiltyProperties = false;
57     private boolean ignoreServicePath = true;
58     private boolean ignorePolicies = false;
59     private boolean ignoreNodeFilterRequirements = false;
60     private boolean ignoreNodeFilter = false;
61     private boolean ignoreSubstitutionFilter = false;
62     private boolean ignoreDataType = false;
63
64     public ComponentParametersView(boolean setAllToIgnore) {
65         this();
66         if (setAllToIgnore) {
67             this.disableAll();
68         }
69     }
70
71     public ComponentParametersView(List<String> filters) {
72         this(true);
73         for (String fieldName : filters) {
74             switch (ComponentFieldsEnum.findByValue(fieldName)) {
75                 case PROPERTIES:
76                     this.setIgnoreProperties(false);
77                     break;
78                 case INPUTS:
79                     this.setIgnoreInputs(false);
80                     break;
81                 case OUTPUTS:
82                     this.setIgnoreOutputs(false);
83                     break;
84                 case USERS:
85                     this.setIgnoreUsers(false);
86                     break;
87                 case CATEGORIES:
88                     this.setIgnoreCategories(false);
89                     break;
90                 case METADATA:
91                     this.setIgnoreUsers(false);
92                     this.setIgnoreCategories(false);
93                     this.setIgnoreAllVersions(false);
94                     this.setIgnoreDerivedFrom(false);
95                     break;
96                 case GROUPS:
97                 case NON_EXCLUDED_GROUPS:
98                     this.setIgnoreGroups(false);
99                     break;
100                 case COMPONENT_INSTANCES:
101                     this.setIgnoreComponentInstances(false);
102                     this.setIgnoreCapabilities(false);
103                     this.setIgnoreRequirements(false);
104                     this.setIgnoreNodeFilter(false);
105                     this.setIgnoreSubstitutionFilter(false);
106                     this.setIgnoreCapabiltyProperties(false);
107                     this.setIgnoreInterfaces(false);
108                     this.setIgnoreComponentInstancesInterfaces(false);
109                     break;
110                 case COMPONENT_INSTANCES_PROPERTIES:
111                     this.setIgnoreComponentInstances(false); //we need this in order to get the calculate capabilities requirements
112                     this.setIgnoreComponentInstancesProperties(false);
113                     break;
114                 case CAPABILITIES:
115                     this.setIgnoreComponentInstances(false);//we need this in order to get the calculate capabilities requirements
116                     this.setIgnoreCapabilities(false);
117                     this.setIgnoreCapabiltyProperties(false);
118                     break;
119                 case REQUIREMENTS:
120                     this.setIgnoreComponentInstances(false);
121                     this.setIgnoreRequirements(false);
122                     break;
123                 case ALL_VERSIONS:
124                     this.setIgnoreAllVersions(false);
125                     break;
126                 case ADDITIONAL_INFORMATION:
127                     this.setIgnoreAdditionalInformation(false);
128                     break;
129                 case ARTIFACTS:
130                 case DEPLOYMENT_ARTIFACTS:
131                 case TOSCA_ARTIFACTS:
132                 case SERVICE_API_ARTIFACTS:
133                     this.setIgnoreArtifacts(false);
134                     break;
135                 case INTERFACES:
136                     this.setIgnoreInterfaces(false);
137                     break;
138                 case DERIVED_FROM:
139                     this.setIgnoreDerivedFrom(false);
140                     break;
141                 case ATTRIBUTES:
142                     this.setIgnoreAttributes(false);
143                     break;
144                 case COMPONENT_INSTANCES_ATTRIBUTES:
145                     this.setIgnoreComponentInstances(false);
146                     this.setIgnoreComponentInstancesAttributes(false);
147                     break;
148                 case COMPONENT_INSTANCE_INPUTS:
149                     this.setIgnoreComponentInstances(false);
150                     this.setIgnoreComponentInstancesInputs(false);
151                     break;
152                 case COMPONENT_INSTANCE_OUTPUTS:
153                     this.setIgnoreComponentInstances(false);
154                     this.setIgnoreComponentInstancesOutputs(false);
155                     break;
156                 case INSTANCE_CAPABILTY_PROPERTIES:
157                     this.setIgnoreCapabiltyProperties(false);
158                     break;
159                 case FORWARDING_PATHS:
160                     this.setIgnoreServicePath(false);
161                     break;
162                 case POLICIES:
163                 case NON_EXCLUDED_POLICIES:
164                     this.setIgnorePolicies(false);
165                     break;
166                 case NODE_FILTER:
167                     this.setIgnoreNodeFilterRequirements(false);
168                     this.setIgnoreNodeFilter(false);
169                     break;
170                 case SUBSTITUTION_FILTER:
171                     this.setIgnoreSubstitutionFilter(false);
172                     break;
173                 case COMPONENT_INSTANCES_INTERFACES:
174                     this.setIgnoreComponentInstances(false);
175                     this.setIgnoreInterfaces(false);
176                     this.setIgnoreComponentInstancesInterfaces(false);
177                     break;
178                 case DATA_TYPES:
179                     this.setIgnoreDataType(false);
180                     break;
181                 default:
182                     break;
183             }
184         }
185     }
186     ///////////////////////////////////////////////////////////////
187
188     // When adding new member, please update the filter method.
189
190     ///////////////////////////////////////////////////////////////
191     public Component filter(Component component, ComponentTypeEnum componentType) {
192         if (ignoreUsers) {
193             component.setCreatorUserId(null);
194             component.setCreatorFullName(null);
195             component.setLastUpdaterUserId(null);
196             component.setLastUpdaterFullName(null);
197         }
198         if (ignoreGroups) {
199             component.setGroups(null);
200         }
201         if (ignoreComponentInstances) {
202             component.setComponentInstances(null);
203             component.setComponentInstancesRelations(null);
204         }
205         if (ignoreComponentInstancesProperties) {
206             component.setComponentInstancesProperties(null);
207         }
208         if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
209             ((Resource) component).setProperties(null);
210         }
211         if (ignoreAttributes) {
212             component.setAttributes(null);
213         }
214         if (ignoreCapabilities) {
215             component.setCapabilities(null);
216         }
217         if (ignoreRequirements) {
218             component.setRequirements(null);
219         }
220         if (ignoreCategories) {
221             component.setCategories(null);
222         }
223         if (ignoreAllVersions) {
224             component.setAllVersions(null);
225         }
226         if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
227             ((Resource) component).setAdditionalInformation(null);
228         }
229         if (ignoreArtifacts) {
230             component.setArtifacts(null);
231             component.setSpecificComponetTypeArtifacts(null);
232             component.setDeploymentArtifacts(null);
233             component.setToscaArtifacts(null);
234         }
235         if (ignoreNodeFilterRequirements) {
236             component.setNodeFilterComponents(null);
237         }
238         if (ignoreInterfaces && ignoreInterfaceInstances && 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 }