Search in sources :

Example 11 with TechnologyId

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

the class GeneratorViewListeners method tryPerformCustomization.

private Optional<Either<String, TechnologyId>> tryPerformCustomization(final GeneratorView generatorView, final Entity context) {
    try {
        Optional<Either<String, TechnologyId>> customizedTechId = Optional.ofNullable(context.getBelongsToField(GeneratorContextFields.PRODUCT)).flatMap(mainProduct -> generatorView.getSelectedNodeId().flatMap(nodeId -> technologyCustomizer.customize(nodeId, mainProduct, GeneratorSettings.from(context, parameterService.getParameter()), false)));
        customizedTechId.ifPresent(cti -> {
            if (cti.isRight()) {
                TechnologyId technologyId = cti.getRight();
                technologyCustomizer.addCustomizedProductToQualityCard(technologyId);
            }
        });
        return customizedTechId;
    } catch (Exception e) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("Cannot perform technology customization due to unexpected error", e);
        }
        return Optional.of(Either.left("Cannot perform technology customization due to unexpected error"));
    }
}
Also used : TechnologiesGeneratorForProductsService(com.qcadoo.mes.technologiesGenerator.TechnologiesGeneratorForProductsService) TechnologyCustomizer(com.qcadoo.mes.technologiesGenerator.customization.technology.TechnologyCustomizer) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) GeneratorContextFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields) ComponentState(com.qcadoo.view.api.ComponentState) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) ContextId(com.qcadoo.mes.technologiesGenerator.domain.ContextId) GridComponent(com.qcadoo.view.api.components.GridComponent) TreeGenerator(com.qcadoo.mes.technologiesGenerator.tree.TreeGenerator) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ParameterService(com.qcadoo.mes.basic.ParameterService) GeneratorView(com.qcadoo.mes.technologiesGenerator.view.GeneratorView) Service(org.springframework.stereotype.Service) Either(com.qcadoo.commons.functional.Either) Optional(java.util.Optional) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either)

Example 12 with TechnologyId

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

the class TreeGenerator method performGeneration.

private Either<String, ContextId> performGeneration(final Entity context, final GeneratorSettings settings, boolean applyCustomized) {
    Entity technology = context.getBelongsToField(GeneratorContextFields.TECHNOLOGY);
    TechnologyId technologyId = new TechnologyId(technology.getId());
    ContextId contextId = new ContextId(context.getId());
    Map<OperationProductKey, Long> customizedOperationProductTechnologies = getCustomizedTechnologies(context, applyCustomized);
    Either<String, TechnologyStructureNode> mRoot = tryBuildStructure(settings, technologyId, contextId);
    Either<String, Entity> generationResults = mRoot.flatMap(root -> regenerateNodes(context, root).flatMap(x -> markContextAsGenerated(contextId)));
    if (applyCustomized) {
        updateNodesToCustomized(context, customizedOperationProductTechnologies);
    }
    logResults(generationResults);
    return generationResults.map(Entity::getId).map(ContextId::new);
}
Also used : TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) GeneratorContextFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields) LoggerFactory(org.slf4j.LoggerFactory) TechnologiesGeneratorConstants(com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) TechnologyStructureNode(com.qcadoo.mes.technologiesGenerator.domain.TechnologyStructureNode) TechnologyOperationId(com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId) Service(org.springframework.stereotype.Service) Map(java.util.Map) SizeGroupId(com.qcadoo.mes.technologies.domain.SizeGroupId) Logger(org.slf4j.Logger) OperationProductKey(com.qcadoo.mes.technologiesGenerator.domain.OperationProductKey) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) TechnologyStructureNodeType(com.qcadoo.mes.technologiesGenerator.domain.TechnologyStructureNodeType) TechnologyStructureTreeDataProvider(com.qcadoo.mes.technologiesGenerator.dataProvider.TechnologyStructureTreeDataProvider) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ContextId(com.qcadoo.mes.technologiesGenerator.domain.ContextId) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) JoinType(com.qcadoo.model.api.search.JoinType) List(java.util.List) TechnologyInputProductTypeId(com.qcadoo.mes.technologies.domain.TechnologyInputProductTypeId) Entity(com.qcadoo.model.api.Entity) GeneratorContextDataProvider(com.qcadoo.mes.technologiesGenerator.dataProvider.GeneratorContextDataProvider) ProductInfo(com.qcadoo.mes.technologiesGenerator.domain.ProductInfo) Either(com.qcadoo.commons.functional.Either) Optional(java.util.Optional) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) GeneratorTreeNodeFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorTreeNodeFields) Transactional(org.springframework.transaction.annotation.Transactional) OperationId(com.qcadoo.mes.technologies.domain.OperationId) Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) ContextId(com.qcadoo.mes.technologiesGenerator.domain.ContextId) TechnologyStructureNode(com.qcadoo.mes.technologiesGenerator.domain.TechnologyStructureNode) OperationProductKey(com.qcadoo.mes.technologiesGenerator.domain.OperationProductKey)

Example 13 with TechnologyId

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

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

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

the class TechnologyProductsCustomizerTest method shouldFailDueToInputOperationComponentValidationErrors.

@Test
@Ignore
public final void shouldFailDueToInputOperationComponentValidationErrors() {
    // given
    Entity technology = mockEntity(TECH_ID, true);
    stubTechnologyLookup(technology);
    Long mainOpocId = 100L;
    Entity mainOutputProductComponent = mockEntity(mainOpocId, true);
    stubMainOutputProductComponentLookup(mainOutputProductComponent);
    stubOutputComponents(mockOutputComponent(300L, true, EntityTestUtils.mockEntity()));
    Entity opic = mockInputComponent(400L, false, EntityTestUtils.mockEntity());
    stubInputComponents(opic);
    // when
    Either<String, TechnologyId> result = technologyProductsCustomizer.customize(technologyId, mainProduct, newProduct, generatorSettings);
    // then
    Assert.assertTrue(result.isLeft());
    Assert.assertEquals(productComponentValidationErrorMessage(opic), 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

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