Search in sources :

Example 1 with TypeOfProductionRecording

use of com.qcadoo.mes.productionCounting.constants.TypeOfProductionRecording in project mes by qcadoo.

the class OperationProductsExtractor method getOperationProductComponents.

private List<Entity> getOperationProductComponents(final Entity order, final Entity technologyOperationComponent) {
    List<Entity> trackingOperationProductComponents = Lists.newArrayList();
    Map<OperationProductComponentEntityType, Set<Entity>> entityTypeWithAlreadyAddedProducts = Maps.newHashMap();
    String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
    OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentQuantities(order);
    for (Entry<OperationProductComponentHolder, BigDecimal> productComponentQuantity : productComponentQuantities.asMap().entrySet()) {
        OperationProductComponentHolder operationProductComponentHolder = productComponentQuantity.getKey();
        if (forEach(typeOfProductionRecording)) {
            Entity operationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
            if (technologyOperationComponent == null) {
                if (operationComponent != null) {
                    continue;
                }
            } else {
                if ((operationComponent == null) || !technologyOperationComponent.getId().equals(operationComponent.getId())) {
                    continue;
                }
            }
        } else if (cumulated(typeOfProductionRecording)) {
            OperationProductComponentEntityType entityType = operationProductComponentHolder.getEntityType();
            Entity product = operationProductComponentHolder.getProduct();
            if ((product != null) && (entityType != null)) {
                if (shouldSkipAddingProduct(operationProductComponentHolder, entityTypeWithAlreadyAddedProducts, typeOfProductionRecording)) {
                    if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
                        continue;
                    } else {
                        entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet());
                        continue;
                    }
                } else {
                    if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
                        Set<Entity> alreadAddedProducts = entityTypeWithAlreadyAddedProducts.get(entityType);
                        alreadAddedProducts.add(product);
                        entityTypeWithAlreadyAddedProducts.put(entityType, alreadAddedProducts);
                    } else {
                        entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet(product));
                    }
                }
            }
        }
        Entity trackingOperationProductComponent = trackingOperationComponentBuilder.fromOperationProductComponentHolder(operationProductComponentHolder);
        if (forEach(typeOfProductionRecording)) {
            Optional<Entity> mabyExist = trackingOperationProductComponents.stream().filter(toc -> toc.getBelongsToField(L_PRODUCT).getId().equals(trackingOperationProductComponent.getBelongsToField(L_PRODUCT).getId())).findAny();
            if (!mabyExist.isPresent()) {
                trackingOperationProductComponents.add(trackingOperationProductComponent);
            }
        } else {
            trackingOperationProductComponents.add(trackingOperationProductComponent);
        }
    }
    return trackingOperationProductComponents;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Function(com.google.common.base.Function) OperationProductComponentEntityType(com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType) ProductionTrackingFields(com.qcadoo.mes.productionCounting.constants.ProductionTrackingFields) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderFieldsPC(com.qcadoo.mes.productionCounting.constants.OrderFieldsPC) Multimap(com.google.common.collect.Multimap) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) Maps(com.google.common.collect.Maps) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Sets(com.google.common.collect.Sets) Multimaps(com.google.common.collect.Multimaps) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) Entry(java.util.Map.Entry) ProductionCountingConstants(com.qcadoo.mes.productionCounting.constants.ProductionCountingConstants) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) Optional(java.util.Optional) TypeOfProductionRecording(com.qcadoo.mes.productionCounting.constants.TypeOfProductionRecording) Entity(com.qcadoo.model.api.Entity) Set(java.util.Set) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) OperationProductComponentEntityType(com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType) BigDecimal(java.math.BigDecimal)

Aggregations

Function (com.google.common.base.Function)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Multimaps (com.google.common.collect.Multimaps)1 Sets (com.google.common.collect.Sets)1 OrderFieldsPC (com.qcadoo.mes.productionCounting.constants.OrderFieldsPC)1 ProductionCountingConstants (com.qcadoo.mes.productionCounting.constants.ProductionCountingConstants)1 ProductionTrackingFields (com.qcadoo.mes.productionCounting.constants.ProductionTrackingFields)1 TypeOfProductionRecording (com.qcadoo.mes.productionCounting.constants.TypeOfProductionRecording)1 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)1 TechnologyService (com.qcadoo.mes.technologies.TechnologyService)1 OperationProductComponentEntityType (com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType)1 OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)1 OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)1 Entity (com.qcadoo.model.api.Entity)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1