Unit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / jpa / PolicyAlgorithms.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 PolicyAlgorithms.
42  */
43 @Entity
44 @Table(name = "PolicyAlgorithms")
45 @NamedQuery(name = "PolicyAlgorithms.findAll", query = "SELECT d FROM PolicyAlgorithms d")
46 @Getter
47 @Setter
48 public class PolicyAlgorithms 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 policy algorithms.
70      *
71      * @param identifier the identifier
72      * @param standard the standard
73      */
74     public PolicyAlgorithms(Identifier identifier, char standard) {
75         this.isStandard = standard;
76         if (identifier != null) {
77             this.xacmlId = identifier.stringValue();
78         }
79     }
80
81     /**
82      * Instantiates a new policy algorithms.
83      *
84      * @param identifier the identifier
85      */
86     public PolicyAlgorithms(Identifier identifier) {
87         this(identifier, PolicyAlgorithms.STANDARD);
88     }
89
90     /**
91      * Instantiates a new policy algorithms.
92      */
93     public PolicyAlgorithms() {
94         this(null, PolicyAlgorithms.STANDARD);
95     }
96
97     /**
98      * Checks if is standard.
99      *
100      * @return true, if is standard
101      */
102     @Transient
103     public boolean isStandard() {
104         return this.isStandard == PolicyAlgorithms.STANDARD;
105     }
106
107     /**
108      * Checks if is custom.
109      *
110      * @return true, if is custom
111      */
112     @Transient
113     public boolean isCustom() {
114         return this.isStandard == PolicyAlgorithms.CUSTOM;
115     }
116 }