Catalog alignment
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / utils / GroupUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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.openecomp.sdc.be.model.utils;
22
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;
27
28 public class GroupUtils {
29
30         public static boolean isVfModule(String type) {
31                 return type.equals(Constants.DEFAULT_GROUP_VF_MODULE);
32         }
33         
34            /**
35      * The version of the group/poloces is an integer. In order to support BC, we might get a version in a float format.
36      *
37      * @param promoteVersion
38      * @return
39      */
40         
41         public static String updateVersion(PromoteVersionEnum promoteVersion, String currentVesion) {
42             if(StringUtils.isEmpty(currentVesion)){
43                 return "0.0";
44             }
45         String newVersion = currentVesion;
46          switch (promoteVersion){
47          case MINOR:
48              newVersion = GroupUtils.increaseMainorVersion(currentVesion);
49              break;
50          case MAJOR:
51              newVersion = GroupUtils.increaseMajorVersion(currentVesion);
52              break;
53          default:
54              break;
55          }     
56          return newVersion;
57     }
58     
59         private static String increaseMajorVersion(String version) {
60
61        String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
62        Integer majorVersion = Integer.parseInt(versionParts[0]);
63        
64             
65        Integer mainorVersion = versionParts.length > 1?Integer.parseInt(versionParts[1]):0;       
66       
67        if(mainorVersion > 0 || majorVersion == 0){
68            majorVersion++;
69        }
70        return String.valueOf(majorVersion);
71
72    }
73    
74         private static String increaseMainorVersion(String version) {
75
76        String[] versionParts = version.split(ToscaElementLifecycleOperation.VERSION_DELIMITER_REGEXP);
77       
78        Integer mainorVersion = versionParts.length > 1?Integer.parseInt(versionParts[1]):0;
79
80        mainorVersion++;
81
82        return versionParts[0] + ToscaElementLifecycleOperation.VERSION_DELIMITER + String.valueOf(mainorVersion);
83
84    }
85 }