1 package org.openecomp.sdc.versioning.impl;
3 import org.openecomp.core.utilities.CommonMethods;
4 import org.openecomp.sdc.versioning.VersionCalculator;
5 import org.openecomp.sdc.versioning.dao.types.Version;
6 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
7 import org.openecomp.sdc.versioning.types.VersionCreationMethod;
9 import java.util.HashSet;
12 public class MajorVersionCalculatorImpl implements VersionCalculator {
13 private static final String INITIAL_VERSION = "1.0";
14 private static final String VERSION_STRING_VIOLATION_MSG =
15 "Version string must be in the format of: {integer}.{integer}";
18 public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
20 if (baseVersion == null) {
21 return INITIAL_VERSION;
24 String[] versionLevels = baseVersion.split("\\.");
25 if (versionLevels.length != 2) {
26 throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
29 int index = Integer.parseInt(versionLevels[0]);
31 versionLevels[0] = Integer.toString(index);
32 versionLevels[1] = "0";
34 return CommonMethods.arrayToSeparatedString(versionLevels, '.');
38 public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
39 String optionalVersion;
40 Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
41 if(version.getStatus().equals(VersionStatus.Certified)) {
43 optionalVersion = calculate(version.getName(), VersionCreationMethod.major);
44 if (!existingVersions.contains(optionalVersion)) {
45 optionalCreationMethods.add(VersionCreationMethod.major);
47 } catch (IllegalArgumentException iae) {
48 //not a valid creation method.
51 version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);