// Rupos public methos
  @PluginVariant(
      requiredParameterLabels = {0, 1},
      variantLabel = "PerformanceDetailsUI")
  // @Plugin(name = "PerformanceDetailsUI", returnLabels = { "Performance Total" }, returnTypes = {
  // TotalPerformanceResult.class }, parameterLabels = {}, userAccessible = true)
  @UITopiaVariant(
      affiliation = "Department of Computer Science University of Pisa",
      author = "R.Guanciale,G.Spagnolo et al.",
      email = "*****@*****.**",
      pack = "PetriNetReplayAnalysis")
  public TotalPerformanceResult getPerformanceDetails(
      UIPluginContext context, XLog log, Petrinet net) {

    // list possible classifiers
    List<XEventClassifier> classList = new ArrayList<XEventClassifier>(log.getClassifiers());
    // add default classifiers
    if (!classList.contains(XLogInfoImpl.RESOURCE_CLASSIFIER)) {
      classList.add(0, XLogInfoImpl.RESOURCE_CLASSIFIER);
    }
    //				if (!classList.contains(XLogInfoImpl.LIFECYCLE_TRANSITION_CLASSIFIER)){
    //					classList.add(0, XLogInfoImpl.LIFECYCLE_TRANSITION_CLASSIFIER);
    //				}
    if (!classList.contains(XLogInfoImpl.NAME_CLASSIFIER)) {
      classList.add(0, XLogInfoImpl.NAME_CLASSIFIER);
    }
    if (!classList.contains(XLogInfoImpl.STANDARD_CLASSIFIER)) {
      classList.add(0, XLogInfoImpl.STANDARD_CLASSIFIER);
    }

    Object[] availableEventClass = classList.toArray(new Object[classList.size()]);

    ReplayFitnessSetting setting = new ReplayFitnessSetting();
    suggestActions(setting, log, net);
    ReplayAnalysisUI ui = new ReplayAnalysisUI(setting);

    Marking marking;

    try {
      InitialMarkingConnection connection =
          context
              .getConnectionManager()
              .getFirstConnection(InitialMarkingConnection.class, context, net);
      marking = connection.getObjectWithRole(InitialMarkingConnection.MARKING);
    } catch (ConnectionCannotBeObtained ex) {
      context.log("Petri net lacks initial marking");
      context.getFutureResult(0).cancel(true);
      return null;
    }
    // Build and show the UI to make the mapping
    LogPetrinetAssUI mapping = new LogPetrinetAssUI(log, net, availableEventClass);
    // Create map or not according to the button pressed in the UI

    InteractionResult result = InteractionResult.NEXT;
    /*
     * The wizard loop.
     */
    boolean sem = true;
    /*
     * Show the current step.
     */
    int currentStep = 0;

    // TODO: Insert plugin description
    String label =
        "<html>"
            + "<h2>PetriNetReplayAnalysis: Performance metrics <br/></h2><p>"
            + "This package implement the algorithms described on this article<sup>1</sup>. <br/><br/>"
            + "This plugin replayed a log events on the bussiness process model. "
            + "The model is a Petri net and reproduces a bussiness process. "
            + "<br/>The result of performance plugin is a set Petri nets with annoted for all place sojourn,wait "
            + "and synchronization time for all trace log and all Petri net place,<br/> and annoted them on the Petri net. <br></p>"
            + "<br/><p>The user guide for this plugin is <a href=\"https://svn.win.tue.nl/repos/prom/Documentation/\">here "
            + "</a>https://svn.win.tue.nl/repos/prom/Documentation/PetriNetReplayAnalysis.pdf</p>"
            + "<br/><p>The code for this plugin is <a href=\"https://github.com/rupos-it/PetriNetReplayAnalysis\">"
            + "here </a>https://github.com/rupos-it/PetriNetReplayAnalysis</p>"
            + "<p><span style=\"font-size:8px;\"><sup>1</sup>Roberto Bruni, AndreaCorradini, Gianluigi Ferrari, "
            + "Tito Flagella, Roberto Guanciale, and Giorgio O. Spagnolo. Applying process analysis to the italian "
            + "egovernment enterprise architecture. <br/>In <i>Proceedings of WS-FM 2011,8th International Workshop on "
            + "Web Services and Formal Methods</i> <ahref=\"http://goo.gl/EmiDJ\">http://goo.gl/EmiDJ</a></span></p>"
            + " </html>";

    JComponent intro = new PanelIntroPlugin(label);
    JComponent config = ui.initComponents();
    result = context.showWizard("Select Type Mapping", true, false, intro);

    currentStep++;
    boolean d = false;
    while (sem) {

      switch (result) {
        case NEXT:
          /*
           * Show the next step.
           */

          if (currentStep == 0) {
            currentStep = 1;
          }
          if (currentStep == 1) {
            result = context.showWizard("Mapping Petrinet - Log", false, false, mapping);
            currentStep++;
            d = true;
            break;
          }
          if (currentStep == 2) {
            d = false;

            result = context.showWizard("Configure Performance Settings", false, true, config);
            ui.setWeights();
          }

          break;
        case PREV:
          /*
           * Move back.
           */
          if (d) {
            currentStep--;
            d = false;
          }
          if (currentStep == 1) {
            result = context.showWizard("Select Type Mapping", true, false, intro);
            // mapping = lpcfui=null;//.initComponents();
          }
          if (currentStep == 2) {
            result = context.showWizard("Mapping Petrinet - Log", false, false, mapping);
            currentStep--;
          }

          break;
        case FINISHED:
          /*
           * Return  final step.
           */
          map = getmap(mapping.getMap());
          sem = false;
          break;
        default:
          /*
           * Should not occur.
           */
          context.log("press Cancel");
          context.log("replay is not performed because not enough parameter is submitted");
          context.getFutureResult(0).cancel(true);
          return null;
      }
    }

    TotalPerformanceResult total =
        getPerformanceDetails(context, log, net, setting, marking, mapping.getSelectedClassifier());

    return total;
  }
  public BPMNDiagram mineBPMNModel(final UIPluginContext context, XLog rawlog)
      throws ExecutionCancelledException {
    BPMNSubProcessMiner subProcessMiner = new BPMNSubProcessMiner();

    LogOptimizer logOptimizer = new LogOptimizer();
    XLog optimizedLog = logOptimizer.optimizeLog(rawlog);
    rawlog = optimizedLog;

    UIPluginContext pluginContext = context;
    pluginContext.getProgress().setIndeterminate(true);
    pluginContext.getProgress().setCaption("BPMN Miner");

    pluginContext.getProgress().setIndeterminate(false);
    pluginContext.getProgress().setMinimum(0);
    pluginContext.getProgress().setMaximum(20); // concModel.getEntities().size() + 2);
    pluginContext.getProgress().setValue(1);

    EntityDiscoverer_UI entityDiscoverer_ui = new EntityDiscoverer_UI();
    EntityDiscoverer entityDiscoverer = entityDiscoverer_ui.getEntityDiscoverer();

    // Select Miner
    SelectMinerUI selectMinerUI = new SelectMinerUI();
    SelectMinerResult guiResult = selectMinerUI.showGUI();

    Integer algorithm = 1;

    // discover the ER model
    DiscoverERModel_UI ERmodel = new DiscoverERModel_UI();
    ConceptualModel concModel = null;

    // ui choose artifacts from entities
    // ------------------------------------------
    List<Entity> groupEntities = new ArrayList<Entity>();
    List<Entity> candidatesEntities = new ArrayList<Entity>();
    List<Entity> selectedEntities = new ArrayList<Entity>();

    try {
      concModel = ERmodel.showGUI(rawlog, algorithm);

      if (concModel != null) {
        System.out.println("Discovering groupEntities...");
        groupEntities = entityDiscoverer_ui.discoverGroupEntities(concModel, false);
        System.out.println("groupEntities discovered");

        System.out.println("Discovering candidatesEntities...");
        candidatesEntities =
            entityDiscoverer_ui.discoverCandidatesEntities(concModel, groupEntities);
        System.out.println("candidatesEntities discovered");

        System.out.println("Discovering selectedEntities...");
        selectedEntities =
            entityDiscoverer_ui.selectEntities(groupEntities, candidatesEntities, false);
        System.out.println("selectedEntities discovered");
      }
    } catch (NoEntityException nee) {
    }

    StringBuilder sb = new StringBuilder();
    if (groupEntities != null) {
      sb.append("groupEntities:\n");
      for (Entity e : groupEntities) {
        sb.append(e.toString()).append("\n");
      }
    }
    if (candidatesEntities != null) {
      sb.append("candidatesEntities:\n");
      for (Entity e : candidatesEntities) {
        sb.append(e.toString()).append("\n");
      }
    }
    if (selectedEntities != null) {
      sb.append("selectedEntities:\n");
      for (Entity e : selectedEntities) {
        sb.append(e.toString()).append("\n");
      }
    }
    System.out.println(sb.toString());

    BPMNDiagram model =
        subProcessMiner.mineBPMNModel(
            context,
            rawlog,
            false,
            guiResult,
            algorithm,
            entityDiscoverer,
            concModel,
            groupEntities,
            candidatesEntities,
            selectedEntities,
            true);

    return model;
  }