Пример #1
0
  /** Test for centroid function in alignment3 */
  @Test
  public void testCentroid1() {

    Collection<? extends Cell> cells = alignment5.getCells();

    Iterator<? extends Cell> it = cells.iterator();

    Cell cell = null;

    while (it.hasNext()) {
      Cell temp = it.next();

      if (temp.getTransformationIdentifier()
          .equals("eu.esdihumboldt.cst.functions.geometric.centroid")) {
        cell = temp;
        break;
      }
    }

    // test if there is only one source and one target
    assertEquals(1, cell.getSource().size());
    assertEquals(1, cell.getTarget().size());

    List<? extends Entity> list = cell.getTarget().get(null);
    assertEquals(1, list.size());

    Entity ent = list.get(0);

    String name = ent.getDefinition().getDefinition().getDisplayName();

    assertEquals("referencePoint", name);
  }
Пример #2
0
  /** Test for ordinates to point function in alignment5 */
  @Test
  public void testOrdinatesToPoint1() {

    Collection<? extends Cell> cells = alignment5.getCells();

    Iterator<? extends Cell> it = cells.iterator();

    Cell cell = null;

    while (it.hasNext()) {
      Cell temp = it.next();

      if (temp.getTransformationIdentifier()
          .equals("eu.esdihumboldt.cst.functions.geometric.ordinates_to_point")) {
        cell = temp;
        break;
      }
    }

    ListMultimap<String, ? extends Entity> src = cell.getSource();

    // the parameters were moved to the source entities with the appropriate
    // names so get the source entities with name "X"/"Y"
    Entity srcX = src.get("X").get(0);
    Entity srcY = src.get("Y").get(0);

    // check if the source entity has the correct value
    assertEquals("HOCHWERT", srcX.getDefinition().getDefinition().getDisplayName());
    assertEquals("RECHTSWERT", srcY.getDefinition().getDefinition().getDisplayName());
  }
Пример #3
0
  /** @see Alignment#getTypeCells(Cell) */
  @Override
  public Collection<? extends Cell> getTypeCells(Cell queryCell) {
    Set<TypeEntityDefinition> sources = new HashSet<TypeEntityDefinition>();
    if (queryCell.getSource() != null) {
      Iterator<? extends Entity> it = queryCell.getSource().values().iterator();
      while (it.hasNext()) sources.add(AlignmentUtil.getTypeEntity(it.next().getDefinition()));
    }

    Entity targetEntity = CellUtil.getFirstEntity(queryCell.getTarget());
    TypeDefinition target = targetEntity == null ? null : targetEntity.getDefinition().getType();

    if (sources.isEmpty() && target == null) return getTypeCells();

    List<Cell> result = new ArrayList<Cell>();

    for (Cell typeCell : typeCells) {
      TypeDefinition typeCellTarget =
          CellUtil.getFirstEntity(typeCell.getTarget()).getDefinition().getType();
      if (target == null || DefinitionUtil.isSuperType(target, typeCellTarget)) {
        // target matches
        if (sources.isEmpty() || matchesSources(typeCell.getSource(), sources)) {
          // source matches, too
          result.add(typeCell);
        }
      }
    }

    return result;
  }
Пример #4
0
  /**
   * Determines if all of the given entities are associated to at least one of the given type entity
   * definitions.
   *
   * @param testCellSources the entities
   * @param typeCellTypes the type entity definitions
   * @return whether all entities are associated to at least one of the types
   */
  private boolean matchesSources(
      ListMultimap<String, ? extends Entity> testCellSources,
      Iterable<TypeEntityDefinition> typeCellTypes) {
    if (testCellSources == null) return true;
    for (Entity entity : testCellSources.values()) {
      // if one of the property cell's sources is not part of the type
      // cell it should not be included
      // XXX this is only true for the transformation?
      if (!matchesSources(AlignmentUtil.getTypeEntity(entity.getDefinition()), typeCellTypes))
        return false;
    }

    return true;
  }
Пример #5
0
  /** Test for mathematical expression in alignment */
  @Test
  public void testMathematicalExpression() {
    Collection<? extends Cell> cells = alignment.getCells();

    Iterator<? extends Cell> it = cells.iterator();

    Cell cell = null;
    while (it.hasNext()) {
      Cell temp = it.next();

      if (temp.getTransformationIdentifier()
          .equals("eu.esdihumboldt.cst.functions.numeric.mathexpression")) {
        cell = temp;
        break;
      }
    }

    ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
    List<ParameterValue> values = params.get("expression");

    // test the amount and the correctness of the parameter
    assertEquals(1, values.size());

    String date = values.get(0).as(String.class);

    assertEquals("income * age/10", date);

    // test the amount and the correctness of source properties
    ListMultimap<String, ? extends Entity> src = cell.getSource();

    // all source properties should be named "var" so we test if both lists
    // have the same size
    List<? extends Entity> srcCells = src.get("var");
    assertEquals(2, src.size());
    assertEquals(2, srcCells.size());

    // since we have now the right amount of source properties we can now
    // test the correctness of their names
    Entity srcCell1 = srcCells.get(0);
    Entity srcCell2 = srcCells.get(1);

    String name1 = srcCell1.getDefinition().getDefinition().getDisplayName();
    String name2 = srcCell2.getDefinition().getDefinition().getDisplayName();

    assertEquals("age", name1);
    assertEquals("income", name2);
  }
Пример #6
0
  /**
   * Removes a cell from the internal indexes, based on the given associated entities.
   *
   * @param entities the cell entities (usually either source or target)
   * @param cell the cell to remove
   */
  private void internalRemoveFromMaps(ListMultimap<String, ? extends Entity> entities, Cell cell) {
    if (entities == null) {
      return;
    }

    for (Entity entity : entities.values()) {
      EntityDefinition entityDef = entity.getDefinition();
      cellsPerEntity.remove(entityDef, cell);

      switch (entityDef.getSchemaSpace()) {
        case TARGET:
          cellsPerTargetType.remove(entityDef.getType(), cell);
          break;
        case SOURCE:
          cellsPerSourceType.remove(entityDef.getType(), cell);
          break;
        default:
          throw new IllegalStateException(
              "Entity definition with illegal schema space encountered");
      }
    }
  }