@Test void testConvertUnitsAlgorithm() { EntityType targetEntityType = entityTypeFactory.create("target"); Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight"); targetAttribute.setLabel("height in m"); targetAttribute.setDataType(DECIMAL); targetEntityType.addAttribute(targetAttribute); EntityType sourceEntityType = entityTypeFactory.create("source"); Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight"); sourceAttribute.setDataType(DECIMAL); sourceAttribute.setLabel("body length in cm"); sourceEntityType.addAttribute(sourceAttribute); String actualAlgorithm = algorithmGeneratorService.generate( targetAttribute, Lists.newArrayList(sourceAttribute), targetEntityType, sourceEntityType); String expectedAlgorithm = "$('sourceHeight').unit('cm').toUnit('m').value();"; assertEquals(expectedAlgorithm, actualAlgorithm); }
@Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { if (targetAttribute.hasExpression()) { throw new AlgorithmException( format( "Algorithm generation for expressed attribute '%s' is not allowed", targetAttribute.getName())); } if (!sourceAttributes.isEmpty()) { for (AlgorithmGenerator generator : generators) { if (generator.isSuitable(targetAttribute, sourceAttributes)) { return generator.generate( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } } return generateMixedTypes( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } return StringUtils.EMPTY; }
AlgorithmGeneratorServiceImpl implements AlgorithmGeneratorService { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { if (targetAttribute.hasExpression()) { throw new AlgorithmException( format( "Algorithm generation for expressed attribute '%s' is not allowed", targetAttribute.getName())); } if (!sourceAttributes.isEmpty()) { for (AlgorithmGenerator generator : generators) { if (generator.isSuitable(targetAttribute, sourceAttributes)) { return generator.generate( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } } return generateMixedTypes( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } return StringUtils.EMPTY; } }
AlgorithmGeneratorServiceImpl implements AlgorithmGeneratorService { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { if (targetAttribute.hasExpression()) { throw new AlgorithmException( format( "Algorithm generation for expressed attribute '%s' is not allowed", targetAttribute.getName())); } if (!sourceAttributes.isEmpty()) { for (AlgorithmGenerator generator : generators) { if (generator.isSuitable(targetAttribute, sourceAttributes)) { return generator.generate( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } } return generateMixedTypes( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } return StringUtils.EMPTY; } AlgorithmGeneratorServiceImpl(
      DataService dataService,
      UnitResolver unitResolver,
      AlgorithmTemplateService algorithmTemplateService); }
AlgorithmGeneratorServiceImpl implements AlgorithmGeneratorService { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { if (targetAttribute.hasExpression()) { throw new AlgorithmException( format( "Algorithm generation for expressed attribute '%s' is not allowed", targetAttribute.getName())); } if (!sourceAttributes.isEmpty()) { for (AlgorithmGenerator generator : generators) { if (generator.isSuitable(targetAttribute, sourceAttributes)) { return generator.generate( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } } return generateMixedTypes( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } return StringUtils.EMPTY; } AlgorithmGeneratorServiceImpl(
      DataService dataService,
      UnitResolver unitResolver,
      AlgorithmTemplateService algorithmTemplateService); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); @Override GeneratedAlgorithm generate(
      Attribute targetAttribute,
      Hits<ExplainedAttribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); }
AlgorithmGeneratorServiceImpl implements AlgorithmGeneratorService { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { if (targetAttribute.hasExpression()) { throw new AlgorithmException( format( "Algorithm generation for expressed attribute '%s' is not allowed", targetAttribute.getName())); } if (!sourceAttributes.isEmpty()) { for (AlgorithmGenerator generator : generators) { if (generator.isSuitable(targetAttribute, sourceAttributes)) { return generator.generate( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } } return generateMixedTypes( targetAttribute, sourceAttributes, targetEntityType, sourceEntityType); } return StringUtils.EMPTY; } AlgorithmGeneratorServiceImpl(
      DataService dataService,
      UnitResolver unitResolver,
      AlgorithmTemplateService algorithmTemplateService); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); @Override GeneratedAlgorithm generate(
      Attribute targetAttribute,
      Hits<ExplainedAttribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType);  }