private boolean addToList(final List<Entity> tree, final Entity child, final boolean makeIdsUnique) { child.setField(PRIORITY, 1); child.setField(ENTITY_TYPE, L_BATCH); if (checkIfTreeContainsEntity(tree, child)) { return false; } else { if (makeIdsUnique) { child.setId((long) tree.size()); } tree.add(child); return true; } }
private void addChild(List<Entity> tree, final Entity child, final Entity parent) { child.setField(FactoryStructureElementFields.PARENT, parent); child.setId((long) tree.size() + 1); child.setField(FactoryStructureElementFields.NODE_NUMBER, child.getId()); child.setField(FactoryStructureElementFields.PRIORITY, 1); tree.add(child); }
private Entity copyReferencedTechnologyOperations(final Entity node, final Entity technology) { Entity copy = node.copy(); copy.setId(null); copy.setField(TechnologyOperationComponentFields.PARENT, null); copy.setField(TechnologyOperationComponentFields.TECHNOLOGY, technology); for (Entry<String, Object> entry : node.getFields().entrySet()) { Object value = entry.getValue(); if (value instanceof EntityList) { EntityList entities = (EntityList) value; List<Entity> copies = Lists.newArrayList(); for (Entity entity : entities) { copies.add(copyReferencedTechnologyOperations(entity, technology)); } copy.setField(entry.getKey(), copies); } } return copy; }
@Transactional(propagation = Propagation.REQUIRES_NEW) private Either<Entity, Void> tryValidateDailyProgress(final Entity dailyProgress) { Entity savedDailyProgress = saved(dailyProgress); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // reset id to avoid 'entity cannot be found' exceptions. savedDailyProgress.setId(dailyProgress.getId()); if (savedDailyProgress.isValid()) { return Either.right(null); } return Either.left(savedDailyProgress); }
private void fillPositions(Entity location, Entity document, DocumentBuilder pzBuilder) { List<Entity> positions = document.getHasManyField(DocumentFields.POSITIONS); positions.forEach(pos -> { Entity pzPosition = pos.copy(); pzPosition.setId(null); pzPosition.setField(PositionFields.DOCUMENT, null); pzPosition.setField(PositionFields.RESOURCE, null); pzPosition.setField(PositionFields.TYPE_OF_PALLET, null); pzPosition.setField(PositionFields.PALLET_NUMBER, null); Optional<Entity> maybyStorageLocation = findStorageLocationForProduct(pos.getBelongsToField(PositionFields.PRODUCT), location); if (maybyStorageLocation.isPresent()) { pzPosition.setField(PositionFields.STORAGE_LOCATION, maybyStorageLocation.get()); } else { pzPosition.setField(PositionFields.STORAGE_LOCATION, null); } pzBuilder.addPosition(pzPosition); }); }
private Entity generateFormEntity(final ViewDefinitionState view) { DataDefinition dd = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT); FormComponent form = getForm(view); Entity formEntity = form.getEntity(); GridComponent parentsGrid = (GridComponent) view.getComponentByReference("parents"); if (parentsGrid.getSelectedEntities().isEmpty()) { return null; } Long productId = parentsGrid.getSelectedEntities().get(0).getId(); if (productId == null) { throw new FormValidationException("basic.productFamiliesTree.noProductSelected"); } Entity product = dd.get(productId); List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(product); EntityTree entityTree = EntityTreeUtilsService.getDetachedEntityTree(tree); formEntity.setId(productId); formEntity.setField(PRODUCT_FAMILY_CHILDREN_TREE, entityTree); return formEntity; }
if (shouldBeCorrected) { dailyProgress = dailyProgress.copy(); dailyProgress.setId(null);
public void generateTimeGaps(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) throws ParseException { FormComponent form = (FormComponent) formState; Entity contextEntity = form.getPersistedEntityWithIncludedFormValues(); // We don't want to reuse contexts - in case of the user working with many browser tabs to compare a couple of results contextEntity.setId(null); contextEntity.setField(TimeGapsContextFields.TIME_GAPS, Collections.<Entity> emptyList()); // Call validation contextEntity = contextEntity.getDataDefinition().save(contextEntity); if (!contextEntity.isValid()) { clearSummaryFields(contextEntity); form.setEntity(contextEntity); return; } // Generate & persist results TimeGapsSearchResult searchResult = performGeneration(contextEntity); Entity persistedContext = persistResults(contextEntity, searchResult); if (persistedContext.isValid()) { // Show 'time gaps' tab WindowComponent window = (WindowComponent) findComponentByReferenceName(viewState, "window"); window.setActiveTab("timeGaps"); } form.setEntity(persistedContext); }
public void generateBalance(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) { FormComponent form = (FormComponent) formState; Entity contextEntity = form.getPersistedEntityWithIncludedFormValues(); // We don't want to reuse contexts - in case of the user working with many browser tabs to compare a couple of results contextEntity.setId(null); contextEntity.setField(BalanceContextFields.BALANCES, Collections.<Entity> emptyList()); // Call validation contextEntity = contextEntity.getDataDefinition().save(contextEntity); if (!contextEntity.isValid()) { form.setEntity(contextEntity); return; } BalanceGenerationStrategy strategy = resolveBalanceGenerationStrategy(contextEntity); List<Entity> balances = productionBalancePerShiftGenerator.generate(strategy); contextEntity.setField(BalanceContextFields.BALANCES, balances); Entity persistedContext = contextEntity.getDataDefinition().save(contextEntity); if (persistedContext.isValid()) { // Show 'balances' tab WindowComponent window = (WindowComponent) viewState.getComponentByReference("window"); window.setActiveTab("balances"); } form.setEntity(persistedContext); }