@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; }
@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; }
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; }
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 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 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 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); } }