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.onap.policy.rest.jpa;
23 import java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.HashSet;
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;
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;
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";
48 protected static final Map<String, String> defaults = new HashMap<>();
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.");
54 private static final String[] RANGE_TYPES = {"minExclusive", "minInclusive", "maxExclusive", "maxInclusive"};
57 @GeneratedValue(strategy = GenerationType.AUTO)
61 @Column(name="constraint_type", nullable=false, length=64)
62 private String constraintType;
64 @Column(name="description", nullable=false, length=255)
65 private String description;
67 //bi-directional many-to-one association to Attribute
68 @OneToMany(mappedBy="constraintType")
69 private Set<Attribute> attributes = new HashSet<>();
71 public ConstraintType() {
72 //An empty constructor
75 public ConstraintType(String constraintType) {
77 this.constraintType = constraintType;
80 public ConstraintType(String constraintType, String description) {
82 this.description = description;
89 public void setId(int id) {
93 public String getConstraintType() {
94 return constraintType;
97 public void setConstraintType(String constraintType) {
98 this.constraintType = constraintType;
101 public String getDescription() {
105 public void setDescription(String description) {
106 this.description = description;
109 public Set<Attribute> getAttributes() {
113 public void setAttributes(Set<Attribute> attributes) {
114 this.attributes = attributes;
117 public static String[] getRangeTypes() {