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;
46 import lombok.ToString;
49 * The persistent class for the Datatype database table.
53 @Table(name = "Datatype")
54 @NamedQuery(name = "Datatype.findAll", query = "SELECT d FROM Datatype d")
58 public class Datatype implements Serializable {
59 private static final long serialVersionUID = 1L;
61 public static final char STANDARD = 'S';
62 public static final char CUSTOM = 'C';
65 @GeneratedValue(strategy = GenerationType.AUTO)
69 @Column(name = "is_standard", nullable = false)
70 private char isStandard;
72 @Column(name = "xacml_id", nullable = false, unique = true, length = 255)
73 private String xacmlId;
75 @Column(name = "short_name", nullable = false, length = 64)
76 private String shortName;
78 // bi-directional many-to-one association to Attribute
79 @OneToMany(mappedBy = "datatypeBean")
81 private Set<Attribute> attributes = new HashSet<>();
83 // bi-directional many-to-one association to Attribute
84 @OneToMany(mappedBy = "datatypeBean")
86 private Set<FunctionDefinition> functions = new HashSet<>();
88 // bi-directional many-to-one association to Attribute
89 @OneToMany(mappedBy = "datatypeBean")
91 private Set<FunctionArgument> arguments = new HashSet<>();
94 * Instantiates a new datatype.
97 this.xacmlId = XACML3.ID_DATATYPE_STRING.stringValue();
98 this.isStandard = Datatype.STANDARD;
102 * Instantiates a new datatype.
107 public Datatype(int id, Datatype dt) {
109 this.isStandard = dt.isStandard;
110 this.xacmlId = dt.xacmlId;
111 this.shortName = dt.shortName;
115 this.attributes = new HashSet<>();
119 * Instantiates a new datatype.
121 * @param identifier the identifier
122 * @param standard the standard
124 public Datatype(Identifier identifier, char standard) {
125 if (identifier != null) {
126 this.xacmlId = identifier.stringValue();
129 this.isStandard = standard;
133 * Instantiates a new datatype.
135 * @param identifier the identifier
137 public Datatype(Identifier identifier) {
138 this(identifier, Datatype.STANDARD);
142 * Adds the attribute.
144 * @param attribute the attribute
145 * @return the attribute
147 public Attribute addAttribute(Attribute attribute) {
148 getAttributes().add(attribute);
149 attribute.setDatatypeBean(this);
155 * Removes the attribute.
157 * @param attribute the attribute
158 * @return the attribute
160 public Attribute removeAttribute(Attribute attribute) {
161 getAttributes().remove(attribute);
162 attribute.setDatatypeBean(null);
168 * Removes the attribute.
170 * @param function the function
171 * @return the function definition
173 public FunctionDefinition removeAttribute(FunctionDefinition function) {
174 getFunctions().remove(function);
175 function.setDatatypeBean(null);
183 * @param function the function
184 * @return the function definition
186 public FunctionDefinition addFunction(FunctionDefinition function) {
187 getFunctions().add(function);
188 function.setDatatypeBean(this);
196 * @param argument the argument
197 * @return the function argument
199 public FunctionArgument addArgument(FunctionArgument argument) {
200 getArguments().add(argument);
201 argument.setDatatypeBean(this);
207 * Removes the argument.
209 * @param argument the argument
210 * @return the function argument
212 public FunctionArgument removeArgument(FunctionArgument argument) {
213 getArguments().remove(argument);
214 argument.setDatatypeBean(null);
220 * Gets the identifer.
222 * @return the identifer
225 public Identifier getIdentifer() {
226 return new IdentifierImpl(this.xacmlId);
230 * Gets the identifer by short name.
232 * @return the identifer by short name
235 public Identifier getIdentiferByShortName() {
236 return new IdentifierImpl(this.shortName);
240 * Checks if is standard.
242 * @return true, if is standard
245 public boolean isStandard() {
246 return this.isStandard == Datatype.STANDARD;
250 * Checks if is custom.
252 * @return true, if is custom
255 public boolean isCustom() {
256 return this.isStandard == Datatype.CUSTOM;