use of com.qcadoo.model.api.units.PossibleUnitConversions in project qcadoo by qcadoo.
the class UnitConversionServiceImplTest method shouldReturnNonEmptyConversionsSetUsingSimpleBiDirectionalTraverseWithCycle.
@Test
@Ignore
public final // TODO MAKU
void shouldReturnNonEmptyConversionsSetUsingSimpleBiDirectionalTraverseWithCycle() {
// given
final Entity kmToM = mockUnitConversionItem(BigDecimal.ONE, "km", BigDecimal.valueOf(1000L), "m");
final Entity mToDm = mockUnitConversionItem(BigDecimal.ONE, "m", BigDecimal.valueOf(10L), "dm");
final Entity kmToMm = mockUnitConversionItem(BigDecimal.ONE, "km", BigDecimal.valueOf(1000000L), "mm");
final Entity mmToDm = mockUnitConversionItem(BigDecimal.valueOf(100L), "mm", BigDecimal.ONE, "dm");
final Entity dmToM = mockUnitConversionItem(BigDecimal.valueOf(10L), "dm", BigDecimal.ONE, "m");
stubGetAll(Lists.newArrayList(mToDm, kmToM, kmToMm, mmToDm, dmToM));
// when
final PossibleUnitConversions result = unitConversionService.getPossibleConversions("m");
// then
assertEquals(3, result.asUnitToConversionMap().size());
assertBigDecimalEquals(new BigDecimal("0.001"), result.convertTo(BigDecimal.ONE, "km"));
assertBigDecimalEquals(BigDecimal.valueOf(10L), result.convertTo(BigDecimal.ONE, "dm"));
assertBigDecimalEquals(BigDecimal.valueOf(1000L), result.convertTo(BigDecimal.ONE, "mm"));
}
use of com.qcadoo.model.api.units.PossibleUnitConversions in project qcadoo by qcadoo.
the class UnitConversionServiceImplTest method shouldReturnNonEmptyConversionsSetUsingSimpleOneDirectionalTraverseWithCycle.
@Test
@Ignore
public final // TODO MAKU
void shouldReturnNonEmptyConversionsSetUsingSimpleOneDirectionalTraverseWithCycle() {
// given
final Entity mToDm = mockUnitConversionItem(BigDecimal.ONE, "m", BigDecimal.valueOf(10L), "dm");
final Entity dmToCm = mockUnitConversionItem(BigDecimal.ONE, "dm", BigDecimal.valueOf(10L), "cm");
final Entity cmToMm = mockUnitConversionItem(BigDecimal.ONE, "cm", BigDecimal.valueOf(10L), "mm");
final Entity mmToM = mockUnitConversionItem(BigDecimal.ONE, "mm", new BigDecimal("0.001"), "m");
stubGetAll(Lists.newArrayList(mToDm, dmToCm, cmToMm, mmToM));
// when
final PossibleUnitConversions result = unitConversionService.getPossibleConversions("m");
// then
assertEquals(3, result.asUnitToConversionMap().size());
assertBigDecimalEquals(BigDecimal.valueOf(10L), result.convertTo(BigDecimal.ONE, "dm"));
assertBigDecimalEquals(BigDecimal.valueOf(100L), result.convertTo(BigDecimal.ONE, "cm"));
assertBigDecimalEquals(BigDecimal.valueOf(1000L), result.convertTo(BigDecimal.ONE, "mm"));
}
use of com.qcadoo.model.api.units.PossibleUnitConversions in project qcadoo by qcadoo.
the class UnitConversionServiceImplTest method shouldReturnNonEmptyConversionsSetUsingSimpleBiDirectionalTraverse.
@Test
@Ignore
public final // TODO MAKU
void shouldReturnNonEmptyConversionsSetUsingSimpleBiDirectionalTraverse() {
// given
final Entity kmToM = mockUnitConversionItem(BigDecimal.ONE, "km", BigDecimal.valueOf(1000L), "m");
final Entity mToDm = mockUnitConversionItem(BigDecimal.ONE, "m", BigDecimal.valueOf(100L), "cm");
final Entity cmToMm = mockUnitConversionItem(BigDecimal.ONE, "cm", BigDecimal.valueOf(10L), "mm");
stubGetAll(Lists.newArrayList(mToDm, kmToM, cmToMm));
// when
final PossibleUnitConversions result = unitConversionService.getPossibleConversions("m");
// then
assertEquals(3, result.asUnitToConversionMap().size());
assertBigDecimalEquals(new BigDecimal("0.001"), result.convertTo(BigDecimal.ONE, "km"));
assertBigDecimalEquals(BigDecimal.valueOf(100L), result.convertTo(BigDecimal.ONE, "cm"));
assertBigDecimalEquals(BigDecimal.valueOf(1000L), result.convertTo(BigDecimal.ONE, "mm"));
}
use of com.qcadoo.model.api.units.PossibleUnitConversions in project qcadoo by qcadoo.
the class UnitConversionServiceImplTest method shouldReturnNonEmptyConversionsSetUsingSimpleOneDirectionalTraverse.
@Test
@Ignore
public final // TODO MAKU
void shouldReturnNonEmptyConversionsSetUsingSimpleOneDirectionalTraverse() {
// given
final Entity mToDm = mockUnitConversionItem(BigDecimal.ONE, "m", BigDecimal.valueOf(10L), "dm");
final Entity dmToCm = mockUnitConversionItem(BigDecimal.ONE, "dm", BigDecimal.valueOf(10L), "cm");
final Entity cmToMm = mockUnitConversionItem(BigDecimal.ONE, "cm", BigDecimal.valueOf(10L), "mm");
stubGetAll(Lists.newArrayList(mToDm, dmToCm, cmToMm));
// when
final PossibleUnitConversions result = unitConversionService.getPossibleConversions("m");
// then
assertEquals(3, result.asUnitToConversionMap().size());
assertBigDecimalEquals(BigDecimal.valueOf(10L), result.convertTo(BigDecimal.ONE, "dm"));
assertBigDecimalEquals(BigDecimal.valueOf(100L), result.convertTo(BigDecimal.ONE, "cm"));
assertBigDecimalEquals(BigDecimal.valueOf(1000L), result.convertTo(BigDecimal.ONE, "mm"));
}
use of com.qcadoo.model.api.units.PossibleUnitConversions in project mes by qcadoo.
the class ProductionCountingDocumentService method crateProductionCountingQuantityHolder.
private ProductionCountingQuantityHolder crateProductionCountingQuantityHolder(Entity inProductRecord, Entity inProduct) {
ProductionCountingQuantityHolder holder = new ProductionCountingQuantityHolder();
BigDecimal usedQuantity = inProductRecord.getDecimalField(TrackingOperationProductInComponentFields.USED_QUANTITY);
BigDecimal givenQuantity = inProductRecord.getDecimalField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY);
BigDecimal conversion = BigDecimal.ONE;
String unit = inProduct.getStringField(ProductFields.UNIT);
String givenUnit = inProductRecord.getStringField(TrackingOperationProductOutComponentFields.GIVEN_UNIT);
if (Objects.nonNull(usedQuantity) && Objects.nonNull(givenQuantity)) {
PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(unit, searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, inProduct)));
if (unitConversions.isDefinedFor(givenUnit)) {
conversion = numberService.setScaleWithDefaultMathContext(unitConversions.asUnitToConversionMap().get(givenUnit));
}
}
holder.setProductId(inProduct.getId());
holder.setProduct(inProduct);
holder.setUsedQuantity(usedQuantity);
holder.setConversion(conversion);
holder.setGivenQuantity(givenQuantity);
holder.setGivenUnit(givenUnit);
return holder;
}
Aggregations