@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; }
@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; }
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; }
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(); } }
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; } }
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 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 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); }
public void validateTypeOfProductionRecordingForTechnology(final StateChangeContext stateChangeContext) { Entity technology = stateChangeContext.getOwner(); if (technology != null && !stateChangeContext.getStatus().equals(StateChangeStatus.FAILURE)) { EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity mainProduct = technologyService.getMainOutputProductComponent(tree.getRoot()); String typeOfProductionRecording = technology.getStringField(TechnologyFieldsPC.TYPE_OF_PRODUCTION_RECORDING); if (mainProduct.getBooleanField(OperationProductOutComponentFields.SET) && typeOfProductionRecording.equals("03forEach")) { stateChangeContext.addValidationError("technologies.technology.technologyState.error.typeOfProductionRecording"); } } }
private EntityTree transformProductStructureTreeToTOCTree(final EntityTree productStructureTree) { List<Entity> tocTree = Lists.newArrayList(); DataDefinition tocDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT); Entity root = productStructureTree.getRoot(); Long rootTocID = root.getBelongsToField(ProductStructureTreeNodeFields.OPERATION).getId(); addChildTOC(tocTree, tocDD.get(rootTocID), null, root.getBelongsToField(ProductStructureTreeNodeFields.PRODUCT), L_FINAL_PRODUCT); addTocChildes(tocTree, tocDD, root); return EntityTreeUtilsService.getDetachedEntityTree(tocTree); }
@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 = productStructureTreeService.getOperationComponentsFromTechnology(technology); technology.setField(TechnologyFields.OPERATION_COMPONENTS, EntityTreeUtilsService.getDetachedEntityTree(operationComponents)); Entity root = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); Map<Long, Entity> entitiesById = new LinkedHashMap<Long, Entity>(); for (Entity entity : operationComponents) { entitiesById.put(entity.getId(), entity); } if (root != null) { productQuantitiesService.preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns); productQuantitiesService.traverseProductQuantitiesAndOperationRuns(technology, entitiesById, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns); } return operationProductComponentWithQuantityContainer; }
public boolean validateProductionFlowForSet(final DataDefinition dataDefinition, final Entity productionCountingQuantity) { String typeOfMaterial = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL); Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER); if (ProductionCountingQuantityTypeOfMaterial.INTERMEDIATE.getStringValue().equals(typeOfMaterial)) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity mainProduct = technologyService.getMainOutputProductComponent(tree.getRoot()); String productionFlow = productionCountingQuantity .getStringField(ProductionCountingQuantityFieldsPFTD.PRODUCTION_FLOW); if (mainProduct.getBooleanField(OperationProductOutComponentFields.SET) && productionFlow != null && !productionFlow.equals("02withinTheProcess")) { productionCountingQuantity.addError(dataDefinition.getField(ProductionCountingQuantityFieldsPFTD.PRODUCTION_FLOW), "technologies.technology.error.productionFlow"); return false; } } return true; }
private Optional<Entity> getSetProductTechnology(final Long productId) { DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY); Entity masterTechnology = technologyDD.find().add(SearchRestrictions.eq(TechnologyFields.PRODUCT + ".id", productId)) .add(SearchRestrictions.eq(TechnologyFields.MASTER, true)).uniqueResult(); if (masterTechnology != null) { EntityTree operationComponents = masterTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); boolean isSet = operationComponents.getRoot() .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0) .getBooleanField(OperationProductOutComponentFields.SET); if (isSet) { return Optional.of(masterTechnology); } } return Optional.empty(); }
public void rebuildTreeNumbering(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Long technologyId = form.getEntityId(); if (technologyId == null) { return; } Entity technology = getTechnologyById(technologyId); if (!isDraftTechnology(technology)) { return; } EntityTree technologyTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if (technologyTree == null || technologyTree.getRoot() == null) { return; } debug("Fire tree node number generator for tecnology with id = " + technologyId); treeNumberingService.generateTreeNumbers(technologyTree); }
public void validateTypeOfProductionRecordingForOrder(final StateChangeContext stateChangeContext) { if(parameterService.getParameter().getBooleanField(ParameterFieldsO.CREATE_SET_ELEMENTS_ON_ACCEPT)) { Entity order = stateChangeContext.getOwner(); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null && !stateChangeContext.getStatus().equals(StateChangeStatus.FAILURE)) { EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity mainProduct = technologyService.getMainOutputProductComponent(tree.getRoot()); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); if (typeOfProductionRecording != null && mainProduct.getBooleanField(OperationProductOutComponentFields.SET) && typeOfProductionRecording.equals("03forEach")) { stateChangeContext .addValidationError("technologies.technology.technologyState.error.typeOfProductionRecording"); } } } } }
public boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateContext) { Entity technology = stateContext.getOwner(); final Entity savedTechnology = technology.getDataDefinition().get(technology.getId()); final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT); final EntityTree operations = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); final EntityTreeNode root = operations.getRoot(); if (root != null) { final EntityList productOutComps = root .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS); for (Entity productOutComp : productOutComps) { if (product.getId().equals(productOutComp.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) { return true; } } } stateContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree"); return false; }
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); } }
public Entity getDailyProgress(final Entity productionPerShift, final Date day, final Entity shift) { Entity order = getOrder(productionPerShift); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity toc = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(); DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY); List<Entity> correctedProgressForDay = progressForDayDD.find() .add(SearchRestrictions.belongsTo(ProgressForDayFields.PRODUCTION_PER_SHIFT, productionPerShift)) .add(SearchRestrictions.eq(ProgressForDayFields.CORRECTED, true)).list().getEntities(); Entity progressForDay; if (correctedProgressForDay.isEmpty()) { progressForDay = progressForDayDD.find() .add(SearchRestrictions.belongsTo(ProgressForDayFields.PRODUCTION_PER_SHIFT, productionPerShift)) .add(SearchRestrictions.eq(ProgressForDayFields.ACTUAL_DATE_OF_DAY, day)) .add(SearchRestrictions.eq(ProgressForDayFields.CORRECTED, false)).setMaxResults(1).uniqueResult(); } else { progressForDay = progressForDayDD.find() .add(SearchRestrictions.belongsTo(ProgressForDayFields.PRODUCTION_PER_SHIFT, productionPerShift)) .add(SearchRestrictions.eq(ProgressForDayFields.ACTUAL_DATE_OF_DAY, day)) .add(SearchRestrictions.eq(ProgressForDayFields.CORRECTED, true)).setMaxResults(1).uniqueResult(); } if (progressForDay == null) { return null; } else { Entity dailyProgress = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS).find() .add(SearchRestrictions.belongsTo(DailyProgressFields.SHIFT, shift)).setMaxResults(1).uniqueResult(); return dailyProgress; } }