2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.openecomp.core.tools.commands;
23 import static org.openecomp.core.tools.commands.CommandName.DELETE_PUBLIC_VERSION;
25 import com.amdocs.zusammen.datatypes.Id;
26 import com.amdocs.zusammen.datatypes.SessionContext;
27 import com.amdocs.zusammen.datatypes.UserInfo;
28 import org.apache.commons.cli.CommandLine;
29 import org.apache.commons.cli.Option;
30 import org.openecomp.core.zusammen.db.ZusammenConnector;
31 import org.openecomp.core.zusammen.db.ZusammenConnectorFactory;
32 import org.openecomp.sdc.logging.api.Logger;
33 import org.openecomp.sdc.logging.api.LoggerFactory;
35 public class DeletePublicVersionCommand extends Command {
37 private static final Logger LOGGER = LoggerFactory.getLogger(DeletePublicVersionCommand.class);
38 private static final String ITEM_ID_OPTION = "i";
39 private static final String VERSION_ID_OPTION = "v";
41 DeletePublicVersionCommand() {
42 options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id")
43 .desc("id of the item to delete from public, 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());
49 public boolean execute(String[] args) {
50 CommandLine cmd = parseArgs(args);
51 if (!cmd.hasOption(ITEM_ID_OPTION) || !cmd.hasOption(VERSION_ID_OPTION)) {
52 LOGGER.error("Arguments i and v are mandatory");
55 String itemId = cmd.getOptionValue(ITEM_ID_OPTION);
56 String versionId = cmd.getOptionValue(VERSION_ID_OPTION);
58 SessionContext context = createSessionContext();
59 ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface();
62 zusammenConnector.cleanVersion(context, new Id(itemId), new Id(versionId));
63 } catch (Exception e) {
64 LOGGER.error(String.format("Error occurred while deleting item %s version %s from public space", itemId,
71 public CommandName getCommandName() {
72 return DELETE_PUBLIC_VERSION;
75 private static SessionContext createSessionContext() {
76 SessionContext sessionContext = new SessionContext();
77 sessionContext.setUser(new UserInfo("public"));
78 sessionContext.setTenant("dox");
79 return sessionContext;