Search in sources :

Example 1 with NumberService

use of com.qcadoo.model.api.NumberService in project mes by qcadoo.

the class OperationWorkTimeServiceTest method init.

@Before
public void init() {
    operationWorkTimeService = new OperationWorkTimeServiceImpl();
    MockitoAnnotations.initMocks(this);
    ReflectionTestUtils.setField(operationWorkTimeService, "numberService", numberService);
    when(numberService.getMathContext()).thenReturn(mc);
    given(numberService.setScaleWithDefaultMathContext(Mockito.any(BigDecimal.class))).willAnswer((Answer<BigDecimal>) invocation -> {
        Object[] args = invocation.getArguments();
        BigDecimal number = (BigDecimal) args[0];
        return number.setScale(5, RoundingMode.HALF_EVEN);
    });
    when(operComp1.getDataDefinition()).thenReturn(dataDefinition);
    when(operComp2.getDataDefinition()).thenReturn(dataDefinition);
    when(operComp3.getDataDefinition()).thenReturn(dataDefinition);
    Long id1 = 1L;
    Long id2 = 2L;
    Long id3 = 3L;
    when(operComp1.getId()).thenReturn(id1);
    when(operComp2.getId()).thenReturn(id2);
    when(operComp3.getId()).thenReturn(id3);
    when(dataDefinition.get(id1)).thenReturn(operComp1);
    when(dataDefinition.get(id2)).thenReturn(operComp2);
    when(dataDefinition.get(id3)).thenReturn(operComp3);
    when(dataDefinition.getName()).thenReturn("technologyOperationComponent");
    neededNumberOfCycles1 = BigDecimal.ONE;
    neededNumberOfCycles2 = new BigDecimal(2);
    neededNumberOfCycles3 = new BigDecimal("2.3");
    when(operComp1.getIntegerField("tj")).thenReturn(600);
    when(operComp2.getIntegerField("tj")).thenReturn(300);
    when(operComp3.getIntegerField("tj")).thenReturn(150);
    when(operComp1.getIntegerField("tpz")).thenReturn(600);
    when(operComp2.getIntegerField("tpz")).thenReturn(900);
    when(operComp3.getIntegerField("tpz")).thenReturn(1200);
    when(operComp1.getIntegerField("timeNextOperation")).thenReturn(600);
    when(operComp2.getIntegerField("timeNextOperation")).thenReturn(300);
    when(operComp3.getIntegerField("timeNextOperation")).thenReturn(450);
    lu1 = new BigDecimal("2.2");
    lu2 = new BigDecimal("0.6");
    lu3 = new BigDecimal("0.8");
    when(operComp1.getDecimalField("laborUtilization")).thenReturn(lu1);
    when(operComp2.getDecimalField("laborUtilization")).thenReturn(lu2);
    when(operComp3.getDecimalField("laborUtilization")).thenReturn(lu3);
    mu1 = new BigDecimal("0.2");
    mu2 = new BigDecimal("1.6");
    mu3 = new BigDecimal("0.7");
    when(operComp1.getDecimalField("machineUtilization")).thenReturn(mu1);
    when(operComp2.getDecimalField("machineUtilization")).thenReturn(mu2);
    when(operComp3.getDecimalField("machineUtilization")).thenReturn(mu3);
    workstations1 = 1;
    workstations2 = 2;
    workstations3 = 1;
    workstations.put(operComp1, workstations1);
    workstations.put(operComp2, workstations2);
    workstations.put(operComp3, workstations3);
    workstationsMap.put(operComp1.getId(), workstations1);
    workstationsMap.put(operComp2.getId(), workstations2);
    workstationsMap.put(operComp3.getId(), workstations3);
    operationsRuns.put(operComp1, new BigDecimal(3));
    operationsRuns.put(operComp2, new BigDecimal("1.5"));
    operationsRuns.put(operComp3, new BigDecimal(7));
    operationRuns.put(operComp1.getId(), new BigDecimal(3));
    operationRuns.put(operComp2.getId(), new BigDecimal("1.5"));
    operationRuns.put(operComp3.getId(), new BigDecimal(7));
}
Also used : Assert.assertEquals(junit.framework.Assert.assertEquals) Arrays(java.util.Arrays) Mock(org.mockito.Mock) BigDecimal(java.math.BigDecimal) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) RoundingMode(java.math.RoundingMode) Before(org.junit.Before) Iterator(java.util.Iterator) MathContext(java.math.MathContext) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Mockito(org.mockito.Mockito) List(java.util.List) Entity(com.qcadoo.model.api.Entity) Assert(junit.framework.Assert) NumberService(com.qcadoo.model.api.NumberService) Mockito.mock(org.mockito.Mockito.mock) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 2 with NumberService

use of com.qcadoo.model.api.NumberService in project mes by qcadoo.

the class DispositionOrderPdfService method addPositionsTable.

private void addPositionsTable(Document document, Entity documentEntity, Locale locale) throws DocumentException {
    List<Integer> headerWidthsList = new ArrayList<>(Arrays.asList(25, 50, 50, 50, 65, 90, 40, 35));
    int numOfColumns = 8;
    if (acceptanceOfDocumentBeforePrinting) {
        headerWidthsList.add(45);
        numOfColumns++;
    }
    int[] headerWidths = headerWidthsList.stream().mapToInt(i -> i).toArray();
    Map<String, HeaderAlignment> headerValues = getPositionsTableHeaderLabels(locale);
    PdfPTable positionsTable = pdfHelper.createTableWithHeader(numOfColumns, Lists.newArrayList(headerValues.keySet()), false, headerWidths, headerValues);
    positionsTable.getDefaultCell().disableBorderSide(PdfPCell.RIGHT);
    positionsTable.getDefaultCell().disableBorderSide(PdfPCell.LEFT);
    positionsTable.setHeaderRows(1);
    List<Entity> positions = PositionDataProvider.getPositions(documentEntity);
    PositionsHolder positionsHolder = new PositionsHolder(numberService);
    fillPositions(positionsHolder, positions);
    List<Position> _positions = positionsHolder.getPositions();
    if (acceptanceOfDocumentBeforePrinting) {
        Collections.sort(_positions, new Comparator<Position>() {

            @Override
            public int compare(Position p1, Position p2) {
                return ComparisonChain.start().compare(p1.getTargetPallet(), p2.getTargetPallet()).compare(p1.getStorageLocation(), p2.getStorageLocation()).result();
            }
        });
    } else {
        Collections.sort(_positions, new Comparator<Position>() {

            @Override
            public int compare(Position p1, Position p2) {
                return ComparisonChain.start().compare(p1.getStorageLocation(), p2.getStorageLocation()).result();
            }
        });
    }
    Integer index = 1;
    for (Position position : _positions) {
        positionsTable.addCell(createCell(index.toString(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getStorageLocation(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getPalletNumber(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getTypeOfPallet(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getAdditionalCodeAndBatch(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getProductName(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(PositionDataProvider.quantity(position.getQuantity()), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getUnit(), Element.ALIGN_LEFT));
        if (acceptanceOfDocumentBeforePrinting) {
            positionsTable.addCell(createCell(position.getTargetPallet(), Element.ALIGN_LEFT));
        }
        index++;
    }
    positionsTable.setSpacingAfter(20);
    document.add(positionsTable);
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Position(com.qcadoo.mes.materialFlowResources.print.helper.Position) Element(com.lowagie.text.Element) ColorUtils(com.qcadoo.report.api.ColorUtils) Locale(java.util.Locale) Map(java.util.Map) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) PdfPageEventHelper(com.lowagie.text.pdf.PdfPageEventHelper) PositionDataProvider(com.qcadoo.mes.materialFlowResources.print.helper.PositionDataProvider) FontUtils(com.qcadoo.report.api.FontUtils) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) ComparisonChain(com.google.common.collect.ComparisonChain) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) DocumentFields(com.qcadoo.mes.materialFlowResources.constants.DocumentFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Rectangle(com.lowagie.text.Rectangle) ParameterService(com.qcadoo.mes.basic.ParameterService) PositionsHolder(com.qcadoo.mes.materialFlowResources.print.helper.PositionsHolder) ResourceFields(com.qcadoo.mes.materialFlowResources.constants.ResourceFields) PdfWriter(com.lowagie.text.pdf.PdfWriter) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) PositionBuilder(com.qcadoo.mes.materialFlowResources.print.helper.PositionBuilder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) PdfDocumentWithWriterService(com.qcadoo.report.api.pdf.PdfDocumentWithWriterService) PalletNumberFields(com.qcadoo.mes.basic.constants.PalletNumberFields) PdfPTable(com.lowagie.text.pdf.PdfPTable) ArrayList(java.util.ArrayList) MaterialFlowResourcesConstants(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants) Lists(com.google.common.collect.Lists) Chunk(com.lowagie.text.Chunk) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Phrase(com.lowagie.text.Phrase) DocumentDataProvider(com.qcadoo.mes.materialFlowResources.print.helper.DocumentDataProvider) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) Service(org.springframework.stereotype.Service) BatchFields(com.qcadoo.mes.advancedGenealogy.constants.BatchFields) PositionFields(com.qcadoo.mes.materialFlowResources.constants.PositionFields) Paragraph(com.lowagie.text.Paragraph) DocumentException(com.lowagie.text.DocumentException) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Document(com.lowagie.text.Document) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) StorageLocationFields(com.qcadoo.mes.materialFlowResources.constants.StorageLocationFields) HeaderPair(com.qcadoo.mes.materialFlowResources.print.helper.DocumentPdfHelper.HeaderPair) PdfPCell(com.lowagie.text.pdf.PdfPCell) Comparator(java.util.Comparator) Collections(java.util.Collections) Entity(com.qcadoo.model.api.Entity) Position(com.qcadoo.mes.materialFlowResources.print.helper.Position) ArrayList(java.util.ArrayList) PositionsHolder(com.qcadoo.mes.materialFlowResources.print.helper.PositionsHolder) PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment)

Example 3 with NumberService

use of com.qcadoo.model.api.NumberService in project qcadoo by qcadoo.

the class UnitConversionServiceImplTest method init.

@Before
public final void init() {
    MockitoAnnotations.initMocks(this);
    unitConversionService = new UnitConversionServiceImpl();
    final NumberService numberService = mock(NumberService.class);
    given(numberService.getMathContext()).willReturn(MATH_CONTEXT);
    given(unitConversionModelService.getDataDefinition()).willReturn(unitConversionItemDD);
    ReflectionTestUtils.setField(unitConversionService, "numberService", numberService);
    ReflectionTestUtils.setField(unitConversionService, "unitConversionModelService", unitConversionModelService);
    ReflectionTestUtils.setField(unitConversionService, "dictionaryService", dictionaryService);
}
Also used : NumberService(com.qcadoo.model.api.NumberService) Before(org.junit.Before)

Aggregations

NumberService (com.qcadoo.model.api.NumberService)3 Maps (com.google.common.collect.Maps)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 Entity (com.qcadoo.model.api.Entity)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 ComparisonChain (com.google.common.collect.ComparisonChain)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Chunk (com.lowagie.text.Chunk)1 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 Element (com.lowagie.text.Element)1 Paragraph (com.lowagie.text.Paragraph)1 Phrase (com.lowagie.text.Phrase)1 Rectangle (com.lowagie.text.Rectangle)1 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfPCell (com.lowagie.text.pdf.PdfPCell)1