public String toShortString() {
    StringBuilder builder = new StringBuilder();
    builder.append("CompositeSearchResult [containingConcept=");
    builder.append(containingConcept != null ? containingConcept.getNid() : null);

    if (matchingComponentNid_ != 0) {
      builder.append(", matchingComponentNid_=");
      builder.append(matchingComponentNid_);
    }

    builder.append(", bestScore=");
    builder.append(bestScore);

    if (matchingComponents != null && matchingComponents.size() > 0) {
      builder.append(", matchingComponents=");
      List<Integer> matchingComponentNids = new ArrayList<>();
      for (ComponentVersionBI matchingComponent : matchingComponents) {
        matchingComponentNids.add(matchingComponent != null ? matchingComponent.getNid() : null);
      }
      builder.append(matchingComponentNids);
    }

    builder.append("]");
    return builder.toString();
  }
  private void initiateWorkflow() {
    if (!validate("Failed initiating workflow")) {
      return;
    }

    String description = generatedComponentDescriptionLabel.getText();
    WorkflowProcess process = workflowProcessesComboBox.getSelectionModel().getSelectedItem();

    Map<String, String> map = getOutputVariablesMap();

    LOG.debug(
        "Invoking createNewConceptWorkflowRequest(preferredDescription=\""
            + description
            + "\", conceptUuid=\""
            + componentOrConcept.getPrimordialUuid().toString()
            + "\", processName=\""
            + process
            + "\")");
    ProcessInstanceCreationRequestI createdRequest = null;

    try {
      createdRequest =
          getWorkflowService()
              .createNewComponentWorkflowRequest(
                  description, componentOrConcept.getPrimordialUuid(), process.getText(), map);
    } catch (Exception e) {
      LOG.error("Unexpected error creating request", e);
    }

    if (createdRequest == null) {
      String title = "Workflow Initiation Failed";
      String msg =
          "Failed creating WorkflowProcessModel "
              + workflowProcessesComboBox.getSelectionModel().getSelectedItem()
              + " (service call returned null)";
      String details = "Component: " + description + "\n" + map;
      AppContext.getCommonDialogs().showErrorDialog(title, msg, details, workflowInitiationView);
    } else {
      LOG.debug("Created ProcessInstanceCreationRequestI: " + createdRequest);

      AppContext.getCommonDialogs()
          .showInformationDialog(
              "Workflow initiation succeeded",
              "Created "
                  + workflowProcessesComboBox.getSelectionModel().getSelectedItem()
                  + "\nFor componentId "
                  + componentOrConcept.getPrimordialUuid());

      doCancel();
    }
  }
  public CompositeSearchResult(ComponentVersionBI matchingComponent, float score) {
    this.matchingComponents.add(matchingComponent);
    this.bestScore = score;
    // matchingComponent may be null, if the match is not on our view path...
    if (matchingComponent == null) {
      throw new RuntimeException(
          "Please call the constructor that takes a nid, if matchingComponent is null...");
    } else {
      this.matchingComponentNid_ = matchingComponent.getNid();
    }
    this.containingConcept =
        OTFUtility.getConceptVersion(matchingComponent.getAssociatedConceptNid());

    // TODO - we need to evaluate / design proper behavior for how view coordinate should work with
    // search
    // default back to just using this for the moment, rather than what OTFUtility says.
    // this.containingConcept = OTFUtility.getConceptVersion(matchingComponent.getConceptNid(), vc);
  }
  public String toStringWithDescriptions() {
    StringBuilder builder = new StringBuilder();
    builder.append("CompositeSearchResult [containingConcept=");
    String containingConceptDesc = null;
    if (containingConcept != null) {
      try {
        containingConceptDesc =
            OTFUtility.getDescriptionIfConceptExists(containingConcept.getConceptNid());
      } catch (Exception e) {
        containingConceptDesc = "{nid=" + containingConcept.getConceptNid() + "}";
      }
    }
    builder.append(containingConceptDesc);

    builder.append(", matchingComponentNid_=");
    builder.append(matchingComponentNid_);

    String matchingComponentDesc = null;
    if (matchingComponentNid_ != 0) {
      try {
        ComponentChronicleBI<?> cc = OTFUtility.getComponentChronicle(matchingComponentNid_);
        matchingComponentDesc = cc.toUserString();
      } catch (Exception e) {
        // NOOP
      }
    }
    if (matchingComponentDesc != null) {
      builder.append(", matchingComponent=");
      builder.append(matchingComponentDesc);
    }

    builder.append(", bestScore=");
    builder.append(bestScore);

    builder.append(", numMatchingComponents=");
    List<Integer> matchingComponentNids = new ArrayList<>();
    for (ComponentVersionBI matchingComponent : getMatchingComponents()) {
      matchingComponentNids.add(matchingComponent != null ? matchingComponent.getNid() : null);
    }
    builder.append(matchingComponentNids);

    builder.append("]");
    return builder.toString();
  }
  public String toLongString() {
    StringBuilder builder = new StringBuilder();
    builder.append("CompositeSearchResult [containingConcept=");
    builder.append(containingConcept);
    builder.append(", matchingComponentNid_=");
    builder.append(matchingComponentNid_);
    builder.append(", bestScore=");
    builder.append(bestScore);
    builder.append(", getMatchingComponents()=");
    List<String> matchingComponentDescs = new ArrayList<>();
    for (ComponentVersionBI matchingComponent : getMatchingComponents()) {
      matchingComponentDescs.add(
          matchingComponent != null ? matchingComponent.toUserString() : null);
    }
    builder.append(matchingComponentDescs);

    builder.append("]");
    return builder.toString();
  }
 /** A convenience method to get string values from the matching Components */
 public List<String> getMatchingStrings() {
   ArrayList<String> strings = new ArrayList<>();
   if (matchingComponents.size() == 0) {
     if (containingConcept == null) {
       strings.add("Match to NID (not on path):" + matchingComponentNid_);
     } else {
       throw new RuntimeException("Unexpected");
     }
   }
   for (ComponentVersionBI cc : matchingComponents) {
     if (cc instanceof DescriptionAnalogBI) {
       strings.add(((DescriptionAnalogBI<?>) cc).getText());
     } else if (cc instanceof ConceptVersionBI) {
       // This means they matched on a UUID or other ID lookup.
       // Return UUID for now - matches on other ID types will be handled differently
       // in the near future - so ignore the SCTID case for now.
       strings.add(cc.getPrimordialUuid().toString());
     } else {
       strings.add("ERROR: No string extractor available for " + cc.getClass().getName());
     }
   }
   return strings;
 }
  public void setComponent(ComponentVersionBI passedComponentOrConcept) {
    if (componentOrConcept != null) {
      String msg =
          "Cannot reset componentOrConcept from "
              + componentOrConcept.getNid()
              + " to "
              + passedComponentOrConcept.getNid();
      LOG.error(msg);
      throw new RuntimeException(msg);
    }

    componentOrConcept = passedComponentOrConcept;
    if (componentOrConcept instanceof ConceptVersionBI) {
      LOG.debug(
          "Set concept nid="
              + passedComponentOrConcept.getNid()
              + ", uuid="
              + passedComponentOrConcept.getPrimordialUuid()
              + ", desc="
              + passedComponentOrConcept.toUserString());
    } else {
      LOG.debug(
          "Set componentOrConcept nid="
              + passedComponentOrConcept.getNid()
              + ", uuid="
              + passedComponentOrConcept.getPrimordialUuid()
              + ", desc="
              + OTFUtility.getDescription(passedComponentOrConcept.getNid()));
    }

    try {
      loadContents();
    } catch (IOException e) {
      LOG.error("Unexpected", e);
      throw new RuntimeException(e);
    }
  }