Support wild cards in "supported policy types"
[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 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 javax.persistence.Column;
25 import javax.persistence.Embeddable;
26 import lombok.EqualsAndHashCode;
27 import lombok.Getter;
28 import lombok.NonNull;
29 import org.onap.policy.common.utils.validation.Assertions;
30
31 /**
32  * An concept key uniquely identifies every first order entity in the system. Every first order concept in the system
33  * must have an {@link PfConceptKey} to identify it. Concepts that are wholly contained in another concept are
34  * identified using a {@link PfReferenceKey} key.
35  *
36  * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
37  * regular expressions respectively.
38  */
39 @Embeddable
40 @Getter
41 @EqualsAndHashCode(callSuper = false)
42 public class PfConceptKey extends PfKeyImpl {
43     private static final long serialVersionUID = 8932717618579392561L;
44
45     @Column(name = NAME_TOKEN, length = 120)
46     private String name;
47
48     @Column(name = VERSION_TOKEN, length = 20)
49     private String version;
50
51     /**
52      * The default constructor creates a null concept key.
53      */
54     public PfConceptKey() {
55         this(NULL_KEY_NAME, NULL_KEY_VERSION);
56     }
57
58     /**
59      * Copy constructor.
60      *
61      * @param copyConcept the concept to copy from
62      */
63     public PfConceptKey(final PfConceptKey copyConcept) {
64         super(copyConcept);
65     }
66
67     /**
68      * Constructor to create a key with the specified name and version.
69      *
70      * @param name the key name
71      * @param version the key version
72      */
73     public PfConceptKey(final String name, final String version) {
74         super(name, version);
75     }
76
77     /**
78      * Constructor to create a key using the key and version from the specified key ID.
79      *
80      * @param id the key ID in a format that respects the KEY_ID_REGEXP
81      */
82     public PfConceptKey(final String id) {
83         super(id);
84     }
85
86     public void setName(@NonNull final String name) {
87         this.name = Assertions.validateStringParameter(NAME_TOKEN, name, getNameRegEx());
88     }
89
90     public void setVersion(@NonNull final String version) {
91         this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
92     }
93
94     /**
95      * Get a null concept key.
96      *
97      * @return a null concept key
98      */
99     public static final PfConceptKey getNullKey() {
100         return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
101     }
102
103     @Override
104     public String toString() {
105         return "PfConceptKey(name=" + getName() + ", version=" + getVersion() + ")";
106     }
107 }