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.parameters.annotations.Pattern;
30 import org.onap.policy.common.utils.validation.Assertions;
33 * An concept key uniquely identifies every first order entity in the system. Every first order concept in the system
34 * must have an {@link PfConceptKey} to identify it. Concepts that are wholly contained in another concept are
35 * identified using a {@link PfReferenceKey} key.
37 * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
38 * regular expressions respectively.
42 @EqualsAndHashCode(callSuper = false)
43 public class PfConceptKey extends PfKeyImpl {
44 private static final long serialVersionUID = 8932717618579392561L;
46 @Column(name = NAME_TOKEN, length = 120)
47 @Pattern(regexp = NAME_REGEXP)
50 @Column(name = VERSION_TOKEN, length = 20)
51 @Pattern(regexp = VERSION_REGEXP)
52 private String version;
55 * The default constructor creates a null concept key.
57 public PfConceptKey() {
58 this(NULL_KEY_NAME, NULL_KEY_VERSION);
64 * @param copyConcept the concept to copy from
66 public PfConceptKey(final PfConceptKey copyConcept) {
71 * Constructor to create a key with the specified name and version.
73 * @param name the key name
74 * @param version the key version
76 public PfConceptKey(final String name, final String version) {
81 * Constructor to create a key using the key and version from the specified key ID.
83 * @param id the key ID in a format that respects the KEY_ID_REGEXP
85 public PfConceptKey(final String id) {
89 public void setName(@NonNull final String name) {
90 this.name = Assertions.validateStringParameter(NAME_TOKEN, name, getNameRegEx());
93 public void setVersion(@NonNull final String version) {
94 this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
98 * Get a null concept key.
100 * @return a null concept key
102 public static final PfConceptKey getNullKey() {
103 return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
107 public String toString() {
108 return "PfConceptKey(name=" + getName() + ", version=" + getVersion() + ")";