Search in sources :

Example 16 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyProductsCustomizerTest method shouldFailDueToMainOutputProductComponentValidationErrors.

@Test
public final void shouldFailDueToMainOutputProductComponentValidationErrors() {
    // given
    Entity technology = mockEntity(TECH_ID, true);
    stubTechnologyLookup(technology);
    Long mainOpocId = 100L;
    Entity mainOutputProductComponent = mockOutputComponent(mainOpocId, false, EntityTestUtils.mockEntity());
    stubMainOutputProductComponentLookup(mainOutputProductComponent);
    // when
    Either<String, TechnologyId> result = technologyProductsCustomizer.customize(technologyId, mainProduct, newProduct, generatorSettings);
    // then
    Assert.assertTrue(result.isLeft());
    Assert.assertEquals(productComponentValidationErrorMessage(mainOutputProductComponent), result.getLeft());
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Test(org.junit.Test)

Example 17 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyProductsCustomizerTest method shouldCustomize.

@Test
@Ignore
public final void shouldCustomize() {
    // given
    Entity technology = mockEntity(TECH_ID, true);
    stubTechnologyLookup(technology);
    Long mainOpocId = 100L;
    Entity mainOutputProductComponent = mockEntity(mainOpocId, true);
    stubMainOutputProductComponentLookup(mainOutputProductComponent);
    Entity customizedOpocProd = mockEntity(1101L, true);
    Entity opoc = mockOutputComponent(300L, true, customizedOpocProd);
    stubOutputComponents(opoc);
    Entity customizedOpicProd = mockEntity(2101L, true);
    Entity opic = mockInputComponent(400L, true, customizedOpicProd);
    stubInputComponents(opic);
    // when
    Either<String, TechnologyId> result = technologyProductsCustomizer.customize(technologyId, mainProduct, newProduct, generatorSettings);
    // then
    Assert.assertTrue(result.isRight());
    Assert.assertEquals(technologyId, result.getRight());
    verify(technology).setField(TechnologyFields.PRODUCT, newProduct);
    verify(opic).setField(OperationProductInComponentFields.PRODUCT, customizedOpicProd);
    verify(opoc).setField(OperationProductOutComponentFields.PRODUCT, customizedOpocProd);
    verify(mainOutputProductComponent).setField(OperationProductOutComponentFields.PRODUCT, newProduct);
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyProductsCustomizerTest method shouldFailDueToTechnologyValidationErrors.

@Test
public final void shouldFailDueToTechnologyValidationErrors() {
    // given
    Entity technology = mockEntity(TECH_ID, true, mockEntity(TECH_ID, false));
    stubTechnologyLookup(technology);
    // when
    Either<String, TechnologyId> result = technologyProductsCustomizer.customize(technologyId, mainProduct, newProduct, generatorSettings);
    // then
    Assert.assertTrue(result.isLeft());
    Assert.assertEquals("Validation error while customizing technology product.", result.getLeft());
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Test(org.junit.Test)

Example 19 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId 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

TechnologyId (com.qcadoo.mes.technologies.domain.TechnologyId)19 Entity (com.qcadoo.model.api.Entity)18 QcadooModelMatchers.anyEntity (com.qcadoo.testing.model.QcadooModelMatchers.anyEntity)12 Test (org.junit.Test)12 Either (com.qcadoo.commons.functional.Either)10 GeneratorSettings (com.qcadoo.mes.technologiesGenerator.GeneratorSettings)9 ProductSuffixes (com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes)8 Optional (java.util.Optional)4 OperationId (com.qcadoo.mes.technologies.domain.OperationId)3 SizeGroupId (com.qcadoo.mes.technologies.domain.SizeGroupId)3 TechnologyInputProductTypeId (com.qcadoo.mes.technologies.domain.TechnologyInputProductTypeId)3 TechnologyOperationId (com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId)3 GeneratorContextFields (com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields)3 GeneratorTreeNodeFields (com.qcadoo.mes.technologiesGenerator.constants.GeneratorTreeNodeFields)3 TechnologiesGeneratorConstants (com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants)3 ContextId (com.qcadoo.mes.technologiesGenerator.domain.ContextId)3 DataDefinition (com.qcadoo.model.api.DataDefinition)3 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)3 List (java.util.List)3 Logger (org.slf4j.Logger)3