public void onSave(final DataDefinition anomalyExplanationDD, final Entity entity) { Entity anomaly = entity.getBelongsToField(AnomalyExplanationFields.ANOMALY); String anomalyState = anomaly.getStringField(AnomalyFields.STATE); if (anomalyState.equals(AnomalyFields.State.COMPLETED)) { throw new IllegalStateException("Completed anomaly can't be updated"); } if (entity.getId() == null && anomalyState.equals(AnomalyFields.State.DRAFT)) { anomaly.setField(AnomalyFields.STATE, AnomalyFields.State.EXPLAINED); anomaly.getDataDefinition().save(anomaly); } }
public void setProductionInOneCycleUNIT(final DataDefinition dataDefinition, final Entity opoc) { Entity toc = opoc.getBelongsToField(OperationProductOutComponentFields.OPERATION_COMPONENT); Entity product = opoc.getBelongsToField(OperationProductOutComponentFields.PRODUCT); toc.setField(TechnologyOperationComponentFieldsTNFO.PRODUCTION_IN_ONE_CYCLE_UNIT, product.getField(ProductFields.UNIT)); toc.getDataDefinition().save(toc); } }
private void updateCompanyAndRequestForQuotation(final Map<Long, Entity> companyAndRequestForQuotations, final Entity company, final Date dueDate, final Entity requestForQuotationProduct) { Entity addedRequestForQuotation = companyAndRequestForQuotations.get(company.getId()); Date desiredDate = (Date) addedRequestForQuotation.getField(DESIRED_DATE); List<Entity> requestForQuotationProducts = Lists.newArrayList(addedRequestForQuotation .getHasManyField(REQUEST_FOR_QUOTATION_PRODUCTS)); requestForQuotationProducts.add(requestForQuotationProduct); addedRequestForQuotation.setField(DESIRED_DATE, updateDesiredDate(desiredDate, getDueDateMinusCompanyBuffer(dueDate, company))); addedRequestForQuotation.setField(REQUEST_FOR_QUOTATION_PRODUCTS, requestForQuotationProducts); companyAndRequestForQuotations.put(company.getId(), addedRequestForQuotation); }
public void onCreate(final DataDefinition resourceDD, final Entity resource) { resource.setField(ResourceFields.IS_CORRECTED, false); if (resource.getField(ResourceFields.WASTE) == null) { resource.setField(ResourceFields.WASTE, false); } if (resource.getDecimalField(ResourceFields.RESERVED_QUANTITY) == null) { resource.setField(ResourceFields.RESERVED_QUANTITY, BigDecimal.ZERO); } if (resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY) == null) { resource.setField(ResourceFields.AVAILABLE_QUANTITY, resource.getDecimalField(ResourceFields.QUANTITY)); } }
public void copyCommentAndAttachmentFromLowerInstance(final Entity technologyOperationComponent, final String belongsToName) { Entity operation = technologyOperationComponent.getBelongsToField(belongsToName); if (operation != null) { technologyOperationComponent.setField(TechnologyOperationComponentFields.COMMENT, operation.getStringField(OperationFields.COMMENT)); technologyOperationComponent.setField(TechnologyOperationComponentFields.ATTACHMENT, operation.getStringField(OperationFields.ATTACHMENT)); } }
public boolean checkIfLocationHasExternalNumber(final DataDefinition stockCorrectionDD, final Entity stockCorrection) { if (stockCorrection.getBelongsToField(LOCATION).getStringField("externalNumber") != null) { stockCorrection.addError(stockCorrectionDD.getField(LOCATION), "materialFlow.validate.global.error.locationHasExternalNumber"); return false; } return true; }
public void copyToOperationsNorms(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity avgLaborCostCalcForOrder = form.getEntity().getDataDefinition().get(form.getEntityId()); Entity order = avgLaborCostCalcForOrder.getBelongsToField(AvgLaborCostCalcForOrderFields.ORDER); List<Entity> tocs = order.getBelongsToField(OrderFields.TECHNOLOGY) .getHasManyField(TechnologyFields.OPERATION_COMPONENTS); for (Entity toc : tocs) { toc.setField(LABOR_HOURLY_COST, avgLaborCostCalcForOrder.getDecimalField(AVERAGE_LABOR_HOURLY_COST)); toc.getDataDefinition().save(toc); } }
private Entity createPositionWithoutResourceForMissingQuantity(Entity position, DataDefinition positionDD, BigDecimal quantity) { Entity newPosition = positionDD.create(); newPosition.setField(PositionFields.PRODUCT, position.getBelongsToField(PositionFields.PRODUCT)); newPosition.setField(PositionFields.GIVEN_UNIT, position.getStringField(PositionFields.GIVEN_UNIT)); newPosition.setField(PositionFields.CONVERSION, position.getField(PositionFields.CONVERSION)); setPositionQuantityAndGivenQuantity(quantity, newPosition); return newPosition; }
private void clearStorageLocations(Entity delivery) { EntityList deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS); if (deliveredProducts != null) { for (Entity deliveryProduct : deliveredProducts) { deliveryProduct.setField(DeliveredProductFields.STORAGE_LOCATION, null); deliveryProduct.getDataDefinition().save(deliveryProduct); } } } }
private boolean locationUniqueToDelivery(Entity orderedProductReservation) { Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT); Entity delivery = orderedProduct.getBelongsToField(OrderedProductFields.DELIVERY); Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION); Entity reservationLocation = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.LOCATION); boolean locationOtherThenDelivery = deliveryLocation == null || !deliveryLocation.getId().equals(reservationLocation.getId()); if (!locationOtherThenDelivery) { FieldDefinition locationField = orderedProductReservation.getDataDefinition().getField(OrderedProductReservationFields.LOCATION); orderedProductReservation.addError(locationField, "deliveries.deliveredProductReservation.error.locationNotUniqueToDelivery"); } return locationOtherThenDelivery; }
private void copyTrackingOperationProductInComponents(Entity productionTracking, Entity correctingProductionTracking) { EntityList trackingOperationProductInComponents = productionTracking .getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS); List<Entity> copiedTrackingOperationProductInComponents = Lists.newArrayList(); trackingOperationProductInComponents.forEach(t -> copiedTrackingOperationProductInComponents.add(t.getDataDefinition() .copy(t.getId()).get(0))); correctingProductionTracking.setField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS, copiedTrackingOperationProductInComponents); }
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); } }
private Entity findForOrder(Entity parentOrder, Entity coverageProduct) { return coverageProduct .getHasManyField(CoverageProductFields.COVERAGE_PRODUCT_LOGGINGS) .stream() .filter(e -> Objects.nonNull(e.getBelongsToField(CoverageProductLoggingFields.ORDER))) .filter(entity -> entity.getBelongsToField(CoverageProductLoggingFields.ORDER).getId() .equals(parentOrder.getId())).findFirst().get(); }
public boolean checkIfUsedQuantitiesWereNotFilled(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); final SearchCriteriaBuilder searchBuilder = productionTracking .getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS).find() .add(SearchRestrictions.isNotNull(TrackingOperationProductInComponentFields.USED_QUANTITY)) .setProjection(SearchProjections.alias(SearchProjections.rowCount(), L_COUNT)).addOrder(asc(L_COUNT)); return (order.getBooleanField(OrderFieldsPC.REGISTER_QUANTITY_IN_PRODUCT) && ((Long) searchBuilder.setMaxResults(1).uniqueResult().getField(L_COUNT) <= 0)); }
private boolean checkIfOperationIsSet(final DataDefinition productionTrackingDD, final Entity productionTracking) { String recordingMode = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER).getStringField( OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); Object orderOperation = productionTracking.getField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); if (TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingMode) && orderOperation == null) { productionTracking.addError(productionTrackingDD.getField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT), "productionCounting.productionTracking.messages.error.operationIsNotSet"); return false; } return true; }
public void setDefaultValueForTechnologyBatchRequiredField(final DataDefinition dataDefinition, final Entity entity) { if (entity.getId() != null) { return; } if (entity.getField("technologyBatchRequired") != null) { return; } Entity parameter = parameterService.getParameter(); entity.setField("technologyBatchRequired", parameter.getBooleanField("batchNumberRequiredProducts")); } }
public void updateDescription(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (parameterService.getParameter().getBooleanField(ParameterFieldsMO.COPY_DESCRIPTION)) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity order = form.getEntity(); Entity masterOrder = order.getBelongsToField(OrderFieldsMO.MASTER_ORDER); if (masterOrder != null) { order.setField(OrderFields.DESCRIPTION, masterOrder.getStringField(MasterOrderFields.DESCRIPTION)); form.setEntity(order); } } } }
private boolean eachOperationHasLastRecords(final Entity order, final Entity productionTracking) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); int numOfOrderOperations = technology.getHasManyField(TechnologyFields.OPERATION_COMPONENTS).size(); Set<Long> matchingRecordIds = getIdsOfAcceptedLastRecords(productionTracking.getDataDefinition(), order.getId()); int numOfMatchingRecords = matchingRecordIds.size(); long recordId = productionTracking.getId(); return (numOfMatchingRecords >= numOfOrderOperations) || (numOfMatchingRecords == (numOfOrderOperations - 1) && !matchingRecordIds.contains(recordId)); }
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); }