use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeValidationServiceImplTest method shouldReturnNotEmptyMapIfSubOpsProduceTheSameOutputsWhichAreConsumed.
@Test
public final void shouldReturnNotEmptyMapIfSubOpsProduceTheSameOutputsWhichAreConsumed() {
// given
Entity product1 = mockProductComponent(1L);
Entity product2 = mockProductComponent(2L);
Entity product3 = mockProductComponent(3L);
Entity product4 = mockProductComponent(4L);
Entity product5 = mockProductComponent(5L);
Entity product6 = mockProductComponent(6L);
EntityTreeNode node3 = mockOperationComponent(3L, "3.", newArrayList(product5), newArrayList(product2, product3));
EntityTreeNode node2 = mockOperationComponent(2L, "2.", newArrayList(product6), newArrayList(product2, product4));
EntityTreeNode node1 = mockOperationComponent(1L, "1.", newArrayList(product2), newArrayList(product1), newArrayList(node2, node3));
given(tree.getRoot()).willReturn(node1);
// when
Map<String, Set<Entity>> returnedMap = technologyTreeValidationService.checkConsumingTheSameProductFromManySubOperations(tree);
// then
assertNotNull(returnedMap);
assertFalse(returnedMap.isEmpty());
assertEquals(1, returnedMap.size());
assertTrue(returnedMap.containsKey("1."));
assertTrue(returnedMap.get("1.").contains(product2));
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeBuildServiceImplTest method shouldBuildTree.
@Test
public final void shouldBuildTree() {
// given
TocHolder customTreeRoot = mockCustomTreeRepresentation();
// when
EntityTree tree = treeBuildService.build(customTreeRoot, new TestTreeAdapter());
// then
EntityTreeNode root = tree.getRoot();
assertNotNull(root);
Entity toc1 = extractEntity(root);
verify(toc1).setField(TechnologyOperationComponentFields.OPERATION, toc1op);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS), toc1opicCaptor.capture());
Collection<Entity> toc1opics = toc1opicCaptor.getValue();
assertEquals(1, toc1opics.size());
Entity toc1opic = toc1opics.iterator().next();
verify(toc1opic).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc1opic).setField(OperationProductInComponentFields.PRODUCT, toc1opic1prod);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS), toc1opocCaptor.capture());
Collection<Entity> toc1opocs = toc1opocCaptor.getValue();
assertEquals(1, toc1opocs.size());
Entity toc1opoc = toc1opocs.iterator().next();
verify(toc1opoc).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc1opoc).setField(OperationProductInComponentFields.PRODUCT, toc1opoc1prod);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.CHILDREN), toc1childrenCaptor.capture());
Collection<Entity> toc1children = toc1childrenCaptor.getValue();
assertEquals(1, toc1children.size());
Entity toc2 = toc1children.iterator().next();
verify(toc2).setField(TechnologyOperationComponentFields.OPERATION, toc2op);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS), toc2opicCaptor.capture());
Collection<Entity> toc2opics = toc2opicCaptor.getValue();
assertEquals(1, toc2opics.size());
Entity toc2opic = toc2opics.iterator().next();
verify(toc2opic).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc2opic).setField(OperationProductInComponentFields.PRODUCT, toc2opic1prod);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS), toc2opocCaptor.capture());
Collection<Entity> toc2opocs = toc2opocCaptor.getValue();
assertEquals(1, toc2opocs.size());
Entity toc2opoc = toc2opocs.iterator().next();
verify(toc2opoc).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc2opoc).setField(OperationProductInComponentFields.PRODUCT, toc2opoc1prod);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.CHILDREN), toc2childrenCaptor.capture());
Collection<Entity> toc2children = toc2childrenCaptor.getValue();
assertTrue(toc2children.isEmpty());
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeValidationServiceImpl method collectChildrenProducingTheSameParentInputs.
private void collectChildrenProducingTheSameParentInputs(final Map<String, Set<Entity>> parentToProductsMap, final EntityTreeNode parentOperation) {
final Set<Long> parentInProductIds = getProductIdsFromOperationComponent(parentOperation, TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
Map<Long, Set<Long>> intersections = Maps.newHashMap();
for (EntityTreeNode subOperation : parentOperation.getChildren()) {
final Set<Long> childOutProductIds = getProductIdsFromOperationComponent(subOperation, TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
Set<Long> intersection = Sets.intersection(parentInProductIds, childOutProductIds);
intersections.put(subOperation.getId(), intersection);
}
for (Entry<Long, Set<Long>> entry : intersections.entrySet()) {
for (Entry<Long, Set<Long>> entry1 : intersections.entrySet()) {
if (entry.getKey().equals(entry1.getKey())) {
continue;
}
Set<Long> commonProducts = Sets.intersection(entry.getValue(), entry1.getValue());
if (!commonProducts.isEmpty()) {
appendProductsToMap(parentToProductsMap, parentOperation, commonProducts);
}
}
}
for (EntityTreeNode subOperation : parentOperation.getChildren()) {
collectChildrenProducingTheSameParentInputs(parentToProductsMap, subOperation);
}
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeValidationServiceImpl method checkConsumingTheSameProductFromManySubOperations.
@Override
public Map<String, Set<Entity>> checkConsumingTheSameProductFromManySubOperations(final EntityTree technologyTree) {
Map<String, Set<Entity>> parentToProductsMap = Maps.newHashMap();
if (Objects.nonNull(technologyTree) && !technologyTree.isEmpty()) {
final EntityTreeNode rootNode = technologyTree.getRoot();
collectChildrenProducingTheSameParentInputs(parentToProductsMap, rootNode);
}
return parentToProductsMap;
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class OperationsCostCalculationServiceImpl method estimateCostCalculationForHourly.
private Map<String, BigDecimal> estimateCostCalculationForHourly(final EntityTreeNode calculationOperationComponent, final OperationTimesContainer realizationTimes, final boolean hourlyCostFromOperation, Entity costCalculation) {
checkArgument(calculationOperationComponent != null, "given operationComponent is empty");
Map<String, BigDecimal> costs = Maps.newHashMapWithExpectedSize(L_COST_KEYS.size());
MathContext mathContext = numberService.getMathContext();
for (String costKey : L_COST_KEYS) {
costs.put(costKey, BigDecimal.ZERO);
}
for (EntityTreeNode child : calculationOperationComponent.getChildren()) {
Map<String, BigDecimal> unitCosts = estimateCostCalculationForHourly(child, realizationTimes, hourlyCostFromOperation, costCalculation);
for (String costKey : L_COST_KEYS) {
BigDecimal unitCost = costs.get(costKey).add(unitCosts.get(costKey), mathContext);
costs.put(costKey, numberService.setScaleWithDefaultMathContext(unitCost));
}
}
OperationTimes operationTimes = realizationTimes.get(calculationOperationComponent.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT).getId());
Map<String, BigDecimal> costsForSingleOperation = estimateHourlyCostCalculationForSingleOperation(operationTimes, hourlyCostFromOperation, costCalculation);
saveGeneratedValues(costsForSingleOperation, calculationOperationComponent, operationTimes.getTimes());
costs.put(CalculationOperationComponentFields.MACHINE_HOURLY_COST, costs.get(CalculationOperationComponentFields.MACHINE_HOURLY_COST).add(costsForSingleOperation.get(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST), mathContext));
costs.put(CalculationOperationComponentFields.LABOR_HOURLY_COST, costs.get(CalculationOperationComponentFields.LABOR_HOURLY_COST).add(costsForSingleOperation.get(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST), mathContext));
return costs;
}
Aggregations