2 * ============LICENSE_START=======================================================
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
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.be.model.utils;
23 import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
24 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
25 import org.openecomp.sdc.common.api.Constants;
26 import org.springframework.util.StringUtils;
28 public class GroupUtils {
30 public static boolean isVfModule(String type) {
31 return type.equals(Constants.DEFAULT_GROUP_VF_MODULE);
35 * The version of the group/poloces is an integer. In order to support BC, we might get a version in a float format.
37 * @param promoteVersion
41 public static String updateVersion(PromoteVersionEnum promoteVersion, String currentVesion) {
42 if(StringUtils.isEmpty(currentVesion)){
45 String newVersion = currentVesion;
46 switch (promoteVersion){
48 newVersion = GroupUtils.increaseMainorVersion(currentVesion);
51 newVersion = GroupUtils.increaseMajorVersion(currentVesion);
59 private static String increaseMajorVersion(String version) {
61 String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
62 Integer majorVersion = Integer.parseInt(versionParts[0]);
65 Integer mainorVersion = versionParts.length > 1?Integer.parseInt(versionParts[1]):0;
67 if(mainorVersion > 0 || majorVersion == 0){
70 return String.valueOf(majorVersion);
74 private static String increaseMainorVersion(String version) {
76 String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
78 Integer mainorVersion = versionParts.length > 1?Integer.parseInt(versionParts[1]):0;
82 return versionParts[0] + ToscaElementLifecycleOperation.VERSION_DELIMITER + String.valueOf(mainorVersion);