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