7bd78a22227b409b95a1dcd2466e85be6458f4ef
[policy/models.git] / models-pap / src / main / java / org / onap / policy / models / pap / concepts / PapPolicyIdentifier.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2021 Nordix Foundation.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.pap.concepts;
22
23 import com.google.gson.annotations.SerializedName;
24 import io.swagger.annotations.ApiModelProperty;
25 import lombok.NonNull;
26 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
27 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
28
29 /**
30  * Policy identifier with an optional version; only the "name" is required.
31  *
32  * <p>Note that there are deliberately no setters or getters on this class, it is use purely for GSON serialization and
33  * deserializaiton
34  */
35 public class PapPolicyIdentifier {
36     @NonNull
37     @ApiModelProperty(name = "policy-id")
38     @SerializedName("policy-id")
39     private String name;
40
41     @ApiModelProperty(name = "policy-version")
42     @SerializedName("policy-version")
43     private String version;
44
45     public PapPolicyIdentifier(final String name, final String version) {
46         this.name = name;
47         this.version = version;
48     }
49
50     public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifier identifier) {
51         this(identifier.getName(), identifier.getVersion());
52     }
53
54     public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifierOptVersion identifier) {
55         this(identifier.getName(), identifier.getVersion());
56     }
57
58     public ToscaConceptIdentifierOptVersion getGenericIdentifier() {
59         return name == null ? new ToscaConceptIdentifierOptVersion()
60                 : new ToscaConceptIdentifierOptVersion(name, version);
61     }
62 }