2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.core.tools.commands;
19 import static org.openecomp.core.tools.commands.CommandName.SET_HEAL_BY_ITEM_VERSION;
21 import com.datastax.driver.core.ResultSet;
23 import java.util.List;
24 import java.util.stream.Collectors;
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.commons.cli.Option;
28 import org.openecomp.core.tools.store.HealingHandler;
29 import org.openecomp.core.tools.store.VersionCassandraLoader;
30 import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
31 import org.openecomp.sdc.logging.api.Logger;
32 import org.openecomp.sdc.logging.api.LoggerFactory;
34 public class SetHealingFlagByItemVersionCommand extends Command {
36 private static final Logger LOGGER = LoggerFactory.getLogger(SetHealingFlagByItemVersionCommand.class);
37 private static final String ITEM_ID_OPTION = "i";
38 private static final String VERSION_ID_OPTION = "v";
39 private static final String PROJECT_OPTION = "o";
41 SetHealingFlagByItemVersionCommand() {
42 options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id")
43 .desc("id of the item to reset healing flag, mandatory").build());
44 options.addOption(Option.builder(VERSION_ID_OPTION).hasArg().argName("version_id")
45 .desc("id of the version to delete from public, mandatory").build());
46 options.addOption(Option.builder(PROJECT_OPTION).hasArg().argName("old_project_version")
47 .desc("old project version, mandatory").build());
51 public boolean execute(String[] args) {
52 CommandLine cmd = parseArgs(args);
53 if (!(cmd.hasOption(ITEM_ID_OPTION) && cmd.hasOption(VERSION_ID_OPTION) && cmd.hasOption(PROJECT_OPTION))) {
54 LOGGER.error("Arguments i, v and o are mandatory");
57 String itemId = cmd.getOptionValue(ITEM_ID_OPTION);
58 String versionId = cmd.getOptionValue(VERSION_ID_OPTION);
59 String projectVersion = cmd.getOptionValue(PROJECT_OPTION);
61 VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
62 ResultSet listItemVersion = versionCassandraLoader.listItemVersion();
64 List<HealingEntity> healingEntities = listItemVersion.all().stream().filter(
65 entry -> (entry.getString("item_id").equals(itemId)
66 && entry.getString("version_id").equals(versionId))).map(entry ->
67 new HealingEntity(entry.getString("space"), entry.getString("item_id"),
68 entry.getString("version_id"), true, projectVersion)).collect(Collectors.toList());
70 HealingHandler healingHandler = new HealingHandler();
71 healingHandler.populateHealingTable(healingEntities);
77 public CommandName getCommandName() {
78 return SET_HEAL_BY_ITEM_VERSION;