aboutsummaryrefslogtreecommitdiffstats
path: root/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceType.java
blob: f6f26ba3929376bb93556c03d812bde054477b20 (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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package org.onap.ccsdk.dashboard.model.inventory;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class ServiceType {

	/** Owner of the ServiceType */
	private final String owner;

	/** Name of the ServiceType */
	private final String typeName;

	/** Version number for this ServiceType */
	private final Integer typeVersion;

	/** String representation of a Cloudify blueprint with unbound variables */
	private final String blueprintTemplate;

	/** controller application name */
	private final String application;
	/** onboarding component name */
	private final String component;
	/** 
	 * List of service ids used to associate with this ServiceType.
	 * ServiceTypes with this property as null or empty means they apply for every service id.
	 */
	private final Collection<String> serviceIds;
	
	/** Collection of vnfTypes associated with this ServiceType */
	private final Collection<String> vnfTypes;

	/**
	 * List of service locations used to associate with this ServiceType.
	 * ServiceTypes with this property as null or empty means they apply for every service location.
	 */
	private final Collection<String> serviceLocations;

	/** 
	 * Id of service this ServiceType is associated with.
	 * Value source is from ASDC's notification event's field 'serviceInvariantUUID'.
	 */
	private final Optional<String> asdcServiceId;

	/**
	 * Id of vf/vnf instance this ServiceType is associated with.
	 * Value source is from ASDC's notification event's field 'resourceInvariantUUID'.
	 */
	private final Optional<String> asdcResourceId;

	/** URL to the ASDC service model */
	private final Optional<String> asdcServiceURL;

	/** Unique identifier for this ServiceType */
	private final Optional<String> typeId;

	/** Link to the ServiceType */
	private final Optional<Link> selfLink;

	/** Creation date of the ServiceType */
	private final Optional<String> created;

	/** Deactivated timestamp for this ServiceType */
	private final Optional<String> deactivated;

	/** Map that stores the inputs for a Blueprint */
	private final Map<String, BlueprintInput> blueprintInputs;

	/** Description of a blueprint */
	private final String blueprintDescription;

	/** internal role based setting */
	private Optional<Boolean> canDeploy;
	
	public static class Builder {
		private final String blueprintTemplate;
		private final String owner;
		private final String typeName;
		private final Integer typeVersion;
		private final String application;
		private final String component;

		private Optional<String> asdcResourceId = Optional.empty();
		private Optional<String> asdcServiceId = Optional.empty();
		private Optional<String> asdcServiceURL = Optional.empty();
		private Optional<String> created = Optional.empty();
		private Optional<String> deactivated = Optional.empty();
		private Optional<Link> selfLink = Optional.empty();
		private Optional<String> typeId = Optional.empty();
		private Collection<String> serviceIds = new LinkedList<String> ();
		private Collection<String> serviceLocations = new LinkedList<String> ();
		private Collection<String> vnfTypes = new LinkedList<String> ();
		private Map<String, BlueprintInput> blueprintInputs = new HashMap<String, BlueprintInput> ();
		private final String blueprintDescription;
		private Optional<Boolean> canDeploy = Optional.of(true);

		public Builder(String owner, String typeName, Integer typeVersion, String blueprintTemplate, String blueprintDescription, String application, String component) {
			this.owner = owner;
			this.typeName = typeName;
			this.typeVersion = typeVersion;
			this.blueprintTemplate = blueprintTemplate;
			this.blueprintDescription = blueprintDescription;
			this.application = application;
			this.component = component;
		}

		public Builder(ServiceType clone) {
			this.asdcResourceId = clone.getAsdcResourceId();
			this.asdcServiceId = clone.getAsdcServiceId();
			this.asdcServiceURL = clone.getAsdcServiceURL();
			this.blueprintTemplate = clone.getBlueprintTemplate();
			this.created = clone.getCreated();
			this.deactivated = clone.getDeactivated();
			this.owner = clone.getOwner();
			this.selfLink = clone.getSelfLink();
			this.serviceIds = clone.getServiceIds();
			this.serviceLocations = clone.getServiceLocations();
			this.typeId = clone.getTypeId();
			this.typeName = clone.getTypeName();
			this.typeVersion = clone.getTypeVersion();
			this.vnfTypes = clone.getVnfTypes();
			this.blueprintInputs = clone.getBlueprintInputs();
			this.blueprintDescription = clone.getBlueprintDescription();
			this.canDeploy = clone.getCanDeploy();
			this.application = clone.getApplication();
			this.component = clone.getComponent();
		}

		public Builder typeId(String typeId) {
			this.typeId = Optional.of(typeId);
			return this;
		}

		public ServiceType build() {
			return new ServiceType(this);
		}
	}

	private ServiceType(Builder builder) {
		this.owner = builder.owner;
		this.typeName = builder.typeName;
		this.typeVersion = builder.typeVersion;
		this.blueprintTemplate = builder.blueprintTemplate;
		this.application = builder.application;
		this.component = builder.component;
		this.serviceIds = builder.serviceIds;
		this.vnfTypes = builder.vnfTypes;
		this.serviceLocations = builder.serviceLocations;

		this.asdcServiceId = builder.asdcServiceId;
		this.asdcResourceId = builder.asdcResourceId;
		this.asdcServiceURL = builder.asdcServiceURL;
		this.typeId = builder.typeId;
		this.selfLink = builder.selfLink;
		this.created = builder.created;
		this.deactivated = builder.deactivated;
		this.blueprintInputs = builder.blueprintInputs;
		this.blueprintDescription = builder.blueprintDescription;
		this.canDeploy = builder.canDeploy;
	}

	@JsonCreator
	public ServiceType(@JsonProperty("owner") String owner, 
			@JsonProperty("typeName") String typeName, 
			@JsonProperty("typeVersion") Integer typeVersion, 
			@JsonProperty("blueprintTemplate") String blueprintTemplate, 
			@JsonProperty("application") String application,
			@JsonProperty("component") String component,
			@JsonProperty("serviceIds") Collection<String> serviceIds, 
			@JsonProperty("vnfTypes") Collection<String> vnfTypes, 
			@JsonProperty("serviceLocations") Collection<String> serviceLocations, 
			@JsonProperty("asdcServiceId") String asdcServiceId, 
			@JsonProperty("asdcResourceId") String asdcResourceId, 
			@JsonProperty("asdcServiceURL") String asdcServiceURL, 
			@JsonProperty("typeId") String typeId, 
			@JsonProperty("selfLink") Link selfLink, 
			@JsonProperty("created") String created, 
			@JsonProperty("deactivated") String deactivated,
			@JsonProperty("canDeploy") Boolean canDeploy) {

		if (owner == null) throw new IllegalArgumentException("owner cannot be null");
		if (typeName == null) throw new IllegalArgumentException("typeName cannot be null");
		if (typeVersion == null) throw new IllegalArgumentException("typeVersion cannot be null");
		if (blueprintTemplate == null) throw new IllegalArgumentException("blueprintTemplate cannot be null");

		this.owner = owner;
		this.typeName = typeName;
		this.typeVersion = typeVersion;
		this.blueprintTemplate = blueprintTemplate;
		this.application = application;
		this.component = component;
		
		this.serviceIds = (serviceIds == null) ? new LinkedList<String> () : serviceIds;
		this.vnfTypes = (vnfTypes == null) ? new LinkedList<String> () : vnfTypes;
		this.serviceLocations = (serviceLocations == null) ? new LinkedList<String> () : serviceLocations;

		this.asdcServiceId = Optional.ofNullable(asdcServiceId);
		this.asdcResourceId = Optional.ofNullable(asdcResourceId);
		this.asdcServiceURL = Optional.ofNullable(asdcServiceURL);
		this.typeId = Optional.ofNullable(typeId);
		this.selfLink = Optional.ofNullable(selfLink);
		this.created = Optional.ofNullable(created);
		this.deactivated = Optional.ofNullable(deactivated);
		this.canDeploy = Optional.of(false);
		try {
			this.blueprintInputs = Blueprint.parse(blueprintTemplate).getInputs();
			this.blueprintDescription = Blueprint.parse(blueprintTemplate).getDescription();
		} catch (BlueprintParseException e) {
			throw new RuntimeException("Error while parsing blueprint template for " + this.typeName + " " + this.typeVersion, e);
		}
	}

	public String getOwner() {
		return owner;
	}

	public String getTypeName() {
		return typeName;
	}

	public Integer getTypeVersion() {
		return typeVersion;
	}

	public String getBlueprintTemplate() {
		return blueprintTemplate;
	}

	public Collection<String> getServiceIds() {
		return serviceIds;
	}

	public Collection<String> getVnfTypes() {
		return vnfTypes;
	}

	public Collection<String> getServiceLocations() {
		return serviceLocations;
	}

	public Optional<String> getAsdcServiceId() {
		return asdcServiceId;
	}

	public Optional<String> getAsdcResourceId() {
		return asdcResourceId;
	}

	public Optional<String> getAsdcServiceURL() {
		return asdcServiceURL;
	}

	public Optional<String> getTypeId() {
		return typeId;
	}

	public Optional<Link> getSelfLink() {
		return selfLink;
	}

	public Optional<String> getCreated() {
		return created;
	}

	public Optional<String> getDeactivated() {
		return deactivated;
	}

	public Map<String, BlueprintInput> getBlueprintInputs() {
		return blueprintInputs;
	}

	public String getBlueprintDescription() {
		return blueprintDescription;
	}

	public Optional<Boolean> getCanDeploy() {
		return canDeploy;
	}

	public String getApplication() {
		return application;
	}

	public String getComponent() {
		return component;
	}

	public void setCanDeploy(Optional<Boolean> canDeploy) {
		this.canDeploy = canDeploy;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ServiceType)) return false;

		final ServiceType serviceType = (ServiceType) obj;

		return (serviceType.getAsdcResourceId().equals(getAsdcResourceId()) &&
			serviceType.getAsdcServiceId().equals(getAsdcServiceId()) &&
			serviceType.getAsdcServiceURL().equals(getAsdcServiceURL()) &&
			serviceType.getBlueprintTemplate().equals(getBlueprintTemplate()) &&
			serviceType.getCreated().equals(getCreated()) &&
			serviceType.getDeactivated().equals(getDeactivated()) &&
			serviceType.getOwner().equals(getOwner()) &&
			serviceType.getSelfLink().equals(getSelfLink()) &&
			serviceType.getServiceIds().equals(getServiceIds()) &&
			serviceType.getServiceLocations().equals(getServiceLocations()) &&
			serviceType.getTypeId().equals(getTypeId()) &&
			serviceType.getTypeName().equals(getTypeName()) &&
			serviceType.getTypeVersion().equals(getTypeVersion()) &&
			serviceType.getVnfTypes().equals(getVnfTypes()) && 
			serviceType.getApplication().equals(getApplication()) &&
			serviceType.getComponent().equals(getComponent())); 
	}
	
	// Used for back end search, only searches the fields displayed in the front end.
	public boolean contains(String searchString) {
		if (StringUtils.containsIgnoreCase(this.getOwner(), searchString) ||
			StringUtils.containsIgnoreCase(this.getBlueprintDescription(), searchString) ||
			StringUtils.containsIgnoreCase(this.getTypeId().get(), searchString) ||
			StringUtils.containsIgnoreCase(this.getTypeName(), searchString) ||
			StringUtils.containsIgnoreCase(Integer.toString(this.getTypeVersion()), searchString) ||
			StringUtils.containsIgnoreCase(this.getCreated().get(), searchString) ||
			StringUtils.containsIgnoreCase(this.getComponent(), searchString) ||
			StringUtils.containsIgnoreCase(this.getApplication(), searchString) ) {
			return true;
		}
		return false;
	}
}