Search in sources :

Example 1 with PossibleUnitConversions

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with PossibleUnitConversions

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with PossibleUnitConversions

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with PossibleUnitConversions

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PossibleUnitConversions

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;
}
Also used : PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal)

Aggregations

PossibleUnitConversions (com.qcadoo.model.api.units.PossibleUnitConversions)35 Entity (com.qcadoo.model.api.Entity)26 BigDecimal (java.math.BigDecimal)21 FieldComponent (com.qcadoo.view.api.components.FieldComponent)5 Test (org.junit.Test)5 Optional (com.google.common.base.Optional)4 DocumentBuilder (com.qcadoo.mes.materialFlowResources.service.DocumentBuilder)4 Ignore (org.junit.Ignore)4 FormComponent (com.qcadoo.view.api.components.FormComponent)3 DataDefinition (com.qcadoo.model.api.DataDefinition)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 CalculationQuantityService (com.qcadoo.mes.basic.CalculationQuantityService)1 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)1 UnitConversionItemFieldsB (com.qcadoo.mes.basic.constants.UnitConversionItemFieldsB)1 LocationFields (com.qcadoo.mes.materialFlow.constants.LocationFields)1 DocumentFields (com.qcadoo.mes.materialFlowResources.constants.DocumentFields)1