All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.common.script.node.IdentifyStateCommand Maven / Gradle / Ivy

package org.bidib.wizard.common.script.node;

import java.util.Scanner;

import org.bidib.jbidibc.messages.enums.IdentifyState;
import org.bidib.wizard.api.context.ApplicationContext;
import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.api.service.console.ConsoleService;
import org.bidib.wizard.common.script.AbstractScriptCommand;
import org.bidib.wizard.common.script.DefaultScriptContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IdentifyStateCommand extends AbstractScriptCommand {

    private static final Logger LOGGER = LoggerFactory.getLogger(IdentifyStateCommand.class);

    public static final String KEY = "identifyState";

    public static final String HELP =
        CODE_BLOCK_START + KEY + prepareHelpHtml(" ") + DIV_END
            + prepareHelpHtml("\nSet the identify state of the node.");

    private IdentifyState identifyState;

    public IdentifyStateCommand(ConsoleService consoleService) {
        super(consoleService, KEY, HELP);
    }

    @Override
    public void parse(String commandLine) {
        try (Scanner scanner = new Scanner(commandLine)) {
            if (!getKey().equals(scanner.next())) {
                LOGGER.info("Invalid command is scanned, key does not match.");
            }
            line = commandLine.trim();

            identifyState = IdentifyState.fromString(scanner.next().toUpperCase());
        }

        LOGGER.info("Parsed command, identifyState: {}", identifyState);
    }

    @Override
    protected void internalExecute(T scripting, ApplicationContext context) {
        LOGGER.info("Set the identify state, identifyState: {}", identifyState);

        final NodeInterface node = context.get(DefaultScriptContext.KEY_SELECTED_NODE, NodeInterface.class);
        scripting.setIdentifyState(node.getUniqueId(), identifyState);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy