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

org.ow2.bonita.textui.Console Maven / Gradle / Ivy

package org.ow2.bonita.textui;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

import org.ow2.bonita.facade.ManagementAPI;
import org.ow2.bonita.facade.QueryDefinitionAPI;
import org.ow2.bonita.facade.def.element.BusinessArchive;
import org.ow2.bonita.facade.def.majorElement.ProcessDefinition;
import org.ow2.bonita.facade.exception.ProcessNotFoundException;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.util.AccessorUtil;
import org.ow2.bonita.util.BonitaException;
import org.ow2.bonita.util.BusinessArchiveFactory;
import org.ow2.bonita.util.ExceptionManager;
import org.ow2.bonita.util.Misc;
import org.ow2.bonita.util.SimpleCallbackHandler;
import org.ow2.bonita.util.StandardCallbackHandler;

public class Console {

  public static final String DEPLOY = "deploy";
  public static final String UNDEPLOY = "undeploy";
  public static final String ACTION_USAGE = "Action must be '" + DEPLOY + "' or '" + UNDEPLOY + "' ";
  public static final String USAGE = "Usage: " + Console.class + DEPLOY + " | " + UNDEPLOY
    + " Ressources LoginConfig" + Misc.LINE_SEPARATOR + "Ressources: bar | processId";
  private static final Logger LOG = Logger.getLogger(Console.class.getName());
  
  protected Console() {
  }

  public static void deploy(final BusinessArchive businessArchive) throws BonitaException, IOException {
    Misc.checkArgsNotNull(businessArchive);
    ManagementAPI managementAPI = null;
    managementAPI = AccessorUtil.getAPIAccessor().getManagementAPI();
    managementAPI.deploy(businessArchive);
  }

  public static void undeploy(final String processId) throws BonitaException {
    Misc.checkArgsNotNull(processId);
    ManagementAPI managementAPI = null;
    QueryDefinitionAPI queryDefinitionAPI = null;
    managementAPI = AccessorUtil.getAPIAccessor().getManagementAPI();
    queryDefinitionAPI = AccessorUtil.getAPIAccessor().getQueryDefinitionAPI();

    ProcessDefinition processDefinition = queryDefinitionAPI.getLastProcess(processId);
    if (processDefinition == null) {
    	String message = ExceptionManager.getInstance().getMessage("btui_C_1", processId);
        throw new ProcessNotFoundException("btui_C_1", message);
    }
    ProcessDefinitionUUID processDefinitionUUID = processDefinition.getUUID();
    managementAPI.disable(processDefinitionUUID);
  }

  public static void main(String... args) throws LoginException, BonitaException, IOException, ClassNotFoundException {
    if (args == null || (args.length != 3 && args.length != 6)) {
      LOG.severe(USAGE);
      throw new IllegalArgumentException(USAGE);
    }
    final Misc.NullCheckResult result = Misc.findNull((Object[]) args);

    if (result.hasNull()) {
      LOG.severe(USAGE);
      throw new IllegalArgumentException("Some parameters are null: " + Misc.componentsToString(args, false));
    }
    String userName = null;
    String password = null;
    LoginContext loginContext = null;
    //final String environnement = args[0];
    final String action = args[0];
    final String loginConfig = args[2];
    if (args.length == 5) {
      userName = args[3];
      password = args[4];
    }
    if ((userName != null) && (password != null)) {
      loginContext = new LoginContext(loginConfig, new SimpleCallbackHandler(userName, password));
    } else {
      loginContext = new LoginContext(loginConfig, new StandardCallbackHandler());
    }
    loginContext.login();
    if (action.equals(DEPLOY)) {
      final String barFile = args[1];
      deploy(BusinessArchiveFactory.getBusinessArchive(new File(barFile)));
    } else if (action.equals(UNDEPLOY)) {
      final String processId = args[1];
      undeploy(processId);
    } else {
      LOG.severe(ACTION_USAGE);
      throw new IllegalArgumentException(ACTION_USAGE);
    }
    loginContext.logout();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy