Search in sources :

Example 1 with BelongsToType

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;
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) HashMap(java.util.HashMap) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 2 with BelongsToType

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;
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 3 with BelongsToType

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"));
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 4 with BelongsToType

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) HibernateProxy(org.hibernate.proxy.HibernateProxy) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition)

Example 5 with BelongsToType

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);
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Map(java.util.Map) Before(org.junit.Before)

Aggregations

BelongsToType (com.qcadoo.model.api.types.BelongsToType)26 FieldDefinition (com.qcadoo.model.api.FieldDefinition)19 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)13 Entity (com.qcadoo.model.api.Entity)12 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)10 HasManyType (com.qcadoo.model.api.types.HasManyType)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)5 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)5 Before (org.junit.Before)4 EntityList (com.qcadoo.model.api.EntityList)2 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)2 FieldType (com.qcadoo.model.api.types.FieldType)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)2 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)2 Map (java.util.Map)2