Add validation methods for PAP REST API
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaPolicyIdentifierOptVersion.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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.tosca.authorative.concepts;
22
23 import com.google.gson.annotations.SerializedName;
24 import lombok.Data;
25 import lombok.NoArgsConstructor;
26 import lombok.NonNull;
27 import org.apache.commons.lang3.ObjectUtils;
28
29 /**
30  * Policy identifier with an optional version; only the "name" is required.
31  */
32 @Data
33 @NoArgsConstructor
34 public class ToscaPolicyIdentifierOptVersion implements Comparable<ToscaPolicyIdentifierOptVersion> {
35
36     @NonNull
37     @SerializedName("policy-id")
38     private String name;
39
40     @SerializedName("policy-version")
41     private String version;
42
43
44     public ToscaPolicyIdentifierOptVersion(@NonNull String name, String version) {
45         this.name = name;
46         this.version = version;
47     }
48
49     public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifierOptVersion source) {
50         this.name = source.name;
51         this.version = source.version;
52     }
53
54     /**
55      * Determines if the version is null/missing.
56      *
57      * @return {@code true} if the version is null/missing, {@code false}
58      */
59     public boolean isNullVersion() {
60         return (version == null);
61     }
62
63     @Override
64     public int compareTo(ToscaPolicyIdentifierOptVersion other) {
65         if (this == other) {
66             return 0;
67         }
68
69         if (other == null) {
70             return 1;
71         }
72
73         int result = ObjectUtils.compare(getName(), other.getName());
74         if (result != 0) {
75             return result;
76         }
77
78         return ObjectUtils.compare(getVersion(), other.getVersion());
79     }
80 }