re base code
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / main / UpdateIsVnfMenu.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.asdctool.main;
22
23 import org.openecomp.sdc.asdctool.impl.UpdatePropertyOnVertex;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.common.log.wrappers.Logger;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public class UpdateIsVnfMenu {
34
35         private static Logger log = Logger.getLogger(UpdateIsVnfMenu.class.getName());
36
37         private static void usageAndExit() {
38                 updateIsVnfTrueUsage();
39                 System.exit(1);
40         }
41
42         private static void updateIsVnfTrueUsage() {
43                 System.out.println(
44                                 "Usage: updateIsVnfTrue <titan.properties> <systemServiceName1,systemServiceName2,...,systemServiceNameN>");
45         }
46
47         public static void main(String[] args) {
48
49                 if (args == null || args.length < 1) {
50                         usageAndExit();
51                 }
52
53                 UpdatePropertyOnVertex updatePropertyOnVertex = new UpdatePropertyOnVertex();
54                 String operation = args[0];
55
56                 switch (operation.toLowerCase()) {
57
58                 case "updateisvnftrue":
59                         boolean isValid = verifyParamsLength(args, 3);
60                         if (false == isValid) {
61                                 updateIsVnfTrueUsage();
62                                 System.exit(1);
63                         }
64
65                         Map<String, Object> keyValueToSet = new HashMap<>();
66                         keyValueToSet.put(GraphPropertiesDictionary.IS_VNF.getProperty(), true);
67
68                         List<Map<String, Object>> orCriteria = buildCriteriaFromSystemServiceNames(args[2]);
69                         Integer updatePropertyOnServiceAtLeastCertified = updatePropertyOnVertex
70                                         .updatePropertyOnServiceAtLeastCertified(args[1], keyValueToSet, orCriteria);
71
72                         if (updatePropertyOnServiceAtLeastCertified == null) {
73                                 System.exit(2);
74                         } else if (updatePropertyOnServiceAtLeastCertified.intValue() >= 0) {
75                                 log.debug("Number of updated services is {}",updatePropertyOnServiceAtLeastCertified.intValue());
76                                 System.exit(0);
77                         }
78
79                         break;
80                 default:
81                         usageAndExit();
82                 }
83
84         }
85
86         private static List<Map<String, Object>> buildCriteriaFromSystemServiceNames(String systemList) {
87
88                 List<Map<String, Object>> systemNames = new ArrayList<>();
89
90                 String[] split = systemList.split(",");
91                 if (split != null) {
92                         for (String systemName : split) {
93                                 systemName = systemName.trim();
94
95                                 Map<String, Object> map = new HashMap();
96                                 map.put(GraphPropertiesDictionary.SYSTEM_NAME.getProperty(), systemName);
97                                 map.put(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Service.getName());
98
99                                 systemNames.add(map);
100                         }
101                 }
102
103                 return systemNames;
104         }
105
106         private static boolean verifyParamsLength(String[] args, int i) {
107                 if (args == null) {
108                         if (i > 0) {
109                                 return false;
110                         }
111                         return true;
112                 }
113
114                 if (args.length >= i) {
115                         return true;
116                 }
117                 return false;
118         }
119
120 }