2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.versioning.dao.types;
23 import com.datastax.driver.mapping.annotations.Transient;
24 import com.datastax.driver.mapping.annotations.UDT;
26 import java.util.Date;
29 @UDT(name = "version", keyspace = "dox")
30 public class Version {
31 public static final String VERSION_STRING_VIOLATION_MSG =
32 "Version string must be in the format of: {integer}.{integer}";
36 private int major; // TODO: 6/7/2017 remove!
37 private int minor; // TODO: 6/7/2017 remove!
41 private String description;
43 private String baseId;
45 private Date creationTime;
47 private Date modificationTime;
49 private VersionStatus status = VersionStatus.Draft;
51 private VersionState state;
53 private Map<String, Object> additionalInfo;
58 public Version(String id) {
63 public Version(int major, int minor) {
71 * @param versionString the version string
74 public static Version valueOf(String versionString) {
75 if (versionString == null) {
78 String[] versionLevels = versionString.split("\\.");
80 if (versionLevels.length != 2) {
81 throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
84 version = new Version(Integer.parseInt(versionLevels[0]), Integer.parseInt(versionLevels[1]));
85 } catch (Exception ex) {
86 throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
92 public int getMajor() {
96 public void setMajor(int major) {
100 public int getMinor() {
104 public void setMinor(int minor) {
108 public String getId() {
112 public void setId(String id) {
116 public String getName() {
120 public void setName(String name) {
124 public String getDescription() {
128 public void setDescription(String description) {
129 this.description = description;
132 public String getBaseId() {
136 public void setBaseId(String baseId) {
137 this.baseId = baseId;
140 public Date getCreationTime() {
144 public void setCreationTime(Date creationTime) {
145 this.creationTime = creationTime;
148 public Date getModificationTime() {
149 return modificationTime;
152 public void setModificationTime(Date modificationTime) {
153 this.modificationTime = modificationTime;
156 public VersionStatus getStatus() {
160 public void setStatus(VersionStatus status) {
161 this.status = status;
164 public VersionState getState() {
168 public void setState(VersionState state) {
172 public Version calculateNextCandidate() {
173 return new Version(major, minor + 1);
176 public Version calculateNextFinal() {
177 return new Version(major + 1, 0);
180 public boolean isFinal() {
181 return major != 0 && minor == 0;
184 public Map<String, Object> getAdditionalInfo() {
185 return additionalInfo;
188 public void setAdditionalInfo(Map<String, Object> additionalInfo) {
189 this.additionalInfo = additionalInfo;
193 public int hashCode() {
195 result = 31 * result + minor;
200 public boolean equals(Object obj) {
204 if (obj == null || getClass() != obj.getClass()) {
208 Version version = (Version) obj;
209 return major == version.major && minor == version.minor;
212 public int compateTo(Version other){
213 if (this.major>other.major) {
215 } else if(this.major<other.major){
217 } else if(this.major == other.major){
218 return Integer.compare(this.minor,other.minor);
224 public String toString() {
225 return name != null ? name : major + "." + minor;
229 public Version clone() {
230 Version version = new Version();
231 version.setStatus(this.getStatus());
232 version.setCreationTime(this.getCreationTime());
233 version.setName(this.getName());
234 version.setBaseId(this.getBaseId());
235 version.setMajor(this.major);
236 version.setMinor(this.minor);
237 version.setModificationTime(this.getModificationTime());
238 version.setDescription(this.description);
239 version.setId(this.getId());