private void collectChildrenProducingTheSameParentInputs(final Map<String, Set<Entity>> parentToProductsMap, final EntityTreeNode parentOperation) { final Set<Long> parentInProdIds = getProductIdsFromOperationComponent(parentOperation, OPERATION_PRODUCT_IN_COMPONENTS); Map<Long, Set<Long>> intersections = Maps.newHashMap(); for (EntityTreeNode subOperation : parentOperation.getChildren()) { final Set<Long> childOutProdIds = getProductIdsFromOperationComponent(subOperation, OPERATION_PRODUCT_OUT_COMPONENTS); Set<Long> intersection = Sets.intersection(parentInProdIds, childOutProdIds); intersections.put(subOperation.getId(), intersection); } for (Entry<Long, Set<Long>> entry : intersections.entrySet()) { for (Entry<Long, Set<Long>> entry1 : intersections.entrySet()) { if (entry.getKey().equals(entry1.getKey())) { continue; } Set<Long> commonProds = Sets.intersection(entry.getValue(), entry1.getValue()); if (!commonProds.isEmpty()) { appendProductsToMap(parentToProductsMap, parentOperation, commonProds); } } } for (EntityTreeNode subOperation : parentOperation.getChildren()) { collectChildrenProducingTheSameParentInputs(parentToProductsMap, subOperation); } }
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 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()); }
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); } }