Search in sources :

Example 11 with Either

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));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 12 with Either

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));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 13 with Either

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);
        }
    }
}
Also used : TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) Async(org.springframework.scheduling.annotation.Async) TechnologyCustomizer(com.qcadoo.mes.technologiesGenerator.customization.technology.TechnologyCustomizer) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) GeneratorContextFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields) TechnologiesGeneratorConstants(com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Lists(com.google.common.collect.Lists) TechnologyDataProvider(com.qcadoo.mes.technologies.dataProvider.TechnologyDataProvider) TechnologyNameAndNumberGenerator(com.qcadoo.mes.technologies.TechnologyNameAndNumberGenerator) GeneratorView(com.qcadoo.mes.technologiesGenerator.view.GeneratorView) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) TransactionAspectSupport(org.springframework.transaction.interceptor.TransactionAspectSupport) Logger(org.slf4j.Logger) TechnologyStructureNodeType(com.qcadoo.mes.technologiesGenerator.domain.TechnologyStructureNodeType) TechnologyStructureNodeDataProvider(com.qcadoo.mes.technologiesGenerator.dataProvider.TechnologyStructureNodeDataProvider) TechnologyStructureTreeDataProvider(com.qcadoo.mes.technologiesGenerator.dataProvider.TechnologyStructureTreeDataProvider) DataDefinition(com.qcadoo.model.api.DataDefinition) Entity(com.qcadoo.model.api.Entity) List(java.util.List) ParameterService(com.qcadoo.mes.basic.ParameterService) ProductFieldsTG(com.qcadoo.mes.technologiesGenerator.constants.ProductFieldsTG) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductCustomizer(com.qcadoo.mes.technologiesGenerator.customization.product.ProductCustomizer) Optional(java.util.Optional) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) GeneratorTreeNodeFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorTreeNodeFields) TechnologyProductsCustomizer(com.qcadoo.mes.technologiesGenerator.customization.technology.TechnologyProductsCustomizer) Transactional(org.springframework.transaction.annotation.Transactional) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either)

Aggregations

Either (com.qcadoo.commons.functional.Either)13 Entity (com.qcadoo.model.api.Entity)13 TechnologyId (com.qcadoo.mes.technologies.domain.TechnologyId)10 GeneratorSettings (com.qcadoo.mes.technologiesGenerator.GeneratorSettings)9 ProductSuffixes (com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes)8 QcadooModelMatchers.anyEntity (com.qcadoo.testing.model.QcadooModelMatchers.anyEntity)7 Test (org.junit.Test)7 Optional (java.util.Optional)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Service (org.springframework.stereotype.Service)5 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)4 List (java.util.List)4 Lists (com.google.common.collect.Lists)3 ParameterService (com.qcadoo.mes.basic.ParameterService)3 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)3 TechnologyService (com.qcadoo.mes.technologies.TechnologyService)3 GeneratorContextFields (com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)2