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;
}
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());
}
});
}
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));
}
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));
}
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));
}
Aggregations