Java 17 Upgrade
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfConceptKey.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.base;
23
24 import jakarta.persistence.Column;
25 import jakarta.persistence.Embeddable;
26 import java.io.Serial;
27 import lombok.EqualsAndHashCode;
28 import lombok.Getter;
29 import lombok.NonNull;
30 import lombok.ToString;
31 import org.onap.policy.common.parameters.annotations.Pattern;
32 import org.onap.policy.common.utils.validation.Assertions;
33
34 /**
35  * A concept key uniquely identifies every first order entity in the system. Every first order concept in the system
36  * must have an {@link PfConceptKey} to identify it. Concepts that are wholly contained in another concept are
37  * identified using a {@link PfReferenceKey} key.
38  *
39  * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
40  * regular expressions respectively.
41  */
42 @Embeddable
43 @Getter
44 @EqualsAndHashCode(callSuper = false)
45 @ToString
46 public class PfConceptKey extends PfKeyImpl {
47     @Serial
48     private static final long serialVersionUID = 8932717618579392561L;
49
50     @Column(name = NAME_TOKEN, length = 120)
51     @Pattern(regexp = NAME_REGEXP)
52     private String name;
53
54     @Column(name = VERSION_TOKEN, length = 20)
55     @Pattern(regexp = VERSION_REGEXP)
56     private String version;
57
58     /**
59      * The default constructor creates a null concept key.
60      */
61     public PfConceptKey() {
62         this(NULL_KEY_NAME, NULL_KEY_VERSION);
63     }
64
65     /**
66      * Copy constructor.
67      *
68      * @param copyConcept the concept to copy from
69      */
70     public PfConceptKey(final PfConceptKey copyConcept) {
71         super(copyConcept);
72     }
73
74     /**
75      * Constructor to create a key with the specified name and version.
76      *
77      * @param name    the key name
78      * @param version the key version
79      */
80     public PfConceptKey(final String name, final String version) {
81         super(name, version);
82     }
83
84     /**
85      * Constructor to create a key using the key and version from the specified key ID.
86      *
87      * @param id the key ID in a format that respects the KEY_ID_REGEXP
88      */
89     public PfConceptKey(final String id) {
90         super(id);
91     }
92
93     public void setName(@NonNull final String name) {
94         this.name = Assertions.validateStringParameter(NAME_TOKEN, name, getNameRegEx());
95     }
96
97     public void setVersion(@NonNull final String version) {
98         this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
99     }
100
101     /**
102      * Get a null concept key.
103      *
104      * @return a null concept key
105      */
106     public static PfConceptKey getNullKey() {
107         return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
108     }
109 }