Search in sources :

Example 6 with TechnologyId

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

the class TechnologyProductsCustomizerTest method shouldFailDueToOutputOperationComponentValidationErrors.

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

Example 7 with TechnologyId

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

the class TechnologyStructureTreeDataProvider method buildProductInfo.

private ProductInfo buildProductInfo(final Entity projection, final Map<ProductId, TechnologyId> defaultTechnologies) {
    Optional<OperationProductInComponentId> opicId = Optional.ofNullable((Long) projection.getField("opicId")).map(OperationProductInComponentId::new);
    TechnologyOperationId tocId = new TechnologyOperationId((Long) projection.getField("tocId"));
    Optional<TechnologyOperationId> parentId = Optional.ofNullable((Long) projection.getField("parentId")).map(TechnologyOperationId::new);
    ProductId productId = buildProduct(projection);
    Optional<TechnologyId> prodTechnology = Optional.ofNullable(defaultTechnologies.get(productId));
    Optional<TechnologyInputProductTypeId> technologyInputProductType = Optional.ofNullable((Long) projection.getField("technologyInputProductTypeId")).map(TechnologyInputProductTypeId::new);
    boolean differentProductsInDifferentSizes = projection.getBooleanField("differentProductsInDifferentSizes");
    boolean variousQuantitiesInProductsBySize = projection.getBooleanField("variousQuantitiesInProductsBySize");
    OperationId operation = buildOperation(projection);
    BigDecimal quantity = projection.getDecimalField("quantity");
    boolean isIntermediate = projection.getBooleanField("isIntermediate");
    String givenUnit = projection.getStringField("givenUnit");
    Optional<SizeGroupId> sizeGroup = Optional.ofNullable((Long) projection.getField("sizeGroupId")).map(SizeGroupId::new);
    return new ProductInfo(opicId, tocId, parentId, productId, quantity, prodTechnology, prodTechnology, technologyInputProductType, differentProductsInDifferentSizes, variousQuantitiesInProductsBySize, operation, isIntermediate, givenUnit, sizeGroup);
}
Also used : ProductInfo(com.qcadoo.mes.technologiesGenerator.domain.ProductInfo) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) TechnologyInputProductTypeId(com.qcadoo.mes.technologies.domain.TechnologyInputProductTypeId) TechnologyOperationId(com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId) OperationId(com.qcadoo.mes.technologies.domain.OperationId) ProductId(com.qcadoo.mes.basic.product.domain.ProductId) TechnologyOperationId(com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId) BigDecimal(java.math.BigDecimal) SizeGroupId(com.qcadoo.mes.technologies.domain.SizeGroupId) OperationProductInComponentId(com.qcadoo.mes.technologies.domain.OperationProductInComponentId)

Example 8 with TechnologyId

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

the class TechnologyStructureTreeDataProvider method findExistingCustomizedNodes.

public Map<TechnologyId, Entity> findExistingCustomizedNodes(final ContextId contextId) {
    if (Objects.isNull(contextId)) {
        return ImmutableMap.of();
    }
    SearchCriteriaBuilder scb = prepareExistingNodeSearchCriteria(contextId);
    List<Entity> existingNodes = scb.list().getEntities();
    return ImmutableMap.copyOf(Maps.uniqueIndex(existingNodes, n -> new TechnologyId(n.getBelongsToField(GeneratorTreeNodeFields.ORIGINAL_TECHNOLOGY).getId())));
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions.isNull(com.qcadoo.model.api.search.SearchRestrictions.isNull) OperationProductInComponentId(com.qcadoo.mes.technologies.domain.OperationProductInComponentId) TechnologiesGeneratorConstants(com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SearchProjections.id(com.qcadoo.model.api.search.SearchProjections.id) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) BigDecimal(java.math.BigDecimal) TechnologyOperationId(com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId) Service(org.springframework.stereotype.Service) ProductId(com.qcadoo.mes.basic.product.domain.ProductId) Map(java.util.Map) SizeGroupId(com.qcadoo.mes.technologies.domain.SizeGroupId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableMap(com.google.common.collect.ImmutableMap) SearchRestrictions.idEq(com.qcadoo.model.api.search.SearchRestrictions.idEq) SearchRestrictions.neField(com.qcadoo.model.api.search.SearchRestrictions.neField) SearchRestrictions.belongsTo(com.qcadoo.model.api.search.SearchRestrictions.belongsTo) SearchRestrictions.isNotNull(com.qcadoo.model.api.search.SearchRestrictions.isNotNull) 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) ProductInfo(com.qcadoo.mes.technologiesGenerator.domain.ProductInfo) Optional(java.util.Optional) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) GeneratorTreeNodeFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorTreeNodeFields) OperationId(com.qcadoo.mes.technologies.domain.OperationId) Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId)

Example 9 with TechnologyId

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

the class TechnologiesGeneratorForProductsService method setupTechnologyNumberAndName.

private Either<String, TechnologyId> setupTechnologyNumberAndName(final GeneratorSettings settings, final Entity technology, final Entity product) {
    technology.setField("generatorContext", settings.getGenerationContext());
    technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
    technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
    Entity savedTech = technology.getDataDefinition().save(technology);
    if (savedTech.isValid()) {
        LOG.info(String.format("Generated technology with number : %S", technology.getStringField(TechnologyFields.NUMBER)));
        return Either.right(new TechnologyId(savedTech.getId()));
    } else {
        return Either.left("Cannot setup technology name and number due to validation errors");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId)

Example 10 with TechnologyId

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

the class TechnologyCustomizer method setupTechnologyNumberAndName.

private Either<String, TechnologyId> setupTechnologyNumberAndName(final Entity technology, final Entity product) {
    technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
    technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
    Entity savedTech = technology.getDataDefinition().save(technology);
    if (savedTech.isValid()) {
        return Either.right(new TechnologyId(savedTech.getId()));
    } else {
        return Either.left("Cannot setup technology name and number due to validation errors");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId)

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