Search in sources :

Example 1 with FieldDefinition

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

the class TranslatedFieldComponentState method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject json = new JSONObject();
    String value = (String) getFieldValue();
    FieldDefinition fieldDefinition = pattern.getFieldComponentFieldDefinition();
    if (fieldDefinition != null && EnumeratedType.class.isAssignableFrom(fieldDefinition.getType().getClass())) {
        value = ((EnumeratedType) fieldDefinition.getType()).activeValues(getLocale()).get(value);
    }
    json.put(JSON_VALUE, value);
    json.put(JSON_REQUIRED, isRequired());
    return json;
}
Also used : JSONObject(org.json.JSONObject) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 2 with FieldDefinition

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

the class PriorityServiceImpl method getCriteria.

private Criteria getCriteria(final InternalDataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Object databaseEntity) {
    Criteria criteria = hibernateService.getCurrentSession().createCriteria(dataDefinition.getClassForEntity());
    FieldDefinition scopeFieldDefinition = getScopeForPriority(fieldDefinition);
    if (scopeFieldDefinition != null) {
        Object scopeValue = entityService.getField(databaseEntity, scopeFieldDefinition);
        if (scopeValue instanceof Entity) {
            criteria.add(Restrictions.eq(scopeFieldDefinition.getName() + ".id", ((Entity) scopeValue).getId()));
        } else {
            criteria.add(Restrictions.eq(scopeFieldDefinition.getName(), scopeValue));
        }
    }
    return criteria;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) Criteria(org.hibernate.Criteria)

Example 3 with FieldDefinition

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

the class ValidationServiceImpl method parseFields.

private void parseFields(final InternalDataDefinition dataDefinition, final Entity genericEntity) {
    for (Entry<String, FieldDefinition> fieldDefinitionEntry : dataDefinition.getFields().entrySet()) {
        final InternalFieldDefinition fieldDefinition = (InternalFieldDefinition) fieldDefinitionEntry.getValue();
        final FieldType fieldType = fieldDefinition.getType();
        final Object fieldValue = genericEntity.getField(fieldDefinitionEntry.getKey());
        Object parsedValue = null;
        if (fieldType instanceof BelongsToType) {
            parsedValue = parseBelongsToField(fieldDefinition, trimAndNullIfEmpty(fieldValue), genericEntity);
        } else {
            parsedValue = fieldValue;
        }
        genericEntity.setField(fieldDefinitionEntry.getKey(), parsedValue);
    }
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition)

Example 4 with FieldDefinition

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

the class GridComponentFilterUtilsTest method shouldFilterColumnWithThreeLevelsDeepPathInExpressionWithBrackets.

@Test
public final void shouldFilterColumnWithThreeLevelsDeepPathInExpressionWithBrackets() throws GridComponentFilterException {
    // given
    DataDefinition firstBtDataDef = mock(DataDefinition.class);
    FieldDefinition firstBtFieldDef = mockBelongsToField("firstBt", dataDefinition, firstBtDataDef);
    DataDefinition secondBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("secondBt", firstBtDataDef, secondBtDataDef);
    DataDefinition thirdBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("thirdBt", secondBtDataDef, thirdBtDataDef);
    mockFieldDefinition(TEST_FIELD, Integer.class, thirdBtDataDef);
    // when
    performFiltering("3", buildGridComponentColumn(TEST_COL, firstBtFieldDef, "#firstBt['secondBt'].get('thirdBt').get('" + TEST_FIELD + "')"));
    // then
    PowerMockito.verifyStatic();
    SearchRestrictions.eq("thirdBt_a." + TEST_FIELD, 3);
    PowerMockito.verifyStatic(never());
    SearchRestrictions.eq(TEST_FIELD, 3);
    SearchRestrictions.eq("firstBt_a." + TEST_FIELD, 3);
    SearchRestrictions.eq("secondBt_a." + TEST_FIELD, 3);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with FieldDefinition

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

the class GridComponentFilterUtilsTest method shouldFilterColumnWithTwoLevelsDeepPathInExpressionWithBrackets.

@Test
public final void shouldFilterColumnWithTwoLevelsDeepPathInExpressionWithBrackets() throws GridComponentFilterException {
    // given
    DataDefinition firstBtDataDef = mock(DataDefinition.class);
    FieldDefinition firstBtFieldDef = mockBelongsToField("firstBt", dataDefinition, firstBtDataDef);
    DataDefinition secondBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("secondBt", firstBtDataDef, secondBtDataDef);
    mockFieldDefinition(TEST_FIELD, Integer.class, secondBtDataDef);
    // when
    performFiltering("3", buildGridComponentColumn(TEST_COL, firstBtFieldDef, "#firstBt['secondBt'].get('" + TEST_FIELD + "')"));
    // then
    PowerMockito.verifyStatic();
    SearchRestrictions.eq("secondBt_a." + TEST_FIELD, 3);
    PowerMockito.verifyStatic(never());
    SearchRestrictions.eq(TEST_FIELD, 3);
    SearchRestrictions.eq("firstBt_a." + TEST_FIELD, 3);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FieldDefinition (com.qcadoo.model.api.FieldDefinition)142 Test (org.junit.Test)92 DataDefinition (com.qcadoo.model.api.DataDefinition)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)48 Entity (com.qcadoo.model.api.Entity)32 BelongsToType (com.qcadoo.model.api.types.BelongsToType)19 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)15 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)13 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)12 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)11 HasManyType (com.qcadoo.model.api.types.HasManyType)9 StringType (com.qcadoo.model.internal.types.StringType)9 JSONObject (org.json.JSONObject)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)6 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 Before (org.junit.Before)6 EntityList (com.qcadoo.model.api.EntityList)5