aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
blob: 3c1125733a8c53a595868969e62288e4f78dacb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*-
 * ============LICENSE_START=======================================================
 * policy-management
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.policy.drools.protocol.coders;

import java.util.List;

public class TopicCoderFilterConfiguration {

	/**
	 * Custom coder, contains class and static field to access parser that the controller
	 * desires to use instead of the framework provided parser
	 */
	public static abstract class CustomCoder {
		protected String className;
		protected String staticCoderField;
		
		/**
		 * create custom coder from raw string in the following format
		 * (typically embedded in a property file):
		 * 
		 * Note this is to support decoding/encoding of partial structures that are
		 * only known by the model.
		 * 
		 * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>
		 */
		public CustomCoder(String rawCustomCoder) throws IllegalArgumentException {			
			if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
				
				this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(","));
				if (this.className == null || this.className.isEmpty()) {
					throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
				}
				
				this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1);
				if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
					throw new IllegalArgumentException
						("No staticCoderField to create CustomCoder cannot be created for class " +
						 className);
				}

			}
		}
		/**
		 * @param classContainer
		 * @param staticCoderField
		 */
		public CustomCoder(String className, String staticCoderField) throws IllegalArgumentException {
			if (className == null || className.isEmpty()) {
				throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
			}
			
			if (staticCoderField == null || staticCoderField.isEmpty()) {
				throw new IllegalArgumentException
					("No staticCoderField to create CustomCoder cannot be created for class " +
					 className);
			}
			
			this.className = className;
			this.staticCoderField = staticCoderField;
		}

		/**
		 * @return the className
		 */
		public String getClassContainer() {
			return className;
		}

		/**
		 * @param className the className to set
		 */
		public void setClassContainer(String className) {
			this.className = className;
		}

		/**
		 * @return the staticCoderField
		 */
		public String getStaticCoderField() {
			return staticCoderField;
		}

		/**
		 * @param staticCoderField the staticGson to set
		 */
		public void setStaticCoderField(String staticCoderField) {
			this.staticCoderField = staticCoderField;
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("CustomCoder [className=").append(className).append(", staticCoderField=")
					.append(staticCoderField).append("]");
			return builder.toString();
		}
	}
	
	public static class CustomGsonCoder extends CustomCoder {
	
		public CustomGsonCoder(String className, String staticCoderField) {
				super(className, staticCoderField);
		}

		public CustomGsonCoder(String customGson) throws IllegalArgumentException {
			super(customGson);
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
			return builder.toString();
		}

	}
	
	public static class CustomJacksonCoder extends CustomCoder {
		
		public CustomJacksonCoder(String className, String staticCoderField) {
				super(className, staticCoderField);
		}
		
		public CustomJacksonCoder(String customJackson) throws IllegalArgumentException {
			super(customJackson);
		}
		
		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]");
			return builder.toString();
		}

	}

	/**
	 * Coder/Decoder class and Filter container.   The decoder class is potential,
	 * in order to be operational needs to be fetched from an available
	 * class loader.
	 *
	 */
	public static class PotentialCoderFilter {

		/**
		 * decoder class (pending from being able to be fetched and found 
		 * in some class loader)
		 */
		protected String codedClass;
		
		/**
		 * filters to apply to the selection of the decodedClass;
		 */
		protected JsonProtocolFilter filter;
		
		/**
		 * constructor
		 * 
		 * @param codedClass decoder class
		 * @param filter filters to apply
		 */
		public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
			this.codedClass = codedClass;
			this.filter = filter;
		}

		/**
		 * @return the decodedClass
		 */
		public String getCodedClass() {
			return codedClass;
		}

		/**
		 * @param decodedClass the decodedClass to set
		 */
		public void setCodedClass(String decodedClass) {
			this.codedClass = decodedClass;
		}

		/**
		 * @return the filter
		 */
		public JsonProtocolFilter getFilter() {
			return filter;
		}

		/**
		 * @param filter the filter to set
		 */
		public void setFilter(JsonProtocolFilter filter) {
			this.filter = filter;
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter)
					.append("]");
			return builder.toString();
		}
	}
	
	/**
	 * the source topic
	 */
	protected final String topic;
	
	/**
	 * List of decoder -> filters
	 */
	protected final List<PotentialCoderFilter> coderFilters;
	
	/**
	 * custom gson coder that this controller prefers to use instead of the framework ones
	 */
	protected CustomGsonCoder customGsonCoder;
	
	/**
	 * custom jackson coder that this controller prefers to use instead of the framework ones
	 */
	protected CustomJacksonCoder customJacksonCoder;

	/**
	 * Constructor 
	 * 
	 * @param decoderFilters list of decoders and associated filters
	 * @param topic the topic
	 */
	public TopicCoderFilterConfiguration(String topic, List<PotentialCoderFilter> decoderFilters,
                                         CustomGsonCoder customGsonCoder, 
                                         CustomJacksonCoder customJacksonCoder) {
		this.coderFilters = decoderFilters;
		this.topic = topic;
		this.customGsonCoder = customGsonCoder;
		this.customJacksonCoder = customJacksonCoder;
	}

	/**
	 * @return the topic
	 */
	public String getTopic() {
		return topic;
	}

	/**
	 * @return the decoderFilters
	 */
	public List<PotentialCoderFilter> getCoderFilters() {
		return coderFilters;
	}
	
	/**
	 * @return the customGsonCoder
	 */
	public CustomGsonCoder getCustomGsonCoder() {
		return customGsonCoder;
	}

	/**
	 * @param customGsonCoder the customGsonCoder to set
	 */
	public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
		this.customGsonCoder = customGsonCoder;
	}

	/**
	 * @return the customJacksonCoder
	 */
	public CustomJacksonCoder getCustomJacksonCoder() {
		return customJacksonCoder;
	}

	/**
	 * @param customJacksonCoder the customJacksonCoder to set
	 */
	public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) {
		this.customJacksonCoder = customJacksonCoder;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=")
				.append(coderFilters).append(", customGsonCoder=").append(customGsonCoder)
				.append(", customJacksonCoder=").append(customJacksonCoder).append("]");
		return builder.toString();
	}


}