Java tutorial
/** * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium) * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package eu.itesla_project.online.tools; import com.google.auto.service.AutoService; import eu.itesla_project.commons.tools.Command; import eu.itesla_project.commons.tools.Tool; import eu.itesla_project.modules.online.OnlineConfig; import eu.itesla_project.modules.online.OnlineDb; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import java.util.List; /** * * @author Quinary <itesla@quinary.com> */ @AutoService(Tool.class) public class ListOnlineWorkflowStatesTool implements Tool { private static Command COMMAND = new Command() { @Override public String getName() { return "list-online-workflow-states"; } @Override public String getTheme() { return Themes.ONLINE_WORKFLOW; } @Override public String getDescription() { return "List stored states ids of an online workflow"; } @Override public Options getOptions() { Options options = new Options(); options.addOption(Option.builder().longOpt("workflow").desc("the workflow id").hasArg().required() .argName("ID").build()); return options; } @Override public String getUsageFooter() { return null; } }; @Override public Command getCommand() { return COMMAND; } @Override public void run(CommandLine line) throws Exception { OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); String workflowId = line.getOptionValue("workflow"); List<Integer> storedStates = onlinedb.listStoredStates(workflowId); if (storedStates != null) { if (!storedStates.isEmpty()) { System.out.println("Stored States = " + storedStates.toString()); } else System.out.println("No stores states for this workflow"); } else System.out.println("No stores states for this workflow"); onlinedb.close(); } }