JUnit/SONAR/Checkstyle in ONAP-REST
[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  * 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.HashMap;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Set;
29
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.GeneratedValue;
33 import javax.persistence.GenerationType;
34 import javax.persistence.Id;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToMany;
37 import javax.persistence.Table;
38
39 import lombok.Getter;
40 import lombok.NoArgsConstructor;
41 import lombok.Setter;
42
43 @Entity
44 @Table(name = "ConstraintType")
45 @NamedQuery(name = "ConstraintType.findAll", query = "SELECT a FROM ConstraintType a")
46 @Getter
47 @Setter
48 @NoArgsConstructor
49 public class ConstraintType implements Serializable {
50     private static final long serialVersionUID = 1L;
51
52     public static final String ENUMERATION_TYPE = "Enumeration";
53     public static final String RANGE_TYPE = "Range";
54     public static final String REGEXP_TYPE = "Regular Expression";
55
56     protected static final Map<String, String> defaults = new HashMap<>();
57
58     static {
59         defaults.put(ENUMERATION_TYPE,
60                         "Enumerate a set of values that the attribute may be set to during policy creation.");
61         defaults.put(RANGE_TYPE, "Set a range of min and/or max integer/double values "
62                         + "the attribute can be set to during policy creation.");
63         defaults.put(REGEXP_TYPE,
64                         "Define a regular expression the attribute must match against during policy creation.");
65     }
66
67     private static final String[] RANGE_TYPES =
68         { "minExclusive", "minInclusive", "maxExclusive", "maxInclusive" };
69
70     @Id
71     @GeneratedValue(strategy = GenerationType.AUTO)
72     @Column(name = "id")
73     private int id;
74
75     @Column(name = "constraint_type", nullable = false, length = 64)
76     private String constraintType;
77
78     @Column(name = "description", nullable = false, length = 255)
79     private String description;
80
81     // bi-directional many-to-one association to Attribute
82     @OneToMany(mappedBy = "constraintType")
83     private Set<Attribute> attributes = new HashSet<>();
84
85     public ConstraintType(String constraintType) {
86         this();
87         this.constraintType = constraintType;
88     }
89
90     public ConstraintType(String constraintType, String description) {
91         this(constraintType);
92         this.description = description;
93     }
94
95     public static String[] getRangeTypes() {
96         return RANGE_TYPES;
97     }
98
99 }