Search in sources :

Example 86 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class ReplaceCustomTranslationsListeners method replaceCustomTranslations.

public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE);
    FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM);
    FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO);
    String locale = (String) localeField.getFieldValue();
    String replaceFrom = (String) replaceFromField.getFieldValue();
    String replaceTo = (String) replaceToField.getFieldValue();
    if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) {
        replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE);
    } else {
        List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale);
        if (customTranslations.isEmpty()) {
            replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO);
        } else {
            int count = 0;
            for (Entity customTranslation : customTranslations) {
                String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION);
                if (translation.contains(replaceFrom)) {
                    count++;
                    translation = translation.replace(replaceFrom, replaceTo);
                    customTranslation.setField(CUSTOM_TRANSLATION, translation);
                    customTranslation.getDataDefinition().save(customTranslation);
                }
            }
            if (count > 0) {
                replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS);
            } else {
                replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 87 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class AwesomeDynamicListModelUtilsImplTest method shouldSetProxyEntityInPlaceOfEntity.

@Test
public final void shouldSetProxyEntityInPlaceOfEntity() throws Exception {
    // given
    Entity belongsToEntity = mock(Entity.class);
    when(belongsToEntity.getId()).thenReturn(1L);
    when(entity.getField(BELONGS_TO_FIELD_NAME)).thenReturn(belongsToEntity);
    ArgumentCaptor<Entity> entityCaptor = ArgumentCaptor.forClass(Entity.class);
    // when
    awesomeDynamicListModelUtils.proxyBelongsToFields(entity);
    // then
    verify(entity, Mockito.times(1)).setField(Mockito.eq(BELONGS_TO_FIELD_NAME), entityCaptor.capture());
    assertProxy(entityCaptor.getValue());
}
Also used : Entity(com.qcadoo.model.api.Entity) Test(org.junit.Test)

Example 88 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class LookupComponentStateTest method shouldReturnNullWhenEntityDoesnotExistsInDB.

@Test
public void shouldReturnNullWhenEntityDoesnotExistsInDB() throws Exception {
    // given
    Long id = 1L;
    lookup.setFieldValue(id);
    when(dataDefinition.get(id)).thenReturn(null);
    // when
    Entity result = lookup.getEntity();
    // then
    Assert.assertNull(result);
}
Also used : Entity(com.qcadoo.model.api.Entity) Test(org.junit.Test)

Example 89 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class LookupComponentStateTest method shouldReturnNullWhenValueIsNull.

@Test
public void shouldReturnNullWhenValueIsNull() throws Exception {
    lookup.setFieldValue(null);
    // when
    Entity result = lookup.getEntity();
    // then
    Assert.assertNull(result);
}
Also used : Entity(com.qcadoo.model.api.Entity) Test(org.junit.Test)

Example 90 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldCreateCategory.

@Test
public final void shouldCreateCategory() {
    // given
    MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE);
    given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(null);
    given(menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY)).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            DataDefinition dataDefinition = mock(DataDefinition.class);
            return new DefaultEntity(dataDefinition);
        }
    });
    given(menuCrudService.getTotalNumberOfCategories()).willReturn(3);
    // when
    menuService.createCategory(menuCategoryDefinition);
    // then
    verify(menuCrudService).save(entityCaptor.capture());
    Entity savedItem = entityCaptor.getValue();
    assertEquals(PLUGIN_IDENTIFIER, savedItem.getStringField(MenuCategoryFields.PLUGIN_IDENTIFIER));
    assertEquals("categoryName", savedItem.getStringField(MenuCategoryFields.NAME));
    assertEquals(3, savedItem.getField(MenuCategoryFields.SUCCESSION));
    assertEquals(ROLE_VISIBLE, savedItem.getStringField(MenuCategoryFields.AUTH_ROLE));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)2833 FormComponent (com.qcadoo.view.api.components.FormComponent)514 Test (org.junit.Test)491 BigDecimal (java.math.BigDecimal)376 DataDefinition (com.qcadoo.model.api.DataDefinition)337 FieldComponent (com.qcadoo.view.api.components.FieldComponent)210 LookupComponent (com.qcadoo.view.api.components.LookupComponent)188 Date (java.util.Date)185 List (java.util.List)149 GridComponent (com.qcadoo.view.api.components.GridComponent)141 Map (java.util.Map)124 Autowired (org.springframework.beans.factory.annotation.Autowired)114 Service (org.springframework.stereotype.Service)112 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)105 Transactional (org.springframework.transaction.annotation.Transactional)101 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)100 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)95 Collectors (java.util.stream.Collectors)87 Lists (com.google.common.collect.Lists)75 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)75