2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.rest.jpa;
24 import java.io.Serializable;
25 import java.util.HashMap;
26 import java.util.HashSet;
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;
40 @Table(name = "ConstraintType")
41 @NamedQuery(name = "ConstraintType.findAll", query = "SELECT a FROM ConstraintType a")
42 public class ConstraintType implements Serializable {
43 private static final long serialVersionUID = 1L;
45 public static final String ENUMERATION_TYPE = "Enumeration";
46 public static final String RANGE_TYPE = "Range";
47 public static final String REGEXP_TYPE = "Regular Expression";
49 protected static final Map<String, String> defaults = new HashMap<>();
52 defaults.put(ENUMERATION_TYPE,
53 "Enumerate a set of values that the attribute may be set to during policy creation.");
54 defaults.put(RANGE_TYPE, "Set a range of min and/or max integer/double values "
55 + "the attribute can be set to during policy creation.");
56 defaults.put(REGEXP_TYPE,
57 "Define a regular expression the attribute must match against during policy creation.");
60 private static final String[] RANGE_TYPES =
61 { "minExclusive", "minInclusive", "maxExclusive", "maxInclusive" };
64 @GeneratedValue(strategy = GenerationType.AUTO)
68 @Column(name = "constraint_type", nullable = false, length = 64)
69 private String constraintType;
71 @Column(name = "description", nullable = false, length = 255)
72 private String description;
74 // bi-directional many-to-one association to Attribute
75 @OneToMany(mappedBy = "constraintType")
76 private Set<Attribute> attributes = new HashSet<>();
78 public ConstraintType() {
79 // An empty constructor
82 public ConstraintType(String constraintType) {
84 this.constraintType = constraintType;
87 public ConstraintType(String constraintType, String description) {
89 this.description = description;
96 public void setId(int id) {
100 public String getConstraintType() {
101 return constraintType;
104 public void setConstraintType(String constraintType) {
105 this.constraintType = constraintType;
108 public String getDescription() {
112 public void setDescription(String description) {
113 this.description = description;
116 public Set<Attribute> getAttributes() {
120 public void setAttributes(Set<Attribute> attributes) {
121 this.attributes = attributes;
124 public static String[] getRangeTypes() {