/** * Try find technology generator context entity by its id. * * @param contextId * unique identifier of an context. * @return matching context entity, if exists. */ public Optional<Entity> find(final ContextId contextId) { return Optional.ofNullable(getContextDD().get(contextId.get())); }
private Integer getWorkstationsQuantityFromMap(final Map<Long, Integer> workstations, final Entity operationComponent) { Entity operComp = operationComponent; String entityType = operationComponent.getDataDefinition().getName(); if (!TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT.equals(entityType)) { operComp = operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getDataDefinition() .get(operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getId()); } return workstations.get(operComp.getId()); }
public boolean canEditActions(Long id) { Entity user = userService.getCurrentUserEntity(); boolean hasProperRole = securityService.hasRole(user, "ROLE_PLANNED_EVENTS_BASIC_EDIT"); Entity plannedEvent = dataDefinitionService .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT).get(id); String state = plannedEvent.getStringField(PlannedEventFields.STATE); boolean eventIsInProperState = !(PlannedEventStateStringValues.REALIZED.equals(state) || PlannedEventStateStringValues.CANCELED.equals(state)); return hasProperRole && eventIsInProperState; } }
private BigDecimal getOperationRunsFromMap(final Map<Long, BigDecimal> operationRuns, final Entity operationComponent) { Entity operComp = operationComponent; String entityType = operationComponent.getDataDefinition().getName(); if (!TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT.equals(entityType)) { operComp = operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getDataDefinition() .get(operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getId()); } return BigDecimalUtils.convertNullToZero(operationRuns.get(operComp.getId())); }
public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) { Long currentUserId = securityService.getCurrentUserId(); if (Objects.nonNull(currentUserId)) { EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS); if (!userLocations.isEmpty()) { Set<Integer> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)) .mapToInt(e -> e.getId().intValue()).boxed().collect(Collectors.toSet()); scb.add(SearchRestrictions.in(LOCATION_ID, locationIds)); } } }
public boolean hasUnitChangedOnUpdate(final Entity product) { final Entity existingProduct = product.getDataDefinition().get(product.getId()); final String existingProductUnit = existingProduct.getStringField(ProductFields.UNIT); final String currentUnit = product.getStringField(ProductFields.UNIT); if (existingProductUnit == null) { return currentUnit != null; } else { return !existingProductUnit.equals(currentUnit); } }
private boolean shouldValidateDates(final DataDefinition dataDefinition, final Entity originalEntity) { if (originalEntity.getId() == null) { return true; } Entity dbEntity = dataDefinition.get(originalEntity.getId()); Date originalDateFrom = originalEntity.getDateField(WorkstationTypeComponentFields.DATE_FROM); Date dbDateFrom = dbEntity.getDateField(WorkstationTypeComponentFields.DATE_FROM); return originalDateFrom.compareTo(dbDateFrom) != 0; } }
private Entity getEntityFromForm(final ViewDefinitionState view) { FormComponent costCalculationForm = (FormComponent) view.getComponentByReference(L_FORM); checkArgument(costCalculationForm != null, "form is null"); checkArgument(costCalculationForm.isValid(), "invalid form"); Long costCalculationId = costCalculationForm.getEntityId(); return costCalculationForm.getEntity().getDataDefinition().get(costCalculationId); }
public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) { Long currentUserId = securityService.getCurrentUserId(); if (Objects.nonNull(currentUserId)) { EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS); if (!userLocations.isEmpty()) { Set<Long> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)) .map(Entity::getId).collect(Collectors.toSet()); scb.add(SearchRestrictions.in("location.id", locationIds)); } } }
public void fillTitleLabel(final ViewDefinitionState viewDefinitionState) { FieldComponent title = (FieldComponent) viewDefinitionState.getComponentByReference("title"); Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId); String number = order.getField("number").toString(); String name = order.getField("name").toString(); title.setFieldValue(name + " - " + number); title.requestComponentUpdateState(); }
private boolean changedFieldValue(final Entity entity, final BigDecimal fieldValue, final String reference) { if (entity.getId() == null) { return true; } Entity entityFromDB = entity.getDataDefinition().get(entity.getId()); return entityFromDB.getDecimalField(reference) == null || !(fieldValue.compareTo(entityFromDB.getDecimalField(reference)) == 0); }
public void setCriteriaModifierParameters(final ViewDefinitionState view) { Long orderId = (Long) view.getComponentByReference(WarehouseIssueFields.ORDER).getFieldValue(); Entity order = null; if (orderId != null) { order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId); } setCriteriaModifierParameters(view, order); }
public void checkDoneCalculate(final ViewDefinitionState viewDefinitionState) { FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId); Integer realizationTime = (Integer) order.getField("realizationTime"); if (realizationTime == null) { form.addMessage("orders.order.report.realizationTime", MessageType.INFO, false); } }
private String getAddressType(final Entity address) { Long addressId = address.getId(); if (addressId == null) { return address.getStringField(AddressFields.ADDRESS_TYPE); } else { return address.getDataDefinition().get(addressId).getStringField(AddressFields.ADDRESS_TYPE); } }
public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } }
private boolean mustRebuildSetTrackingOperationProductsComponents(Entity productionTracking) { if (productionTracking.getId() == null) { return true; } Long previousOrderId = productionTracking.getDataDefinition().get(productionTracking.getId()) .getBelongsToField(ProductionTrackingFields.ORDER).getId(); return !previousOrderId.equals(productionTracking.getBelongsToField(ProductionTrackingFields.ORDER).getId()); } }
private BigDecimal getAvailableQuantity(final DataDefinition productToIssueDD, final Entity productToIssue) { BigDecimal oldQuantity = BigDecimal.ZERO; if (productToIssue.getId() != null) { Entity productToIssueFromDB = productToIssueDD.get(productToIssue.getId()); oldQuantity = productToIssueFromDB.getDecimalField(ProductsToIssueFields.DEMAND_QUANTITY); } Entity location = productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE) .getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE); return resourceStockService .getResourceStockAvailableQuantity(productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT), location) .add(oldQuantity); }
public boolean onDelete(final DataDefinition generatorContextDD, final Entity generatorContext) { if(!generatorContext.getDataDefinition().get(generatorContext.getId()).getHasManyField("technologies").isEmpty()){ generatorContext.addGlobalError("technologiesGenerator.generate.deleteContext.error", false); return false; } return true; } }
private Either<String, ContextId> performGeneration(final GeneratorView generatorView, final Entity savedContext) { Either<String, ContextId> generationRes = treeGenerator.generate(savedContext, GeneratorSettings.from(savedContext, parameterService.getParameter())); if (generationRes.isRight()) { Entity updatedContext = savedContext.getDataDefinition().get(savedContext.getId()); generatorView.setFormEntity(updatedContext); generatorView.showGenerationSuccessMsg(); } else { generatorView.showErrorMsg("technologiesGenerator.generate.error.problemDuringStructureGeneration"); } return generationRes; }
public void saveCosts(final ViewDefinitionState viewDefinitionState, final ComponentState component, final String[] args) { FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference("order"); Entity order = orderForm.getEntity(); Entity orderEntity = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( order.getId()); orderEntity.setField(OrderFieldsCNFM.DIRECT_ADDITIONAL_COST, order.getDecimalField(OrderFieldsCNFM.DIRECT_ADDITIONAL_COST)); orderEntity.setField(OrderFieldsCNFM.DIRECT_ADDITIONAL_COST_DESCRIPTION, order.getStringField(OrderFieldsCNFM.DIRECT_ADDITIONAL_COST_DESCRIPTION)); orderEntity.getDataDefinition().save(orderEntity); }