use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class OrderCreationService method createTechnology.
private Either<String, Entity> createTechnology(OrderCreationRequest orderCreationRequest) {
Entity product = getProduct(orderCreationRequest.getProductId());
Entity parameter = parameterService.getParameter();
Entity operation = parameter.getBelongsToField(L_DASHBOARD_OPERATION);
Entity dashboardComponentsLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_COMPONENTS_LOCATION);
Entity dashboardProductsInputLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_PRODUCTS_INPUT_LOCATION);
Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).create();
toc.setField(TechnologyOperationComponentFields.OPERATION, operation);
toc.setField(TechnologyOperationComponentFields.ENTITY_TYPE, L_OPERATION);
for (String fieldName : FIELDS_OPERATION) {
toc.setField(fieldName, operation.getField(fieldName));
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_TYPE) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_TYPE, L_ALL);
}
if (operation.getField(PRODUCTION_IN_ONE_CYCLE) == null) {
toc.setField(PRODUCTION_IN_ONE_CYCLE, "1");
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY, "0");
}
Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
topoc.setField(OperationProductOutComponentFields.PRODUCT, product);
topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Lists.newArrayList(topoc));
List<Entity> topics = Lists.newArrayList();
for (MaterialDto material : orderCreationRequest.getMaterials()) {
Entity inProduct = getProduct(material.getProductId());
Entity topic = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).create();
topic.setField(OperationProductInComponentFields.PRODUCT, inProduct);
topic.setField(OperationProductInComponentFields.QUANTITY, material.getQuantityPerUnit());
topics.add(topic);
}
toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS, topics);
String range = parameter.getStringField(L_RANGE);
Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).create();
technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
technology.setField(TechnologyFields.PRODUCT, product);
technology.setField(TechnologyFields.EXTERNAL_SYNCHRONIZED, true);
technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList(toc));
technology.setField(L_RANGE, range);
technology.setField("componentsLocation", dashboardComponentsLocation);
technology.setField("productsInputLocation", dashboardProductsInputLocation);
technology.setField("typeOfProductionRecording", "02cumulated");
technology = technology.getDataDefinition().save(technology);
if (technology.isValid()) {
final StateChangeContext technologyStateChangeContext = stateChangeContextBuilder.build(technologyStateChangeAspect.getChangeEntityDescriber(), technology, TechnologyState.ACCEPTED.getStringValue());
technologyStateChangeAspect.changeState(technologyStateChangeContext);
technology = technology.getDataDefinition().get(technology.getId());
if (!technology.getStringField(TechnologyFields.STATE).equals(TechnologyStateStringValues.ACCEPTED)) {
return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.acceptError", LocaleContextHolder.getLocale()));
}
technology.setField(TechnologyFields.MASTER, Boolean.TRUE);
technology.getDataDefinition().save(technology);
} else {
return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
}
return Either.right(technology);
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class OrderStateReasonViewListeners method continueStateChange.
public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
final FormComponent form = (FormComponent) component;
form.performEvent(view, "save");
if (!form.isValid()) {
return;
}
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
final StateChangeContext stateContext = stateChangeContextBuilder.build(orderStateChangeService.getChangeEntityDescriber(), stateChangeEntity);
stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
orderStateChangeService.changeState(stateContext);
orderStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class WarehouseIssueStateService method checkIfAnyNotIssuedPositionsExists.
public boolean checkIfAnyNotIssuedPositionsExists(final StateChangeContext stateChangeContext) {
Entity warehouseIssue = stateChangeContext.getOwner();
List<Entity> issues = warehouseIssue.getHasManyField(WarehouseIssueFields.ISSUES);
if (!issues.stream().filter(e -> !e.getBooleanField(IssueFields.ISSUED)).collect(Collectors.toList()).isEmpty()) {
stateChangeContext.addValidationError("productFlowThruDivision.issue.state.complete.error.existsNotIssuedPositions");
return true;
}
return false;
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class TechnologyValidationService method checkIfEveryInComponentsHasQuantities.
public boolean checkIfEveryInComponentsHasQuantities(final StateChangeContext stateChangeContext) {
Entity technology = stateChangeContext.getOwner();
final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
for (Entity operationComponent : operationComponents) {
List<Entity> operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
for (Entity operationProductInComponent : operationProductInComponents) {
boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
boolean variousQuantitiesInProductsBySize = operationProductInComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE);
if (!differentProductsInDifferentSizes && Objects.isNull(operationProductInComponent.getDecimalField(OperationProductInComponentFields.QUANTITY))) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.inComponentsQuantitiesNotFilled", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
return false;
}
if (differentProductsInDifferentSizes && variousQuantitiesInProductsBySize) {
boolean quantitiesOrProductsNotSet = false;
if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).isEmpty()) {
quantitiesOrProductsNotSet = true;
} else if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().anyMatch(pbs -> Objects.isNull(pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY)))) {
quantitiesOrProductsNotSet = true;
}
if (quantitiesOrProductsNotSet) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.variousQuantitiesInProductsBySizeNotFilled", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
return false;
}
}
}
}
return true;
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class TechnologyValidationService method checkIfWasteProductsIsRightMarked.
public boolean checkIfWasteProductsIsRightMarked(final StateChangeContext stateChangeContext) {
Entity technology = stateChangeContext.getOwner();
final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
for (Entity operationComponent : operationComponents) {
List<Entity> operationProductOutComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
long notWasteCount = operationProductOutComponents.stream().filter(opoc -> !opoc.getBooleanField(OperationProductOutComponentFields.WASTE)).count();
if (notWasteCount > 1 || notWasteCount == 0) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.noProductsWithWasteFlagNotMarked", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
return false;
}
}
return true;
}
Aggregations