private Entity getOrderTechnologyOperationComponent(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology == null) { return null; } else { return technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); } }
public List<Entity> getProductNodesWithCheckedTechnologies(final ViewDefinitionState view, final Entity order) { EntityTree tree = productStructureTreeService.generateProductStructureTree(view, order.getBelongsToField(OrderFields.TECHNOLOGY)); return tree .stream() .filter(node -> node.getStringField(ProductStructureTreeNodeFields.ENTITY_TYPE).equals(L_COMPONENT) && (node.getBelongsToField(ProductStructureTreeNodeFields.TECHNOLOGY) != null && node .getBelongsToField(ProductStructureTreeNodeFields.TECHNOLOGY) .getStringField(TechnologyFields.STATE).equals(TechnologyState.CHECKED.getStringValue()))) .collect(Collectors.toList()); }
@Override public final Map<String, Set<String>> checkConsumingManyProductsFromOneSubOp(final EntityTree technologyTree) { final Map<String, Set<String>> parentToChildsMap = Maps.newHashMap(); if (technologyTree != null && !technologyTree.isEmpty()) { final EntityTreeNode rootNode = technologyTree.getRoot(); collectChildrenProducingManyParentInputs(parentToChildsMap, rootNode); } return parentToChildsMap; }
productionLine); List<Entity> tocs = calculationOperationComponents.stream().map(e -> e.getBelongsToField("technologyOperationComponent")) .collect(Collectors.toList()); OperationTimesContainer operationTimes = operationWorkTimeService.estimateOperationsWorkTimes(tocs, productQuantitiesAndOperationRuns.getOperationRuns(), includeTPZ, includeAdditionalTime, workstations, true); Map<String, BigDecimal> resultsMap = estimateCostCalculationForHourly(calculationOperationComponents.getRoot(), productionCostMargin, quantity, operationTimes, hourlyCostFromOperation);
Entity technologyFromDB = technology.getDataDefinition().get(technology.getId()); EntityTree tree = technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE); if (tree.getRoot() != null) { Date productStructureCreateDate = tree.getRoot().getDateField(ProductStructureTreeNodeFields.CREATE_DATE); List<Entity> treeEntities = tree.find().list().getEntities(); Entity technologyStateChange = getLastTechnologyStateChange(technologyFromDB); if (productStructureCreateDate.before(technologyStateChange.getDateField(TechnologyStateChangeFields.DATE_AND_TIME))
public boolean checkIfTechnologyTreeIsSet(final StateChangeContext stateChangeContext) { final Entity technology = stateChangeContext.getOwner(); final EntityTree operations = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if (operations.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.emptyTechnologyTree"); return false; } return true; }
public boolean checkIfTechnologyHasAtLeastOneComponent(final StateChangeContext stateContext) { Entity technology = stateContext.getOwner(); final Entity savedTechnology = technology.getDataDefinition().get(technology.getId()); final EntityTree operations = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if (!operations.isEmpty()) { return true; } stateContext.addValidationError("technologies.technology.validate.global.error.emptyTechnologyTree"); return false; }
private Entity createTechnologyInstanceForCalculation(final EntityTree sourceTree, final Entity parentEntity) { checkArgument(sourceTree != null, "source is null"); DataDefinition calculationOperationComponentDD = dataDefinitionService.get(PLUGIN_IDENTIFIER, MODEL_CALCULATION_OPERATION_COMPONENT); // drop old operation components tree EntityTree oldCalculationOperationComponents = parentEntity.getTreeField(L_CALCULATION_OPERATION_COMPONENTS); if (oldCalculationOperationComponents != null && oldCalculationOperationComponents.getRoot() != null) { calculationOperationComponentDD.delete(oldCalculationOperationComponents.getRoot().getId()); } Entity tree = createCalculationOperationComponent(sourceTree.getRoot(), null, calculationOperationComponentDD, parentEntity); parentEntity.setField(L_CALCULATION_OPERATION_COMPONENTS, asList(tree)); return parentEntity; }
@Override public Map<String, Set<Entity>> checkConsumingTheSameProductFromManySubOperations(final EntityTree technologyTree) { Map<String, Set<Entity>> parentToProductsMap = Maps.newHashMap(); if (technologyTree != null && !technologyTree.isEmpty()) { final EntityTreeNode rootNode = technologyTree.getRoot(); collectChildrenProducingTheSameParentInputs(parentToProductsMap, rootNode); } return parentToProductsMap; }
public List<ComponentsCalculationHolder> fillBasicComponents(final EntityTree operationComponents) { List<ComponentsCalculationHolder> basicComponents = Lists.newArrayList(); Map<Long, Entity> componentsById = operationComponents.stream().collect(Collectors.toMap(x -> x.getId(), x -> x)); List<Entity> tocs = operationComponents.stream() .filter(pc -> L_COMPONENT.equals(pc.getStringField(TechnologyOperationComponentFields.TYPE_FROM_STRUCTURE_TREE))) .collect(Collectors.toList()); for (Entity toc : tocs) { if (toc.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).stream() .filter(op -> op.getBooleanField(OperationProductOutComponentFields.SET)).findAny().isPresent()) { List<Entity> setOperations = toc.getHasManyField(TechnologyOperationComponentFields.CHILDREN); for (Entity setOperation : setOperations) { Entity op = componentsById.get(setOperation.getId()); if (!L_COMPONENT.equals(op.getStringField(TechnologyOperationComponentFields.TYPE_FROM_STRUCTURE_TREE))) { ComponentsCalculationHolder component = new ComponentsCalculationHolder(op, op.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE)); basicComponents.add(component); } } } else { ComponentsCalculationHolder component = new ComponentsCalculationHolder(toc, toc.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE)); basicComponents.add(component); } } return basicComponents; }
private void setOperationOutProduct(Entity technologyOperationComponent) { if (Objects.nonNull(technologyOperationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)) && technologyOperationComponent.getHasManyField( TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).isEmpty()) { Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY); EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); DataDefinition opocDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT); Entity opoc = opocDD.create(); opoc.setField(OperationProductOutComponentFields.QUANTITY, 1); opoc.setField(OperationProductOutComponentFields.SET, false); if (tree == null || tree.isEmpty()) { opoc.setField(OperationProductOutComponentFields.PRODUCT, technology.getBelongsToField(TechnologyFields.PRODUCT)); technologyOperationComponent.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Collections.singletonList(opoc)); } else { Entity operation = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (Objects.nonNull(operation)) { Entity product = operation.getBelongsToField(OperationFields.PRODUCT); if (Objects.nonNull(product)) { opoc.setField(OperationProductOutComponentFields.PRODUCT, product); technologyOperationComponent.setField( TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Collections.singletonList(opoc)); } } } } }
private Entity getOrderTechnologyOperationComponent(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology == null) { return null; } else { Entity technologyOperationComponent = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); return technologyOperationComponent; } }
private void setParentIfRootNodeAlreadyExists(final Entity technologyOperationComponent) { Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY); EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if (tree == null || tree.isEmpty()) { return; } EntityTreeNode rootNode = tree.getRoot(); if ((rootNode == null) || (technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.PARENT) != null)) { return; } technologyOperationComponent.setField(TechnologyOperationComponentFields.PARENT, rootNode); }
Optional<Entity> maybeElement = tree.stream().filter(element -> element.getId() == factoryStructureId).findFirst();
public Map<Long, BigDecimal> getProductQuantitiesFromTechnology(final Long technologyId) { Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).get(technologyId); Entity operationComponentRoot = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); if (operationComponentRoot != null) { try { BigDecimal givenQty = technologyService.getProductCountForOperationComponent(operationComponentRoot); Map<Long, BigDecimal> productQuantities = productQuantitiesService.getNeededProductQuantities(technology, givenQty, MrpAlgorithm.COMPONENTS_AND_SUBCONTRACTORS_PRODUCTS); return productQuantities; } catch (IllegalStateException e) { if (LOG.isWarnEnabled()) { LOG.warn("Invalid technology tree!", e); } } } return Maps.newHashMap(); }
private void updateTechnology(final Entity technology) { String number = technology.getStringField(TechnologyFields.NUMBER); Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT); technology.setField(TechnologyFields.NAME, makeTechnologyName(number, product)); technology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, null); technology.setField(TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue()); EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if ((operationComponents != null) && !operationComponents.isEmpty()) { EntityTreeNode root = operationComponents.getRoot(); root.getDataDefinition().delete(root.getId()); } technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList()); technology.getDataDefinition().save(technology); if (TechnologyStateStringValues.CHECKED.equals(technology.getStringField(TechnologyFields.STATE))) { changeTechnologyState(technology, TechnologyStateStringValues.DRAFT); } }
private BigDecimal getEffectiveQuantity(final Entity entity) { Entity technology = entity.getBelongsToField(CostCalculationFields.TECHNOLOGY); Entity rootOperation = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); BigDecimal effectiveQuantity = entity.getDecimalField(CostCalculationFields.QUANTITY); boolean areProductQuantitiesDivisible = rootOperation .getBooleanField(TechnologyOperationComponentFieldsTNFO.ARE_PRODUCT_QUANTITIES_DIVISIBLE); if (!areProductQuantitiesDivisible) { List<Entity> opocs = rootOperation .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS); if (opocs.size() == 1) { Entity opoc = opocs.get(0); BigDecimal quantityInSingleCycle = opoc.getDecimalField(OperationProductOutComponentFields.QUANTITY); BigDecimal quantity = effectiveQuantity.divide(quantityInSingleCycle, new MathContext(2, RoundingMode.UP)); effectiveQuantity = quantityInSingleCycle.multiply(quantity, numberService.getMathContext()); } } return effectiveQuantity; }
private void deleteOperationsTreeIfExists(final Entity costCalculation) { Entity yetAnotherCostCalculation = costCalculation.getDataDefinition().get(costCalculation.getId()); EntityTree existingOperationsTree = yetAnotherCostCalculation.getTreeField(L_CALCULATION_OPERATION_COMPONENTS); if (existingOperationsTree == null || existingOperationsTree.getRoot() == null) { return; } debug("existing calculation operation components tree will be removed.."); EntityTreeNode existingOperationsTreeRoot = existingOperationsTree.getRoot(); existingOperationsTreeRoot.getDataDefinition().delete(existingOperationsTreeRoot.getId()); }
@Override public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) { OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer(); EntityTree operationComponents = getOperationComponentsFromTechnology(technology); Entity root = operationComponents.getRoot(); if (root != null) { preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns); traverseProductQuantitiesAndOperationRuns(technology, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns); } return operationProductComponentWithQuantityContainer; }
private void checkProductionFlowIsWithinProcess(Entity technology, StateChangeContext stateChangeContext) { EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity mainProduct = technologyService.getMainOutputProductComponent(tree.getRoot()); String productionFlow = technology.getStringField(TechnologyFieldsPFTD.PRODUCTION_FLOW); if (mainProduct.getBooleanField(OperationProductOutComponentFields.SET)) { if (productionFlow != null && !productionFlow.equals("02withinTheProcess")) { stateChangeContext.addValidationError("technologies.technology.error.productionFlow"); return; } for (Entity toc : tree) { List<Entity> opics = toc.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS); if (opics.stream() .anyMatch(opic -> opic.getStringField(OperationProductInComponentFieldsPFTD.PRODUCTION_FLOW) != null && !opic.getStringField(OperationProductInComponentFieldsPFTD.PRODUCTION_FLOW) .equals("02withinTheProcess"))) { stateChangeContext.addValidationError("technologies.technology.error.productionFlow.intermediate"); return; } List<Entity> opocs = toc.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS); if (opocs.stream() .anyMatch(opoc -> opoc.getStringField(OperationProductOutComponentFieldsPFTD.PRODUCTION_FLOW) != null && !opoc.getStringField(OperationProductOutComponentFieldsPFTD.PRODUCTION_FLOW) .equals("02withinTheProcess"))) { stateChangeContext.addValidationError("technologies.technology.error.productionFlow.intermediate"); } } } }