2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.jpa;
24 import com.att.research.xacml.api.Identifier;
25 import com.att.research.xacml.api.XACML3;
26 import com.att.research.xacml.std.IdentifierImpl;
27 import com.fasterxml.jackson.annotation.JsonBackReference;
28 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import java.io.Serializable;
31 import java.util.HashSet;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.GeneratedValue;
37 import javax.persistence.GenerationType;
38 import javax.persistence.Id;
39 import javax.persistence.NamedQuery;
40 import javax.persistence.OneToMany;
41 import javax.persistence.Table;
42 import javax.persistence.Transient;
45 * The persistent class for the Datatype database table.
49 @Table(name = "Datatype")
50 @NamedQuery(name = "Datatype.findAll", query = "SELECT d FROM Datatype d")
51 public class Datatype implements Serializable {
52 private static final long serialVersionUID = 1L;
54 public static final char STANDARD = 'S';
55 public static final char CUSTOM = 'C';
58 @GeneratedValue(strategy = GenerationType.AUTO)
62 @Column(name = "is_standard", nullable = false)
63 private char isStandard;
65 @Column(name = "xacml_id", nullable = false, unique = true, length = 255)
66 private String xacmlId;
68 @Column(name = "short_name", nullable = false, length = 64)
69 private String shortName;
71 // bi-directional many-to-one association to Attribute
72 @OneToMany(mappedBy = "datatypeBean")
74 private Set<Attribute> attributes = new HashSet<>();
76 // bi-directional many-to-one association to Attribute
77 @OneToMany(mappedBy = "datatypeBean")
79 private Set<FunctionDefinition> functions = new HashSet<>();
81 // bi-directional many-to-one association to Attribute
82 @OneToMany(mappedBy = "datatypeBean")
84 private Set<FunctionArgument> arguments = new HashSet<>();
87 * Instantiates a new datatype.
90 this.xacmlId = XACML3.ID_DATATYPE_STRING.stringValue();
91 this.isStandard = Datatype.STANDARD;
95 * Instantiates a new datatype.
100 public Datatype(int id, Datatype dt) {
102 this.isStandard = dt.isStandard;
103 this.xacmlId = dt.xacmlId;
104 this.shortName = dt.shortName;
108 this.attributes = new HashSet<>();
112 * Instantiates a new datatype.
114 * @param identifier the identifier
115 * @param standard the standard
117 public Datatype(Identifier identifier, char standard) {
118 if (identifier != null) {
119 this.xacmlId = identifier.stringValue();
122 this.isStandard = standard;
126 * Instantiates a new datatype.
128 * @param identifier the identifier
130 public Datatype(Identifier identifier) {
131 this(identifier, Datatype.STANDARD);
146 * @param id the new id
148 public void setId(int id) {
153 * Gets the checks if is standard.
155 * @return the checks if is standard
157 public char getIsStandard() {
158 return this.isStandard;
162 * Sets the checks if is standard.
164 * @param isStandard the new checks if is standard
166 public void setIsStandard(char isStandard) {
167 this.isStandard = isStandard;
173 * @return the xacml id
175 public String getXacmlId() {
182 * @param xacmlId the new xacml id
184 public void setXacmlId(String xacmlId) {
185 this.xacmlId = xacmlId;
189 * Gets the short name.
191 * @return the short name
193 public String getShortName() {
198 * Sets the short name.
200 * @param shortName the new short name
202 public void setShortName(String shortName) {
203 this.shortName = shortName;
207 * Gets the attributes.
209 * @return the attributes
211 public Set<Attribute> getAttributes() {
212 return this.attributes;
216 * Sets the attributes.
218 * @param attributes the new attributes
220 public void setAttributes(Set<Attribute> attributes) {
221 this.attributes = attributes;
225 * Adds the attribute.
227 * @param attribute the attribute
228 * @return the attribute
230 public Attribute addAttribute(Attribute attribute) {
231 getAttributes().add(attribute);
232 attribute.setDatatypeBean(this);
238 * Removes the attribute.
240 * @param attribute the attribute
241 * @return the attribute
243 public Attribute removeAttribute(Attribute attribute) {
244 getAttributes().remove(attribute);
245 attribute.setDatatypeBean(null);
251 * Removes the attribute.
253 * @param function the function
254 * @return the function definition
256 public FunctionDefinition removeAttribute(FunctionDefinition function) {
257 getFunctions().remove(function);
258 function.setDatatypeBean(null);
264 * Gets the functions.
266 * @return the functions
268 public Set<FunctionDefinition> getFunctions() {
269 return this.functions;
273 * Sets the functions.
275 * @param functions the new functions
277 public void setFunctions(Set<FunctionDefinition> functions) {
278 this.functions = functions;
284 * @param function the function
285 * @return the function definition
287 public FunctionDefinition addFunction(FunctionDefinition function) {
288 getFunctions().add(function);
289 function.setDatatypeBean(this);
295 * Gets the arguments.
297 * @return the arguments
299 public Set<FunctionArgument> getArguments() {
300 return this.arguments;
304 * Sets the arguments.
306 * @param argument the new arguments
308 public void setArguments(Set<FunctionArgument> argument) {
309 this.arguments = argument;
315 * @param argument the argument
316 * @return the function argument
318 public FunctionArgument addArgument(FunctionArgument argument) {
319 getArguments().add(argument);
320 argument.setDatatypeBean(this);
326 * Removes the argument.
328 * @param argument the argument
329 * @return the function argument
331 public FunctionArgument removeArgument(FunctionArgument argument) {
332 getArguments().remove(argument);
333 argument.setDatatypeBean(null);
339 * Gets the identifer.
341 * @return the identifer
344 public Identifier getIdentifer() {
345 return new IdentifierImpl(this.xacmlId);
349 * Gets the identifer by short name.
351 * @return the identifer by short name
354 public Identifier getIdentiferByShortName() {
355 return new IdentifierImpl(this.shortName);
359 * Checks if is standard.
361 * @return true, if is standard
364 public boolean isStandard() {
365 return this.isStandard == Datatype.STANDARD;
369 * Checks if is custom.
371 * @return true, if is custom
374 public boolean isCustom() {
375 return this.isStandard == Datatype.CUSTOM;
385 public String toString() {
386 return "Datatype [id=" + id + ", isStandard=" + isStandard + ", xacmlId=" + xacmlId + ", shortName=" + shortName
387 + ", attributes=" + attributes + ", functions=" + functions + ", arguments=" + arguments + "]";