use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class FieldComponentPattern method getJspOptions.
@Override
protected Map<String, Object> getJspOptions(final Locale locale) {
Map<String, Object> options = new HashMap<String, Object>();
Map<String, Object> translations = new HashMap<String, Object>();
if (getFieldDefinition() == null) {
translations.put(LABEL, getTranslationService().translate(getTranslationPath() + LABEL_SUFFIX, locale));
} else {
String code1 = getFieldDefinition().getDataDefinition().getPluginIdentifier() + "." + getFieldDefinition().getDataDefinition().getName() + "." + getFieldDefinition().getName() + LABEL_SUFFIX;
if (BelongsToType.class.isAssignableFrom(getFieldDefinition().getType().getClass())) {
DataDefinition fieldDataDefinition = ((BelongsToType) getFieldDefinition().getType()).getDataDefinition();
String code2 = fieldDataDefinition.getPluginIdentifier() + "." + fieldDataDefinition.getName() + "." + getFieldDefinition().getName() + LABEL_SUFFIX;
translations.put(LABEL, getTranslationService().translate(getTranslationPath() + LABEL_SUFFIX, code1, code2, locale));
} else {
translations.put(LABEL, getTranslationService().translate(getTranslationPath() + LABEL_SUFFIX, code1, locale));
}
}
if (isHasDescription()) {
translations.put("description", getTranslationService().translate(getTranslationPath() + ".description", locale));
translations.put("descriptionHeader", getTranslationService().translate(getTranslationPath() + ".descriptionHeader", "qcadooView.form.descriptionHeader", locale));
}
options.put("translations", translations);
options.put("labelWidth", labelWidth);
return options;
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class GridComponentFilterUtilsTest method mockBelongsToField.
private FieldDefinition mockBelongsToField(final String fieldName, final DataDefinition sourceDataDefinition, final DataDefinition targetDataDefinition) {
final FieldDefinition belongsToField = mock(FieldDefinition.class);
given(belongsToField.getName()).willReturn(fieldName);
final BelongsToType belongsToType = mock(BelongsToType.class);
given(belongsToField.getType()).willReturn(belongsToType);
given(belongsToType.getDataDefinition()).willReturn(targetDataDefinition);
given(sourceDataDefinition.getField(fieldName)).willReturn(belongsToField);
return belongsToField;
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromBelongsToTypeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromBelongsToTypeFieldDefinition() throws Exception {
// given
BelongsToType fieldType = mock(BelongsToType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class EntityServiceImpl method getBelongsToField.
private Object getBelongsToField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Entity performer) {
BelongsToType belongsToFieldType = (BelongsToType) fieldDefinition.getType();
InternalDataDefinition referencedDataDefinition = (InternalDataDefinition) belongsToFieldType.getDataDefinition();
Object value = getField(databaseEntity, fieldDefinition.getName());
if (value == null) {
return null;
}
if (performer != null && referencedDataDefinition.equals(performer.getDataDefinition()) && performer.getId() != null && performer.getId().equals(getId(value))) {
return performer;
}
if (belongsToFieldType.isLazyLoading()) {
Long id = null;
if (value instanceof HibernateProxy) {
id = (Long) ((HibernateProxy) value).getHibernateLazyInitializer().getIdentifier();
} else {
id = getId(getField(databaseEntity, fieldDefinition.getName()));
}
if (id == null) {
return null;
}
return new ProxyEntity(referencedDataDefinition, id);
} else {
Entity currentPerformer = performer;
if (performer == null || performer.getId() == null && referencedDataDefinition.equals(performer.getDataDefinition())) {
currentPerformer = new ProxyEntity(referencedDataDefinition, getId(value));
}
return convertToGenericEntity(referencedDataDefinition, value, currentPerformer);
}
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class AbstractEntityWrapperTest method superInit.
@Before
public final void superInit() {
belongsToFieldDefinition = mock(FieldDefinition.class);
BelongsToType belongsToType = mock(BelongsToType.class);
when(belongsToFieldDefinition.getType()).thenReturn(belongsToType);
belongsToFieldDataDefinition = mock(DataDefinition.class);
when(belongsToFieldDefinition.getDataDefinition()).thenReturn(belongsToFieldDataDefinition);
FieldDefinition stringFieldDefinition = mock(FieldDefinition.class);
when(stringFieldDefinition.isPersistent()).thenReturn(false);
dataDefinition = mock(DataDefinition.class);
FieldDefinition booleanFieldDefinition = mock(FieldDefinition.class);
Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
fieldsMap.put(BELONGS_TO_FIELD_NAME, belongsToFieldDefinition);
fieldsMap.put(STRING_FIELD_NAME, stringFieldDefinition);
fieldsMap.put(BOOLEAN_FIELD_NAME, booleanFieldDefinition);
for (Map.Entry<String, FieldDefinition> fieldEntry : fieldsMap.entrySet()) {
when(dataDefinition.getField(fieldEntry.getKey())).thenReturn(fieldEntry.getValue());
}
when(dataDefinition.getFields()).thenReturn(fieldsMap);
}
Aggregations