use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class ProductQuantitiesWithComponentsServiceImpl method getProductComponentWithQuantitiesForTechnology.
@Override
public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) {
OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
EntityTree operationComponents = productStructureTreeService.getOperationComponentsFromTechnology(technology);
technology.setField(TechnologyFields.OPERATION_COMPONENTS, EntityTreeUtilsService.getDetachedEntityTree(operationComponents));
Entity root = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot();
Map<Long, Entity> entitiesById = new LinkedHashMap<>();
for (Entity entity : operationComponents) {
entitiesById.put(entity.getId(), entity);
}
if (root != null) {
productQuantitiesService.preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns);
productQuantitiesService.traverseProductQuantitiesAndOperationRuns(technology, entitiesById, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
}
return operationProductComponentWithQuantityContainer;
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class OperationsCostCalculationServiceImpl method calculateOperationsCost.
@Override
public BigDecimal calculateOperationsCost(final Entity costCalculation, final Entity technology) {
DataDefinition costCalculationDataDefinition = costCalculation.getDataDefinition();
BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
ProductQuantitiesHolder productQuantitiesAndOperationRuns = getProductQuantitiesAndOperationRuns(technology, quantity, costCalculation);
Entity copyCostCalculation = operationCostCalculationTreeBuilder.copyTechnologyTree(costCalculation, technology);
Entity yetAnotherCostCalculation = costCalculationDataDefinition.save(copyCostCalculation);
Entity newCostCalculation = costCalculationDataDefinition.get(yetAnotherCostCalculation.getId());
EntityTree calculationOperationComponents = newCostCalculation.getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);
checkArgument(calculationOperationComponents != null, "given operation components is null");
List<Entity> tocs = calculationOperationComponents.stream().map(e -> e.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT)).collect(Collectors.toList());
OperationTimesContainer operationTimes = operationWorkTimeService.estimateOperationsWorkTimes(tocs, productQuantitiesAndOperationRuns.getOperationRuns(), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_TPZ), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME), true);
boolean hourlyCostFromOperation = !SourceOfOperationCosts.PARAMETERS.getStringValue().equals(costCalculation.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS));
Map<String, BigDecimal> resultsMap = estimateCostCalculationForHourly(calculationOperationComponents.getRoot(), operationTimes, hourlyCostFromOperation, costCalculation);
costCalculation.setField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS, calculationOperationComponents);
return BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.MACHINE_HOURLY_COST))).add(BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.LABOR_HOURLY_COST))), numberService.getMathContext());
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class EventListeners method addEvent.
public void addEvent(final ViewDefinitionState viewDefinitionState, final ComponentState triggerState, final String[] args) {
String eventType = args[0];
factoryStructureId = Long.parseLong(args[1]);
EntityTree tree = factoryStructureForEventHooks.getGeneratedTree();
Optional<Entity> maybeElement = tree.stream().filter(element -> element.getId() == factoryStructureId).findFirst();
if (!maybeElement.isPresent()) {
viewDefinitionState.addMessage("cmmsMachineParts.error.elementNotSelected", ComponentState.MessageType.FAILURE);
return;
}
Entity selectedElement = maybeElement.get();
FactoryStructureElementType elementType = FactoryStructureElementType.of(selectedElement);
if (elementType.compareTo(FactoryStructureElementType.COMPANY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.companySelected", ComponentState.MessageType.INFO);
return;
}
if (elementType.compareTo(FactoryStructureElementType.FACTORY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.factorySelected", ComponentState.MessageType.INFO);
return;
}
DataDefinition dataDefinition = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT);
Entity maintenanceEvent = dataDefinition.create();
if (elementType.compareTo(FactoryStructureElementType.DIVISION) == 0 || elementType.compareTo(FactoryStructureElementType.PRODUCTION_LINE) == 0 || MaintenanceEventType.parseString(eventType).compareTo(MaintenanceEventType.PROPOSAL) == 0) {
maintenanceEvent.setField(MaintenanceEventFields.FAULT_TYPE, faultTypesService.getDefaultFaultType());
}
fillEventFieldsFromSelectedElement(maintenanceEvent, selectedElement);
maintenanceEvent.setField(MaintenanceEventFields.TYPE, eventType);
maintenanceEvent = dataDefinition.save(maintenanceEvent);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", maintenanceEvent.getId());
viewDefinitionState.redirectTo("../page/" + CmmsMachinePartsConstants.PLUGIN_IDENTIFIER + "/maintenanceEventDetails.html", false, true, parameters);
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class ProductionLineDetailsListeners method generateFactoryStructure.
public void generateFactoryStructure(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity productionLine = form.getEntity();
EntityTree structure = factoryStructureGenerationService.generateFactoryStructureForProductionLine(productionLine);
productionLine.setField(WorkstationFieldsPL.FACTORY_STRUCTURE, structure);
form.setEntity(productionLine);
WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
window.setActiveTab("factoryStructureTab");
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyStateChangeListenerServiceTNFO method checkIfAllOperationComponenthHaveTJSet.
public boolean checkIfAllOperationComponenthHaveTJSet(final StateChangeContext stateChangeContext) {
Entity technology = stateChangeContext.getOwner();
DataDefinition dataDefinition = technology.getDataDefinition();
StringBuilder errors = new StringBuilder();
Entity savedTechnology = dataDefinition.get(technology.getId());
EntityTree operationComponents = savedTechnology.getTreeField("operationComponents");
boolean isValid = true;
for (Entity operationComponent : operationComponents) {
if (!checkIfTJSet(operationComponent)) {
isValid = false;
errors.append(" ");
StringBuilder fieldName = new StringBuilder();
fieldName.append(operationComponent.getStringField("nodeNumber")).append(" ");
fieldName.append(operationComponent.getBelongsToField("operation").getStringField("number")).append(" ");
fieldName.append(operationComponent.getBelongsToField("operation").getStringField("name"));
errors.append(fieldName);
errors.append(", ");
}
}
if (!isValid) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid");
stateChangeContext.addMessage("technologies.technology.validate.global.error.noTJSpecified", StateMessageType.FAILURE, false, errors.toString());
}
return isValid;
}
Aggregations