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=========================================================
20 package org.openecomp.sdc.be.model.utils;
22 import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
23 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
24 import org.openecomp.sdc.common.api.Constants;
25 import org.springframework.util.StringUtils;
27 public class GroupUtils {
29 public static boolean isVfModule(String type) {
30 return type.equals(Constants.DEFAULT_GROUP_VF_MODULE);
34 * The version of the group/poloces is an integer. In order to support BC, we might get a version in a float format.
36 * @param promoteVersion
39 public static String updateVersion(PromoteVersionEnum promoteVersion, String currentVesion) {
40 if (StringUtils.isEmpty(currentVesion)) {
43 String newVersion = currentVesion;
44 switch (promoteVersion) {
46 newVersion = GroupUtils.increaseMainorVersion(currentVesion);
49 newVersion = GroupUtils.increaseMajorVersion(currentVesion);
57 private static String increaseMajorVersion(String version) {
58 String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
59 Integer majorVersion = Integer.parseInt(versionParts[0]);
60 Integer mainorVersion = versionParts.length > 1 ? Integer.parseInt(versionParts[1]) : 0;
61 if (mainorVersion > 0 || majorVersion == 0) {
64 return String.valueOf(majorVersion);
67 private static String increaseMainorVersion(String version) {
68 String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
69 Integer mainorVersion = versionParts.length > 1 ? Integer.parseInt(versionParts[1]) : 0;
71 return versionParts[0] + ToscaElementLifecycleOperation.VERSION_DELIMITER + String.valueOf(mainorVersion);