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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.base;
24 import javax.persistence.Column;
25 import javax.persistence.Embeddable;
26 import lombok.EqualsAndHashCode;
28 import lombok.NonNull;
29 import org.onap.policy.common.utils.validation.Assertions;
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.
36 * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
37 * regular expressions respectively.
41 @EqualsAndHashCode(callSuper = false)
42 public class PfConceptKey extends PfKeyImpl {
43 private static final long serialVersionUID = 8932717618579392561L;
45 @Column(name = NAME_TOKEN, length = 120)
48 @Column(name = VERSION_TOKEN, length = 20)
49 private String version;
52 * The default constructor creates a null concept key.
54 public PfConceptKey() {
55 this(NULL_KEY_NAME, NULL_KEY_VERSION);
61 * @param copyConcept the concept to copy from
63 public PfConceptKey(final PfConceptKey copyConcept) {
68 * Constructor to create a key with the specified name and version.
70 * @param name the key name
71 * @param version the key version
73 public PfConceptKey(final String name, final String version) {
78 * Constructor to create a key using the key and version from the specified key ID.
80 * @param id the key ID in a format that respects the KEY_ID_REGEXP
82 public PfConceptKey(final String id) {
86 public void setName(@NonNull final String name) {
87 this.name = Assertions.validateStringParameter(NAME_TOKEN, name, getNameRegEx());
90 public void setVersion(@NonNull final String version) {
91 this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
95 * Get a null concept key.
97 * @return a null concept key
99 public static final PfConceptKey getNullKey() {
100 return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
104 public String toString() {
105 return "PfConceptKey(name=" + getName() + ", version=" + getVersion() + ")";