2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.rest.jpa;
23 import java.io.Serializable;
24 import java.util.HashSet;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.OneToMany;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
37 import com.att.research.xacml.api.Identifier;
38 import com.att.research.xacml.api.XACML3;
39 import com.att.research.xacml.std.IdentifierImpl;
40 import com.fasterxml.jackson.annotation.JsonBackReference;
41 import com.fasterxml.jackson.annotation.JsonIgnore;
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 this.xacmlId = XACML3.ID_DATATYPE_STRING.stringValue();
88 this.isStandard = Datatype.STANDARD;
92 public Datatype(int id, Datatype dt) {
94 this.isStandard = dt.isStandard;
95 this.xacmlId = dt.xacmlId;
96 this.shortName = dt.shortName;
100 this.attributes = new HashSet<>();
103 public Datatype(Identifier identifier, char standard) {
104 if (identifier != null) {
105 this.xacmlId = identifier.stringValue();
108 this.isStandard = standard;
111 public Datatype(Identifier identifier) {
112 this(identifier, Datatype.STANDARD);
119 public void setId(int id) {
123 public char getIsStandard() {
124 return this.isStandard;
127 public void setIsStandard(char isStandard) {
128 this.isStandard = isStandard;
131 public String getXacmlId() {
135 public void setXacmlId(String xacmlId) {
136 this.xacmlId = xacmlId;
139 public String getShortName() {
143 public void setShortName(String shortName) {
144 this.shortName = shortName;
147 public Set<Attribute> getAttributes() {
148 return this.attributes;
151 public void setAttributes(Set<Attribute> attributes) {
152 this.attributes = attributes;
155 public Attribute addAttribute(Attribute attribute) {
156 getAttributes().add(attribute);
157 attribute.setDatatypeBean(this);
162 public Attribute removeAttribute(Attribute attribute) {
163 getAttributes().remove(attribute);
164 attribute.setDatatypeBean(null);
169 public Set<FunctionDefinition> getFunctions() {
170 return this.functions;
173 public void setFunctions(Set<FunctionDefinition> functions) {
174 this.functions = functions;
177 public FunctionDefinition addFunction(FunctionDefinition function) {
178 getFunctions().add(function);
179 function.setDatatypeBean(this);
184 public FunctionDefinition removeAttribute(FunctionDefinition function) {
185 getFunctions().remove(function);
186 function.setDatatypeBean(null);
191 public Set<FunctionArgument> getArguments() {
192 return this.arguments;
195 public void setArguments(Set<FunctionArgument> argument) {
196 this.arguments = argument;
199 public FunctionArgument addArgument(FunctionArgument argument) {
200 getArguments().add(argument);
201 argument.setDatatypeBean(this);
206 public FunctionArgument removeArgument(FunctionArgument argument) {
207 getArguments().remove(argument);
208 argument.setDatatypeBean(null);
214 public Identifier getIdentifer() {
215 return new IdentifierImpl(this.xacmlId);
219 public Identifier getIdentiferByShortName() {
220 return new IdentifierImpl(this.shortName);
224 public boolean isStandard() {
225 return this.isStandard == Datatype.STANDARD;
229 public boolean isCustom() {
230 return this.isStandard == Datatype.CUSTOM;
235 public String toString() {
236 return "Datatype [id=" + id + ", isStandard=" + isStandard
237 + ", xacmlId=" + xacmlId + ", shortName=" + shortName
238 + ", attributes=" + attributes + ", functions=" + functions
239 + ", arguments=" + arguments + "]";