Search in sources :

Example 1 with Either

use of com.qcadoo.commons.functional.Either in project mes by qcadoo.

the class ProductionTrackingServiceImpl method findExpirationDate.

@Override
public Either<Boolean, Optional<Date>> findExpirationDate(final Entity productionTracking, final Entity order, final Entity toc, final Entity batch) {
    if (TypeOfProductionRecording.CUMULATED.getStringValue().equals(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING))) {
        List<Entity> productionTracingsForOrder = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING).find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.belongsTo(ProductionTrackingFields.BATCH, batch)).list().getEntities();
        if (Objects.nonNull(productionTracking) && Objects.nonNull(productionTracking.getId())) {
            productionTracingsForOrder = productionTracingsForOrder.stream().filter(pt -> !pt.getId().equals(productionTracking.getId())).collect(Collectors.toList());
        }
        boolean nullDate = productionTracingsForOrder.stream().anyMatch(pt -> Objects.isNull(pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE)));
        if (nullDate) {
            return Either.left(true);
        }
        Optional<Date> maybeDate = productionTracingsForOrder.stream().filter(pt -> Objects.nonNull(pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE))).map(pt -> pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE)).findFirst();
        return Either.right(maybeDate);
    } else {
        Entity bpcq = basicProductionCountingService.getProductionCountingQuantityDD().find().add(SearchRestrictions.eq(ProductionCountingQuantityFields.ORDER + L_ID, order.getId())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.PRODUCED.getStringValue())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT + L_ID, toc.getId())).setMaxResults(1).uniqueResult();
        if (Objects.nonNull(bpcq) && bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCT).getId().equals(order.getBelongsToField(OrderFields.PRODUCT).getId())) {
            List<Entity> productionTracingsForOrder = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING).find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.belongsTo(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT, toc)).add(SearchRestrictions.belongsTo(ProductionTrackingFields.BATCH, batch)).list().getEntities();
            if (Objects.nonNull(productionTracking) && Objects.nonNull(productionTracking.getId())) {
                productionTracingsForOrder = productionTracingsForOrder.stream().filter(pt -> !pt.getId().equals(productionTracking.getId())).collect(Collectors.toList());
            }
            boolean nullDate = productionTracingsForOrder.stream().anyMatch(pt -> Objects.isNull(pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE)));
            if (nullDate) {
                return Either.left(true);
            }
            Optional<Date> maybeDate = productionTracingsForOrder.stream().filter(pt -> Objects.nonNull(pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE))).map(pt -> pt.getDateField(ProductionTrackingFields.EXPIRATION_DATE)).findFirst();
            return Either.right(maybeDate);
        }
    }
    return null;
}
Also used : ProductionTrackingFields(com.qcadoo.mes.productionCounting.constants.ProductionTrackingFields) TrackingOperationProductOutComponentFields(com.qcadoo.mes.productionCounting.constants.TrackingOperationProductOutComponentFields) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) BasicProductionCountingService(com.qcadoo.mes.basicProductionCounting.BasicProductionCountingService) TrackingOperationProductInComponentFields(com.qcadoo.mes.productionCounting.constants.TrackingOperationProductInComponentFields) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) FieldComponent(com.qcadoo.view.api.components.FieldComponent) ProductUnitsConversionService(com.qcadoo.mes.basic.util.ProductUnitsConversionService) LookupComponent(com.qcadoo.view.api.components.LookupComponent) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Optional(java.util.Optional) WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) StaffWorkTimeFields(com.qcadoo.mes.productionCounting.constants.StaffWorkTimeFields) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) OrderFieldsPC(com.qcadoo.mes.productionCounting.constants.OrderFieldsPC) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) ProductionCountingQuantityFields(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityFields) ProductionTrackingStateServiceMarker(com.qcadoo.mes.productionCounting.newstates.ProductionTrackingStateServiceMarker) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) ProductionCountingConstants(com.qcadoo.mes.productionCounting.constants.ProductionCountingConstants) UsedBatchFields(com.qcadoo.mes.productionCounting.constants.UsedBatchFields) TypeOfProductionRecording(com.qcadoo.mes.productionCounting.constants.TypeOfProductionRecording) SecurityService(com.qcadoo.security.api.SecurityService) ProductionTrackingState(com.qcadoo.mes.productionCounting.states.constants.ProductionTrackingState) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) JoinType(com.qcadoo.model.api.search.JoinType) StateChangeContextBuilder(com.qcadoo.mes.states.service.StateChangeContextBuilder) ProductionCountingQuantityRole(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityRole) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) StateExecutorService(com.qcadoo.mes.newstates.StateExecutorService) ProductionTrackingStateStringValues(com.qcadoo.mes.productionCounting.states.constants.ProductionTrackingStateStringValues) Entity(com.qcadoo.model.api.Entity) Date(java.util.Date)

Example 2 with Either

use of com.qcadoo.commons.functional.Either in project mes by qcadoo.

the class GeneratorViewListeners method customize.

private void customize(final GeneratorView generatorView) {
    Entity context = generatorView.getFormEntity();
    Optional<Either<String, TechnologyId>> customizedTechId = tryPerformCustomization(generatorView, context);
    customizedTechId.ifPresent(res -> {
        if (res.isLeft()) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn(res.getLeft());
            }
            generatorView.showErrorMsg("technologiesGenerator.generate.error.problemDuringCustomization");
        } else {
            generatorView.redirectToTechnology(res.getRight().get());
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) Either(com.qcadoo.commons.functional.Either)

Example 3 with Either

use of com.qcadoo.commons.functional.Either in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithMainProduct.

@Test
public final void shouldCreateCustomizedTechnologyWithMainProduct() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    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).customize(new TechnologyId(technologyCopy.getId()), mainProduct, mainProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    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 4 with Either

use of com.qcadoo.commons.functional.Either in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithCopiedAndCustomizedProduct.

@Test
public final void shouldCreateCustomizedTechnologyWithCopiedAndCustomizedProduct() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, mockEntity(), nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    Entity customizedProduct = mockEntity();
    stubIsValid(customizedProduct, true);
    stubProductCustomizer(customizedProduct);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(customizedProduct, 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).customize(new TechnologyId(technologyCopy.getId()), mainProduct, customizedProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    verify(technologyNameAndNumberGenerator).generateName(customizedProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(customizedProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer).findOrCreate(anyEntity(), anyEntity(), eq(new ProductSuffixes(new ProductNumberSuffix(MAIN_PROD_NUMBER), new ProductNameSuffix(MAIN_PROD_NAME))), 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) ProductNameSuffix(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductNameSuffix) Either(com.qcadoo.commons.functional.Either) ProductNumberSuffix(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductNumberSuffix) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 5 with Either

use of com.qcadoo.commons.functional.Either in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithMainProductEvenIfTechnologyOutputProductIsNotAProductsFamily.

@Test
public final void shouldCreateCustomizedTechnologyWithMainProductEvenIfTechnologyOutputProductIsNotAProductsFamily() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PARTICULAR_PRODUCT);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    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).customize(new TechnologyId(technologyCopy.getId()), mainProduct, mainProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    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)

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