Unit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / RuleAlgorithms.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 com.att.research.xacml.api.Identifier;
25
26 import java.io.Serializable;
27
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
36
37 import lombok.Getter;
38 import lombok.Setter;
39
40 /**
41  * The Class RuleAlgorithms.
42  */
43 @Entity
44 @Table(name = "RuleAlgorithms")
45 @NamedQuery(name = "RuleAlgorithms.findAll", query = "SELECT d FROM RuleAlgorithms d")
46 @Getter
47 @Setter
48 public class RuleAlgorithms implements Serializable {
49     private static final long serialVersionUID = 1L;
50
51     public static final char STANDARD = 'S';
52     public static final char CUSTOM = 'C';
53
54     @Id
55     @GeneratedValue(strategy = GenerationType.AUTO)
56     @Column(name = "id")
57     private int id;
58
59     @Column(name = "is_standard", nullable = false)
60     private char isStandard;
61
62     @Column(name = "xacml_id", nullable = false, unique = true, length = 255)
63     private String xacmlId;
64
65     @Column(name = "short_name", nullable = false, length = 64)
66     private String shortName;
67
68     /**
69      * Instantiates a new rule algorithms.
70      *
71      * @param id the id
72      * @param standard the standard
73      */
74     public RuleAlgorithms(Identifier id, char standard) {
75         if (id != null) {
76             this.xacmlId = id.stringValue();
77         }
78         this.isStandard = standard;
79     }
80
81     /**
82      * Instantiates a new rule algorithms.
83      *
84      * @param id the id
85      */
86     public RuleAlgorithms(Identifier id) {
87         this(id, RuleAlgorithms.STANDARD);
88     }
89
90     /**
91      * Instantiates a new rule algorithms.
92      */
93     public RuleAlgorithms() {
94         this(null, RuleAlgorithms.STANDARD);
95     }
96
97     @Transient
98     public boolean isStandard() {
99         return this.isStandard == RuleAlgorithms.STANDARD;
100     }
101
102     @Transient
103     public boolean isCustom() {
104         return this.isStandard == RuleAlgorithms.CUSTOM;
105     }
106 }