use of com.qcadoo.commons.functional.Either in project mes by qcadoo.
the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithAlteredMainOutputProduct.
@Test
public final void shouldCreateCustomizedTechnologyWithAlteredMainOutputProduct() {
// given
given(generatorSettings.shouldCreateAndSwitchProducts()).willReturn(false);
Entity technologyCopy = mockTechnology(2L, true, null);
Entity technology = mockTechnology(1L, true, technologyCopy);
stubIsValid(technology, true);
Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
stubIsValid(nodeProduct, true);
Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
stubIsValid(node, true);
stubNodeSearchResult(node);
String generatedTechNumber = "generatedTechNumber";
String generatedTechName = "generated tech name";
stubTechNameAndNumberGenerator(mainProduct, generatedTechNumber, generatedTechName);
// when
Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
// then
assertTrue(result.isPresent());
assertTrue(result.get().isRight());
assertEquals((long) result.get().getRight().get(), 2L);
verify(technologyOperationProductsCustomizer, never()).customize(any(TechnologyId.class), anyEntity(), anyEntity(), any(GeneratorSettings.class));
verify(technologyOperationProductsCustomizer).prepareMainTechnologyProduct(technologyCopy, mainProduct);
verify(technologyNameAndNumberGenerator).generateName(mainProduct);
verify(technologyNameAndNumberGenerator).generateNumber(mainProduct);
verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
use of com.qcadoo.commons.functional.Either in project mes by qcadoo.
the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithoutChangingProduct.
@Test
public final void shouldCreateCustomizedTechnologyWithoutChangingProduct() {
// given
given(generatorSettings.shouldCreateAndSwitchProducts()).willReturn(false);
Entity technologyCopy = mockTechnology(2L, true, null);
Entity technology = mockTechnology(1L, true, technologyCopy);
stubIsValid(technology, true);
Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
stubIsValid(nodeProduct, true);
Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, mockEntity(), nodeProduct);
stubIsValid(node, true);
stubNodeSearchResult(node);
String generatedTechNumber = "generatedTechNumber";
String generatedTechName = "generated tech name";
stubTechNameAndNumberGenerator(nodeProduct, generatedTechNumber, generatedTechName);
// when
Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
// then
assertTrue(result.isPresent());
assertTrue(result.get().isRight());
assertEquals((long) result.get().getRight().get(), 2L);
verify(technologyOperationProductsCustomizer, never()).customize(any(TechnologyId.class), anyEntity(), anyEntity(), any(GeneratorSettings.class));
verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
verify(technologyNameAndNumberGenerator).generateName(nodeProduct);
verify(technologyNameAndNumberGenerator).generateNumber(nodeProduct);
verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
use of com.qcadoo.commons.functional.Either in project mes by qcadoo.
the class TechnologiesGeneratorForProductsService method generateTechnologyNode.
private void generateTechnologyNode(Entity node, Entity product, Entity context) {
try {
Optional<Either<String, TechnologyId>> customizedTechId = Optional.ofNullable(product).flatMap(mainProduct -> Optional.ofNullable(node.getId()).flatMap(nodeId -> customize(nodeId, mainProduct, GeneratorSettings.from(context, parameterService.getParameter()), true)));
customizedTechId.ifPresent(cti -> {
if (cti.isRight()) {
TechnologyId technologyId = cti.getRight();
technologyCustomizer.addCustomizedProductToQualityCard(technologyId);
}
});
} catch (Exception e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Cannot perform technology customization due to unexpected error", e);
}
}
}
Aggregations