Added oparent to sdc main
[sdc.git] / openecomp-be / tools / zusammen-tools / src / main / java / org / openecomp / core / tools / commands / SetHealingFlag.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 - 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.core.tools.commands;
22
23 import static org.openecomp.core.tools.commands.CommandName.RESET_OLD_VERSION;
24
25 import com.datastax.driver.core.ResultSet;
26 import java.util.ArrayList;
27 import org.apache.commons.cli.CommandLine;
28 import org.apache.commons.cli.Option;
29 import org.openecomp.core.tools.store.HealingHandler;
30 import org.openecomp.core.tools.store.VersionCassandraLoader;
31 import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
32
33
34 /**
35  * Created by ayalaben on 10/15/2017
36  */
37 public class SetHealingFlag extends Command {
38
39     private static final String VERSION_OPTION = "v";
40
41     SetHealingFlag() {
42         options.addOption(Option.builder(VERSION_OPTION).hasArg().argName("version").desc("release version").build());
43     }
44
45     @Override
46     public boolean execute(String[] args) {
47         CommandLine cmd = parseArgs(args);
48         String oldVersion = cmd.hasOption(VERSION_OPTION) ? cmd.getOptionValue(VERSION_OPTION) : null;
49
50         VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
51         ResultSet listItemVersion = versionCassandraLoader.listItemVersion();
52
53         ArrayList<HealingEntity> healingEntities = new ArrayList<>();
54
55         listItemVersion.iterator().forEachRemaining(entry -> healingEntities.add(new HealingEntity(entry.getString(0),
56                 entry.getString(1), entry.getString(2), true, oldVersion)));
57
58         HealingHandler healingHandler = new HealingHandler();
59         healingHandler.populateHealingTable(healingEntities);
60
61         return true;
62     }
63
64     @Override
65     public CommandName getCommandName() {
66         return RESET_OLD_VERSION;
67     }
68 }