/**
   * Adds a dialect to the <code>initialVariantMap</code>.
   *
   * @param dialectSpec the <code>ConceptSpec</code> representing the dialect concept
   * @param viewCoordinate the view coordinate specifying which versions are active or inactive
   * @param varientsSpec the <code>ConceptSpec</code> representing the dialect refex concept
   * @param terminologySnapshot the terminologySnapshot to use for getting component versions
   * @param initialVariantMap the map to udpate
   * @throws ContradictionException if more than one version is found for a given position or view
   *     coordinate
   * @throws IOException signals that an I/O exception has occurred
   */
  private static void addDialect(
      ConceptSpec dialectSpec,
      ViewCoordinate viewCoordinate,
      ConceptSpec varientsSpec,
      TerminologySnapshotDI terminologySnapshot,
      HashMap<Integer, Map<String, String>> initialVariantMap)
      throws ContradictionException, IOException {
    ConceptVersionBI dialectC = dialectSpec.getStrict(viewCoordinate);
    ConceptVersionBI variantTextRefsetC = varientsSpec.getStrict(viewCoordinate);

    Collection<? extends RefexChronicleBI<?>> dialectVarients =
        variantTextRefsetC.getRefexMembersActive(viewCoordinate);
    Map<String, String> variantDialectMap = new HashMap<String, String>();
    for (RefexChronicleBI<?> refex : dialectVarients) {
      if (RefexStringVersionBI.class.isAssignableFrom(refex.getClass())) {
        RefexStringVersionBI<?> dialectText =
            (RefexStringVersionBI<?>) refex.getVersion(viewCoordinate);
        if (dialectText != null) {
          RefexStringVersionBI<?> variantText =
              (RefexStringVersionBI<?>)
                  terminologySnapshot.getComponentVersion(dialectText.getReferencedComponentNid());
          variantDialectMap.put(variantText.getString1(), dialectText.getString1());
        }
      }
    }
    initialVariantMap.put(dialectC.getNid(), variantDialectMap);
  }
  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();
  }
  /**
   * Imports the dialect variant words into a map of the dialect to the dialect variant word. Checks
   * to see if the map is empty before loading, and will only load the words if the map is found to
   * be empty.
   *
   * @param dialectOrLanguageNid the dialect or language nid
   * @throws UnsupportedDialectOrLanguage indicates an unsupported dialect or language
   * @throws IOException signals that an I/O exception has occurred
   */
  private static void lazyInit(int dialectOrLanguageNid)
      throws UnsupportedDialectOrLanguage, IOException {
    if (variantMap == null) {
      initLock.lock();
      try {
        if (variantMap == null) {
          HashMap<Integer, Map<String, String>> initialVariantMap =
              new HashMap<Integer, Map<String, String>>();
          variantSetMap = new HashMap<Integer, Set<String>>();
          ViewCoordinate vc = AppContext.getService(TerminologyStoreDI.class).getMetadataVC();
          TerminologySnapshotDI ts =
              AppContext.getService(TerminologyStoreDI.class).getSnapshot(vc);

          ConceptVersionBI enVariantTextRefsetC =
              Language.EN_VARIANT_TEXT.getStrict(
                  AppContext.getService(TerminologyStoreDI.class).getMetadataVC());
          Collection<? extends RefexChronicleBI<?>> enVariants = enVariantTextRefsetC.getRefexes();
          Set<String> variantSet = new HashSet<String>();
          for (RefexChronicleBI<?> refex : enVariants) {
            if (RefexStringVersionBI.class.isAssignableFrom(refex.getClass())) {
              RefexStringVersionBI<?> variantText = (RefexStringVersionBI<?>) refex.getVersion(vc);
              if (variantText != null) {
                variantSet.add(variantText.getString1());
              }
            }
          }
          variantSetMap.put(Language.EN.getStrict(vc).getNid(), variantSet);

          addDialect(Language.EN_AU, vc, Language.EN_AU_TEXT_VARIANTS, ts, initialVariantMap);
          addDialect(Language.EN_CA, vc, Language.EN_CA_TEXT_VARIANTS, ts, initialVariantMap);
          addDialect(Language.EN_NZ, vc, Language.EN_NZ_TEXT_VARIANTS, ts, initialVariantMap);
          addDialect(Language.EN_UK, vc, Language.EN_UK_TEXT_VARIANTS, ts, initialVariantMap);
          addDialect(Language.EN_US, vc, Language.EN_US_TEXT_VARIANTS, ts, initialVariantMap);
          DialectHelper.variantMap = initialVariantMap;
        }
      } catch (ContradictionException ex) {
        throw new IOException(ex);
      } finally {
        initLock.unlock();
      }
    }
    if (!variantMap.containsKey(dialectOrLanguageNid)
        && !variantSetMap.containsKey(dialectOrLanguageNid)) {
      throw new UnsupportedDialectOrLanguage("nid: " + dialectOrLanguageNid);
    }
  }
 protected void merge(CompositeSearchResult other) {
   if (containingConcept.getNid() != other.containingConcept.getNid()) {
     throw new RuntimeException("Unmergeable!");
   }
   if (other.bestScore > bestScore) {
     bestScore = other.bestScore;
   }
   matchingComponents.addAll(other.getMatchingComponents());
 }
  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();
  }
 /**
  * Checks if the enclosing concept of the given <code>description</code> is has any descriptions
  * in the specified dialect, <code>dialectNid</code>. Uses the given <code>viewCoordinate</code>
  * to determine which version of the descriptions to use.
  *
  * @param description the description containing the text to check
  * @param dialectNid the dialect nid specifying the desired dialect
  * @param viewCoordinate the view coordinate specifying which version of the description to use
  * @return <code>true</code>, if no description is found in the specified dialect
  * @throws IOException signals that an I/O exception has occurred
  * @throws ContradictionException if more than one version is found for the given view coordinate
  * @throws UnsupportedDialectOrLanguage indicates an unsupported dialect or language
  */
 public static boolean isMissingDescForDialect(
     DescriptionVersionBI<?> description, int dialectNid, ViewCoordinate viewCoordinate)
     throws IOException, ContradictionException, UnsupportedDialectOrLanguage {
   lazyInit(dialectNid);
   if (!description.getLang().equals("en")) {
     return false;
   }
   if (isTextForDialect(description.getText(), dialectNid)) {
     return false;
   }
   String dialectText = makeTextForDialect(description.getText(), dialectNid);
   ConceptVersionBI concept =
       AppContext.getService(TerminologyStoreDI.class)
           .getConceptVersion(viewCoordinate, description.getConceptNid());
   for (DescriptionVersionBI<?> d : concept.getDescriptionsActive()) {
     if (d.getText().toLowerCase().equals(dialectText.toLowerCase())) {
       return false;
     }
   }
   return true;
 }
Beispiel #7
0
 public void setColumnVals(
     int currentCol,
     ConceptVersionBI colNameConcept,
     RefexDynamicDataType type,
     RefexDynamicDataBI defaultValueObject,
     boolean isMandatory,
     RefexDynamicValidatorType validatorType,
     RefexDynamicDataBI validatorData) {
   adjustColumnCount(currentCol);
   RefexDynamicColumnInfo rdci = columnInfo_.get(currentCol);
   rdci.setColumnDescriptionConcept(colNameConcept.getPrimordialUuid());
   rdci.setColumnDataType(type);
   rdci.setColumnDefaultData(defaultValueObject);
   rdci.setColumnRequired(isMandatory);
   rdci.setValidatorType(validatorType);
   rdci.setValidatorData(validatorData);
 }
  @FXML
  void initialize() {
    assert claimTasksButton != null
        : "fx:id=\"claimTasksButton\" was not injected: check your FXML file 'WorkflowInbox.fxml'.";
    assert synchronizeButton != null
        : "fx:id=\"synchronizeButton\" was not injected: check your FXML file 'WorkflowInbox.fxml'.";
    assert userName != null
        : "fx:id=\"userName\" was not injected: check your FXML file 'WorkflowInbox.fxml'.";
    assert taskTable != null
        : "fx:id=\"taskTable\" was not injected: check your FXML file 'WorkflowInbox.fxml'.";

    userName.setText(user);

    taskTable.setTableMenuButtonVisible(true);

    // BEGIN Task name
    TableColumn<LocalTask, String> tCol = new TableColumn<>();
    tCol.setText("Task");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getName());
        });
    taskTable.getColumns().add(tCol);
    // END Task name

    // BEGIN Task id
    tCol = new TableColumn<>();
    tCol.setText("id");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getId() + "");
        });
    taskTable.getColumns().add(tCol);
    // END Task id

    // BEGIN Component name
    tCol = new TableColumn<>();
    tCol.setText("Component");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getComponentName());
        });
    taskTable.getColumns().add(tCol);
    // END Component name

    // BEGIN WorkflowAction
    tCol = new TableColumn<>();
    tCol.setText("Action");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getAction().toString());
        });
    tCol.setVisible(false);
    taskTable.getColumns().add(tCol);
    // END WorkflowAction

    // BEGIN TaskActionStatus
    tCol = new TableColumn<>();
    tCol.setText("Action Status");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getActionStatus().name());
        });
    tCol.setVisible(false);
    taskTable.getColumns().add(tCol);
    // END TaskActionStatus

    // BEGIN Owner
    tCol = new TableColumn<>();
    tCol.setText("Owner");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getOwner());
        });
    tCol.setVisible(false);
    taskTable.getColumns().add(tCol);
    // END Owner

    // BEGIN Status
    tCol = new TableColumn<>();
    tCol.setText("Status");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getStatus().name());
        });
    tCol.setVisible(false);
    taskTable.getColumns().add(tCol);
    // END Status

    // BEGIN Component id (hidden)
    tCol = new TableColumn<>();
    tCol.setText("Component Id");
    tCol.setCellValueFactory(
        (value) -> {
          return new SimpleStringProperty(value.getValue().getComponentId());
        });
    tCol.setVisible(false);
    taskTable.getColumns().add(tCol);
    // END Component id (hidden)

    // BEGIN Concept
    TableColumn<LocalTask, SimpleDisplayConcept> conceptCol = new TableColumn<>();
    conceptCol.setText("Concept");
    conceptCol.setCellValueFactory(
        (value) -> {
          if (value.getValue().getComponentId() == null) {
            LOG.error("Component ID for task {} is null", value.getValue().getId());

            return new SimpleObjectProperty<SimpleDisplayConcept>();
          }
          UUID componentUuid = null;
          try {
            componentUuid = UUID.fromString(value.getValue().getComponentId());
          } catch (IllegalArgumentException e) {
            LOG.error("Component ID for task {} is not a valid UUID", value.getValue().getId());

            return new SimpleObjectProperty<SimpleDisplayConcept>();
          }

          ConceptVersionBI containingConcept = null;
          ComponentChronicleBI componentChronicle = WBUtility.getComponentChronicle(componentUuid);
          if (componentChronicle == null) {
            LOG.warn(
                "Component ID for task "
                    + value.getValue().getId()
                    + " retrieved a null componentChronicle");

            containingConcept = WBUtility.getConceptVersion(componentUuid);
            if (containingConcept == null) {
              LOG.error(
                  "Component ID for task "
                      + value.getValue().getId()
                      + " retrieved a null concept");

              return new SimpleObjectProperty<SimpleDisplayConcept>();
            }
          } else {
            try {
              containingConcept =
                  componentChronicle
                      .getEnclosingConcept()
                      .getVersion(WBUtility.getViewCoordinate());
            } catch (Exception e) {
              LOG.error(
                  "Failed getting version from ComponentChronicleBI task "
                      + value.getValue().getId()
                      + ".  Caught "
                      + e.getClass().getName()
                      + " "
                      + e.getLocalizedMessage());
              e.printStackTrace();
            }
            if (containingConcept == null) {
              LOG.error(
                  "ComponentChronicleBI task "
                      + value.getValue().getId()
                      + " contained a null enclosing concept");

              return new SimpleObjectProperty<SimpleDisplayConcept>();
            }
          }

          if (componentChronicle == null) {
            LOG.warn(
                "Component id "
                    + componentUuid
                    + " for task "
                    + value.getValue().getId()
                    + " is a concept, not just a component.");
          }
          SimpleDisplayConcept displayConcept = new SimpleDisplayConcept(containingConcept);
          return new SimpleObjectProperty<SimpleDisplayConcept>(displayConcept);
        });
    taskTable.getColumns().add(conceptCol);
    // END concept

    // BEGIN Concept
    TableColumn<LocalTask, String> conceptIdCol = new TableColumn<>();
    conceptIdCol.setText("Concept Id");
    conceptIdCol.setCellValueFactory(
        (value) -> {
          if (value.getValue().getComponentId() == null) {
            LOG.error("Component ID for task {} is null", value.getValue().getId());

            return new SimpleStringProperty();
          }
          UUID componentUuid = null;
          try {
            componentUuid = UUID.fromString(value.getValue().getComponentId());
          } catch (IllegalArgumentException e) {
            LOG.error("Component ID for task {} is not a valid UUID", value.getValue().getId());

            return new SimpleStringProperty();
          }

          ConceptVersionBI containingConcept = null;
          ComponentChronicleBI componentChronicle = WBUtility.getComponentChronicle(componentUuid);
          if (componentChronicle == null) {
            LOG.warn(
                "Component ID for task "
                    + value.getValue().getId()
                    + " retrieved a null componentChronicle");

            containingConcept = WBUtility.getConceptVersion(componentUuid);
            if (containingConcept == null) {
              LOG.error(
                  "Component ID for task "
                      + value.getValue().getId()
                      + " retrieved a null concept");

              return new SimpleStringProperty();
            }
          } else {
            try {
              containingConcept =
                  componentChronicle
                      .getEnclosingConcept()
                      .getVersion(WBUtility.getViewCoordinate());
            } catch (Exception e) {
              LOG.error(
                  "Failed getting version from ComponentChronicleBI task "
                      + value.getValue().getId()
                      + ".  Caught "
                      + e.getClass().getName()
                      + " "
                      + e.getLocalizedMessage());
              e.printStackTrace();
            }

            if (containingConcept == null) {
              LOG.error(
                  "ComponentChronicleBI task "
                      + value.getValue().getId()
                      + " contained a null enclosing concept");

              return new SimpleStringProperty();
            }
          }

          if (componentChronicle == null) {
            LOG.warn(
                "Component id "
                    + componentUuid
                    + " for task "
                    + value.getValue().getId()
                    + " is a concept, not just a component.");
          }

          UUID uuid = containingConcept.getPrimordialUuid();
          return new SimpleStringProperty(uuid.toString());
        });
    conceptIdCol.setVisible(false);
    taskTable.getColumns().add(conceptIdCol);
    // END concept ID

    float colWidth = 1.0f / taskTable.getColumns().size();
    for (TableColumn<LocalTask, ?> col : taskTable.getColumns()) {
      col.prefWidthProperty().bind(taskTable.widthProperty().multiply(colWidth).subtract(3.0));
      col.setCellFactory(new MyCellFactoryCallback<>());
    }

    claimTasksButton.setOnAction(
        (action) -> {
          claimTasksButton.setDisable(true);
          final BusyPopover claimPopover =
              BusyPopover.createBusyPopover("Claiming new tasks...", claimTasksButton);

          Utility.execute(
              () -> {
                try {
                  wfEngine_.claim(10, user);
                  Platform.runLater(
                      () -> {
                        claimPopover.hide();
                        claimTasksButton.setDisable(false);
                        refreshContent();
                      });
                } catch (Exception e) {
                  logger.error("Unexpected error claiming tasks", e);
                }
              });
        });

    synchronizeButton.setOnAction(
        (action) -> {
          synchronizeButton.setDisable(true);
          final BusyPopover synchronizePopover =
              BusyPopover.createBusyPopover("Synchronizing tasks...", synchronizeButton);

          Utility.execute(
              () -> {
                try {
                  wfEngine_.synchronizeWithRemote();
                  Platform.runLater(
                      () -> {
                        synchronizePopover.hide();
                        synchronizeButton.setDisable(false);
                        refreshContent();
                      });
                } catch (Exception e) {
                  logger.error("Unexpected error synchronizing tasks", e);
                }
              });
        });
  }