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.openecomp.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;
42 import com.fasterxml.jackson.annotation.JsonManagedReference;
46 * The persistent class for the Datatype database table.
50 @Table(name="Datatype")
51 @NamedQuery(name="Datatype.findAll", query="SELECT d FROM Datatype d")
52 public class Datatype implements Serializable {
53 private static final long serialVersionUID = 1L;
55 public static final char STANDARD = 'S';
56 public static final char CUSTOM = 'C';
59 @GeneratedValue(strategy = GenerationType.AUTO)
63 @Column(name="is_standard", nullable=false)
64 private char isStandard;
66 @Column(name="xacml_id", nullable=false, unique=true, length=255)
67 private String xacmlId;
69 @Column(name="short_name", nullable=false, length=64)
70 private String shortName;
72 //bi-directional many-to-one association to Attribute
73 @OneToMany(mappedBy="datatypeBean")
75 private Set<Attribute> attributes = new HashSet<>();
77 //bi-directional many-to-one association to Attribute
78 @OneToMany(mappedBy="datatypeBean")
80 private Set<FunctionDefinition> functions = new HashSet<>();
82 //bi-directional many-to-one association to Attribute
83 @OneToMany(mappedBy="datatypeBean")
85 private Set<FunctionArgument> arguments = new HashSet<>();
88 this.xacmlId = XACML3.ID_DATATYPE_STRING.stringValue();
89 this.isStandard = Datatype.STANDARD;
93 public Datatype(int id, Datatype dt) {
95 this.isStandard = dt.isStandard;
96 this.xacmlId = dt.xacmlId;
97 this.shortName = dt.shortName;
101 this.attributes = new HashSet<>();
104 public Datatype(Identifier identifier, char standard) {
105 if (identifier != null) {
106 this.xacmlId = identifier.stringValue();
109 this.isStandard = standard;
112 public Datatype(Identifier identifier) {
113 this(identifier, Datatype.STANDARD);
120 public void setId(int id) {
124 public char getIsStandard() {
125 return this.isStandard;
128 public void setIsStandard(char isStandard) {
129 this.isStandard = isStandard;
132 public String getXacmlId() {
136 public void setXacmlId(String xacmlId) {
137 this.xacmlId = xacmlId;
140 public String getShortName() {
144 public void setShortName(String shortName) {
145 this.shortName = shortName;
148 public Set<Attribute> getAttributes() {
149 return this.attributes;
152 public void setAttributes(Set<Attribute> attributes) {
153 this.attributes = attributes;
156 public Attribute addAttribute(Attribute attribute) {
157 getAttributes().add(attribute);
158 attribute.setDatatypeBean(this);
163 public Attribute removeAttribute(Attribute attribute) {
164 getAttributes().remove(attribute);
165 attribute.setDatatypeBean(null);
170 public Set<FunctionDefinition> getFunctions() {
171 return this.functions;
174 public void setFunctions(Set<FunctionDefinition> functions) {
175 this.functions = functions;
178 public FunctionDefinition addFunction(FunctionDefinition function) {
179 getFunctions().add(function);
180 function.setDatatypeBean(this);
185 public FunctionDefinition removeAttribute(FunctionDefinition function) {
186 getFunctions().remove(function);
187 function.setDatatypeBean(null);
192 public Set<FunctionArgument> getArguments() {
193 return this.arguments;
196 public void setArguments(Set<FunctionArgument> argument) {
197 this.arguments = argument;
200 public FunctionArgument addArgument(FunctionArgument argument) {
201 getArguments().add(argument);
202 argument.setDatatypeBean(this);
207 public FunctionArgument removeArgument(FunctionArgument argument) {
208 getArguments().remove(argument);
209 argument.setDatatypeBean(null);
215 public Identifier getIdentifer() {
216 return new IdentifierImpl(this.xacmlId);
220 public Identifier getIdentiferByShortName() {
221 return new IdentifierImpl(this.shortName);
225 public boolean isStandard() {
226 return (this.isStandard == Datatype.STANDARD);
230 public boolean isCustom() {
231 return (this.isStandard == Datatype.CUSTOM);
236 public String toString() {
237 return "Datatype [id=" + id + ", isStandard=" + isStandard
238 + ", xacmlId=" + xacmlId + ", shortName=" + shortName
239 + ", attributes=" + attributes + ", functions=" + functions
240 + ", arguments=" + arguments + "]";
242 //return "Datatype [shortName=" + shortName + "]";