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 import lombok.NoArgsConstructor;
44 @Table(name = "ConstraintType")
45 @NamedQuery(name = "ConstraintType.findAll", query = "SELECT a FROM ConstraintType a")
49 public class ConstraintType implements Serializable {
50 private static final long serialVersionUID = 1L;
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";
56 protected static final Map<String, String> defaults = new HashMap<>();
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.");
67 private static final String[] RANGE_TYPES =
68 { "minExclusive", "minInclusive", "maxExclusive", "maxInclusive" };
71 @GeneratedValue(strategy = GenerationType.AUTO)
75 @Column(name = "constraint_type", nullable = false, length = 64)
76 private String theConstraintType;
78 @Column(name = "description", nullable = false, length = 255)
79 private String description;
81 // bi-directional many-to-one association to Attribute
82 @OneToMany(mappedBy = "constraintType")
83 private Set<Attribute> attributes = new HashSet<>();
85 public ConstraintType(String constraintType) {
87 this.theConstraintType = constraintType;
90 public ConstraintType(String constraintType, String description) {
92 this.description = description;
95 public static String[] getRangeTypes() {
99 public String getConstraintType() {
100 return theConstraintType;
103 public void setConstraintType(final String theConstraintType) {
104 this.theConstraintType = theConstraintType;