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