Search in sources :

Example 31 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AdvancedGenealogyTreeViewListenersTest method shouldGenerateUsedToProduceTree.

@SuppressWarnings("unchecked")
@Test
public void shouldGenerateUsedToProduceTree() {
    // given
    Entity batch = mock(Entity.class);
    when(batch.getId()).thenReturn(1L);
    when(batch.getField("parent")).thenReturn(null);
    when(batch.getField("priority")).thenReturn(1);
    when(batch.getField("entityType")).thenReturn("batch");
    ComponentState includeDraftComponent = mock(ComponentState.class);
    ComponentState treeTypeComponent = mock(ComponentState.class);
    when(batchLookup.getFieldValue()).thenReturn(1L);
    when(dataDefinition.get(1L)).thenReturn(batch);
    when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
    String includeDraftsString = "0";
    when(includeDraftComponent.getFieldValue()).thenReturn(includeDraftsString);
    boolean includeDrafts = "1".equals(includeDraftsString);
    when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
    when(treeTypeComponent.getFieldValue()).thenReturn("02usedToProduce");
    List<Entity> tree = mock(List.class);
    when(advancedGenealogyTreeService.getUsedToProduceTree(batch, includeDrafts, true)).thenReturn(tree);
    Iterator<Entity> treeIterator = mock(Iterator.class);
    when(treeIterator.hasNext()).thenReturn(true, false);
    when(treeIterator.next()).thenReturn(batch);
    when(tree.iterator()).thenReturn(treeIterator);
    ComponentState genealogyTree = mock(ComponentState.class);
    when(view.getComponentByReference("genealogyTree")).thenReturn(genealogyTree);
    // when
    viewListeners.generateFormEntity(view, state);
    // then
    verify(advancedGenealogyTreeService).getUsedToProduceTree(batch, includeDrafts, true);
    verify(formEntity).setField("producedBatch", batch);
    verify(formEntity).setField(eq("genealogyTree"), any(EntityTree.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 32 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AdvancedGenealogyTreeViewListenersTest method shouldGenerateProducedFromTree.

@SuppressWarnings("unchecked")
@Test
public void shouldGenerateProducedFromTree() {
    // given
    Entity batch = mock(Entity.class);
    when(batch.getId()).thenReturn(1L);
    when(batch.getField("parent")).thenReturn(null);
    when(batch.getField("priority")).thenReturn(1);
    when(batch.getField("entityType")).thenReturn("batch");
    ComponentState includeDraftComponent = mock(ComponentState.class);
    ComponentState treeTypeComponent = mock(ComponentState.class);
    when(batchLookup.getFieldValue()).thenReturn(1L);
    when(dataDefinition.get(1L)).thenReturn(batch);
    when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
    String includeDraftsString = "0";
    when(includeDraftComponent.getFieldValue()).thenReturn(includeDraftsString);
    boolean includeDrafts = "1".equals(includeDraftsString);
    when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
    when(treeTypeComponent.getFieldValue()).thenReturn("01producedFrom");
    List<Entity> tree = mock(List.class);
    when(advancedGenealogyTreeService.getProducedFromTree(batch, includeDrafts, true)).thenReturn(tree);
    Iterator<Entity> treeIterator = mock(Iterator.class);
    when(treeIterator.hasNext()).thenReturn(true, false);
    when(treeIterator.next()).thenReturn(batch);
    when(tree.iterator()).thenReturn(treeIterator);
    ComponentState genealogyTree = mock(ComponentState.class);
    when(view.getComponentByReference("genealogyTree")).thenReturn(genealogyTree);
    // when
    viewListeners.generateFormEntity(view, state);
    // then
    verify(advancedGenealogyTreeService).getProducedFromTree(batch, includeDrafts, true);
    verify(formEntity).setField("producedBatch", batch);
    verify(formEntity).setField(eq("genealogyTree"), any(EntityTree.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 33 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ProductionCountingQuantityAdvancedDetailsHooks method hideFieldsDependsOfState.

private void hideFieldsDependsOfState(final ViewDefinitionState view) {
    FormComponent productionCountingQuantityForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    ComponentState usedQuantityGridLayout = view.getComponentByReference(L_USED_QUANTITY_GRID_LAYOUT);
    ComponentState producedQuantityGridLayout = view.getComponentByReference(L_PRODUCED_QUANTITY_GRID_LAYOUT);
    FieldComponent roleField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.ROLE);
    Long productionCountingQuantityId = productionCountingQuantityForm.getEntityId();
    boolean isEnabled = (productionCountingQuantityId != null);
    boolean isUsed = checkIfIsUsed((String) roleField.getFieldValue());
    boolean isProduced = checkIfIsProduced((String) roleField.getFieldValue());
    updateComponentState(usedQuantityGridLayout, isEnabled && isUsed);
    updateComponentState(producedQuantityGridLayout, isEnabled && isProduced);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 34 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AdvancedGenealogyTreeViewListenersTest method shouldStopGeneratingTreeAndAddCertainMessageIfNoTreeTypeIsSelected.

@Test(expected = FormValidationException.class)
public void shouldStopGeneratingTreeAndAddCertainMessageIfNoTreeTypeIsSelected() {
    // given
    Entity batch = mock(Entity.class);
    ComponentState includeDraftComponent = mock(ComponentState.class);
    ComponentState treeTypeComponent = mock(ComponentState.class);
    when(batchLookup.getFieldValue()).thenReturn(1L);
    when(dataDefinition.get(1L)).thenReturn(batch);
    when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
    when(includeDraftComponent.getFieldValue()).thenReturn("0");
    when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
    when(treeTypeComponent.getFieldValue()).thenReturn(null);
    // when
    viewListeners.generateFormEntity(view, state);
// then
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 35 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ProductDetailsHooks method enableCharacteristicsTabForExternalItems.

public void enableCharacteristicsTabForExternalItems(final ViewDefinitionState view) {
    FormComponent productForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long productId = productForm.getEntityId();
    if (Objects.isNull(productId)) {
        return;
    }
    Entity product = getProductDD().get(productId);
    if (Objects.isNull(product)) {
        return;
    }
    String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER);
    if (!StringUtils.isEmpty(externalNumber)) {
        for (String componentName : innerComponents) {
            ComponentState characteristicsTab = view.getComponentByReference(componentName);
            characteristicsTab.setEnabled(true);
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) ComponentState(com.qcadoo.view.api.ComponentState)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8