Search in sources :

Example 1 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.

the class DefaultEventHandlerTest method shouldCallEventMethod.

@Test
public void shouldCallEventMethod() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState component = new FormComponentState(pattern);
    component.setFieldValue(13L);
    // when
    component.performEvent(viewDefinitionState, "clear");
    // then
    assertNull("value is " + component.getFieldValue(), component.getFieldValue());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 2 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.

the class DefaultEventHandlerTest method shouldCallCustomEventMethod.

@Test
public void shouldCallCustomEventMethod() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState component = new FormComponentState(pattern);
    ViewEventListenerHook eventListener = mock(ViewEventListenerHook.class);
    given(eventListener.getEventName()).willReturn("custom");
    component.registerCustomEvent(eventListener);
    // when
    component.performEvent(viewDefinitionState, "custom", "arg0", "arg1");
    // then
    Mockito.verify(eventListener).invokeEvent(viewDefinitionState, component, new String[] { "arg0", "arg1" });
}
Also used : ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 3 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.

the class DefaultEventHandlerTest method shouldNotThrowExceptionWhenEventNotExists.

@Test
public void shouldNotThrowExceptionWhenEventNotExists() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState component = new FormComponentState(pattern);
    component.setFieldValue(13L);
    // when
    component.performEvent(viewDefinitionState, "noSuchMethod");
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 4 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.

the class FormComponentStateTest method init.

@Before
public void init() throws Exception {
    entity = mock(Entity.class);
    given(entity.getField("name")).willReturn("text");
    viewDefinitionState = mock(ViewDefinitionState.class);
    translationService = mock(TranslationService.class);
    fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(new StringType());
    given(fieldDefinition.getName()).willReturn("name");
    dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    given(dataDefinition.get(12L)).willReturn(null);
    given(dataDefinition.get(13L)).willReturn(entity);
    given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(dataDefinition.getName()).willReturn("name");
    given(dataDefinition.getField("name")).willReturn(fieldDefinition);
    given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
    given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            Long id = (Long) invocation.getArguments()[0];
            return new DefaultEntity(dataDefinition, id);
        }
    });
    FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
    given(namePattern.isRequired()).willReturn(false);
    given(namePattern.isPersistent()).willReturn(true);
    name = new FieldComponentState(namePattern);
    name.setTranslationService(translationService);
    name.setName("name");
    name.initialize(new JSONObject(), Locale.ENGLISH);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("'static expression'");
    applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    form = new FormComponentState(pattern);
    form.setDataDefinition(dataDefinition);
    form.setTranslationService(translationService);
    form.addFieldEntityIdChangeListener("name", name);
    form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    new ExpressionServiceImpl().init();
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Matchers.anyLong(org.mockito.Matchers.anyLong) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 5 with ViewDefinitionState

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

the class ProductsToIssueDetailsHooks method sortIssuesBasedOnFilter.

private List<Entity> sortIssuesBasedOnFilter(final ViewDefinitionState view, final List<Entity> createdIssues) {
    try {
        sortEntries: {
            String jsonKeyName = "window.mainTab.form.gridProductNumberFilter";
            final String gridProductNumberFilter;
            JSONObject jsonContext = view.getJsonContext();
            if (jsonContext.has(jsonKeyName) && isNotBlank(gridProductNumberFilter = jsonContext.getString(jsonKeyName))) {
                String[] productsNumbers = gridProductNumberFilter.substring(1, gridProductNumberFilter.length() - 1).split(",");
                List<String> productNumbersList = new ArrayList<>(Arrays.stream(productsNumbers).map(String::trim).filter(s -> !s.isEmpty()).map(String::toUpperCase).collect(Collectors.toCollection(LinkedHashSet::new)));
                if (productNumbersList.isEmpty()) {
                    break sortEntries;
                }
                Comparator<Entity> comparator = Comparator.comparing(e -> productNumbersList.indexOf(e.getBelongsToField(ProductsToIssueFields.PRODUCT).getStringField(ProductFields.NUMBER).toUpperCase()));
                createdIssues.sort(comparator);
            }
        }
        return createdIssues;
    } catch (JSONException e) {
        throw new IllegalStateException(e);
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) Arrays(java.util.Arrays) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) ResourceStockDtoFields(com.qcadoo.mes.materialFlowResources.constants.ResourceStockDtoFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HashMultimap(com.google.common.collect.HashMultimap) Optional(com.google.common.base.Optional) Map(java.util.Map) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) FieldComponent(com.qcadoo.view.api.components.FieldComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Multimap(com.google.common.collect.Multimap) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) ArrayList(java.util.ArrayList) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) LinkedHashSet(java.util.LinkedHashSet) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) Comparator(java.util.Comparator) StringUtils(org.springframework.util.StringUtils) LinkedHashSet(java.util.LinkedHashSet) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11