Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / ConstraintType.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.rest.jpa;
22
23 import java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.Map;
27 import java.util.Set;
28
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.GenerationType;
33 import javax.persistence.Id;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToMany;
36 import javax.persistence.Table;
37
38 @Entity
39 @Table(name="ConstraintType")
40 @NamedQuery(name="ConstraintType.findAll", query="SELECT a FROM ConstraintType a")
41 public class ConstraintType implements Serializable {
42         private static final long serialVersionUID = 1L;
43         
44         public static final String ENUMERATION_TYPE = "Enumeration";
45         public static final String RANGE_TYPE = "Range";
46         public static final String REGEXP_TYPE = "Regular Expression";
47         
48         protected static final Map<String, String> defaults = new HashMap<>();
49         static {
50                 defaults.put(ENUMERATION_TYPE, "Enumerate a set of values that the attribute may be set to during policy creation.");
51                 defaults.put(RANGE_TYPE, "Set a range of min and/or max integer/double values the attribute can be set to during policy creation.");
52                 defaults.put(REGEXP_TYPE, "Define a regular expression the attribute must match against during policy creation.");
53         }
54         private static final String[] RANGE_TYPES = {"minExclusive", "minInclusive", "maxExclusive", "maxInclusive"};
55         
56         @Id
57         @GeneratedValue(strategy = GenerationType.AUTO)
58         @Column(name="id")
59         private int id;
60
61         @Column(name="constraint_type", nullable=false, length=64)
62         private String constraintType;
63         
64         @Column(name="description", nullable=false, length=255)
65         private String description;
66
67         //bi-directional many-to-one association to Attribute
68         @OneToMany(mappedBy="constraintType")
69         private Set<Attribute> attributes = new HashSet<>();
70
71         public ConstraintType() {
72                 //An empty constructor
73         }
74
75         public ConstraintType(String constraintType) {
76                 this();
77                 this.constraintType = constraintType;
78         }
79         
80         public ConstraintType(String constraintType, String description) {
81                 this(constraintType);
82                 this.description = description;
83         }
84
85         public int getId() {
86                 return id;
87         }
88
89         public void setId(int id) {
90                 this.id = id;
91         }
92
93         public String getConstraintType() {
94                 return constraintType;
95         }
96
97         public void setConstraintType(String constraintType) {
98                 this.constraintType = constraintType;
99         }
100
101         public String getDescription() {
102                 return description;
103         }
104
105         public void setDescription(String description) {
106                 this.description = description;
107         }
108
109         public Set<Attribute> getAttributes() {
110                 return attributes;
111         }
112
113         public void setAttributes(Set<Attribute> attributes) {
114                 this.attributes = attributes;
115         }
116
117         public static String[] getRangeTypes() {
118                 return RANGE_TYPES;
119         }
120
121 }