JUnit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / FunctionDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.rest.jpa;
23
24 import java.io.Serializable;
25 import java.util.List;
26
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.JoinColumn;
33 import javax.persistence.ManyToOne;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToMany;
37 import javax.persistence.Table;
38 import javax.persistence.Transient;
39
40 import lombok.Getter;
41 import lombok.NoArgsConstructor;
42 import lombok.Setter;
43 import lombok.ToString;
44
45 /**
46  * The persistent class for the FunctionDefinition database table.
47  *
48  */
49 // @formatter:off
50 @Entity
51 @Table(name = "FunctionDefinition")
52 @NamedQueries(
53     {
54         @NamedQuery(name = "FunctionDefinition.findAll", query = "SELECT f FROM FunctionDefinition f")
55     }
56 )
57 @Getter
58 @Setter
59 @ToString
60 @NoArgsConstructor
61 // @formatter:on
62 public class FunctionDefinition implements Serializable {
63     private static final long serialVersionUID = 1L;
64
65     @Id
66     @GeneratedValue(strategy = GenerationType.AUTO)
67     @Column(name = "id")
68     private int id;
69
70     @Column(name = "short_name", nullable = false, length = 64)
71     private String shortname;
72
73     @Column(name = "xacml_id", nullable = false, length = 255)
74     private String xacmlid;
75
76     // bi-directional many-to-one association to Datatype
77     @ManyToOne
78     @JoinColumn(name = "return_datatype", nullable = true)
79     private Datatype datatypeBean;
80
81     @Column(name = "is_bag_return", nullable = false)
82     private Integer isBagReturn;
83
84     @Column(name = "is_higher_order", nullable = false)
85     private Integer isHigherOrder;
86
87     @Column(name = "arg_lb", nullable = false)
88     private Integer argLb;
89
90     @Column(name = "arg_ub", nullable = false)
91     private Integer argUb;
92
93     @Column(name = "ho_arg_lb", nullable = true)
94     private Integer higherOrderArgLb;
95
96     @Column(name = "ho_arg_ub", nullable = true)
97     private Integer higherOrderArgUb;
98
99     @Column(name = "ho_primitive", nullable = true)
100     private Character higherOrderIsPrimitive;
101
102     // bi-directional many-to-one association to FunctionArgument
103     @OneToMany(mappedBy = "functionDefinition")
104     private List<FunctionArgument> functionArguments;
105
106     /**
107      * Adds the function argument.
108      *
109      * @param functionArgument the function argument
110      * @return the function argument
111      */
112     public FunctionArgument addFunctionArgument(FunctionArgument functionArgument) {
113         getFunctionArguments().add(functionArgument);
114         functionArgument.setFunctionDefinition(this);
115
116         return functionArgument;
117     }
118
119     /**
120      * Removes the function argument.
121      *
122      * @param functionArgument the function argument
123      * @return the function argument
124      */
125     public FunctionArgument removeFunctionArgument(FunctionArgument functionArgument) {
126         getFunctionArguments().remove(functionArgument);
127         functionArgument.setFunctionDefinition(null);
128
129         return functionArgument;
130     }
131
132     /**
133      * Checks if is bag return.
134      *
135      * @return true, if is bag return
136      */
137     @Transient
138     public boolean isBagReturn() {
139         return this.isBagReturn == 1;
140     }
141
142     /**
143      * Checks if is higher order.
144      *
145      * @return true, if is higher order
146      */
147     @Transient
148     public boolean isHigherOrder() {
149         return this.isHigherOrder == 1;
150     }
151
152 }