Search in sources :

Example 96 with FieldDefinition

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

the class PriorityServiceImplTest method mockPriorityFieldDefinition.

private void mockPriorityFieldDefinition(final Entity entity, final String priorityFieldName) {
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(entity.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition priorityField = mock(FieldDefinition.class);
    given(dataDefinition.getPriorityField()).willReturn(priorityField);
    given(priorityField.getName()).willReturn(priorityFieldName);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 97 with FieldDefinition

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

the class FieldTypeFactoryTest method shouldReturnPriorityType.

@Test
public void shouldReturnPriorityType() throws Exception {
    // given
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(null, "aaa");
    // when
    FieldType fieldType = new PriorityType(fieldDefinition);
    // then
    assertEquals(Integer.class, fieldType.getType());
    assertTrue(fieldType.toObject(fieldDefinition, 1).isValid());
    assertEquals(fieldDefinition, ((PriorityType) fieldType).getScopeFieldDefinition());
}
Also used : PriorityType(com.qcadoo.model.internal.types.PriorityType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) FieldType(com.qcadoo.model.api.types.FieldType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 98 with FieldDefinition

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

the class PriorityServiceImpl method deprioritizeEntity.

@Override
public void deprioritizeEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity) {
    if (!dataDefinition.isPrioritizable()) {
        return;
    }
    FieldDefinition fieldDefinition = dataDefinition.getPriorityField();
    int currentPriority = (Integer) entityService.getField(databaseEntity, fieldDefinition);
    changePriority(dataDefinition, fieldDefinition, databaseEntity, currentPriority + 1, Integer.MAX_VALUE, -1);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 99 with FieldDefinition

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

the class PriorityServiceImpl method move.

@Override
public void move(final InternalDataDefinition dataDefinition, final Object databaseEntity, final int position, final int offset) {
    FieldDefinition fieldDefinition = dataDefinition.getPriorityField();
    Integer currentPriorityInteger = (Integer) entityService.getField(databaseEntity, fieldDefinition);
    int currentPriority = currentPriorityInteger != null ? currentPriorityInteger.intValue() : 0;
    int targetPriority = getTargetPriority(position, offset, currentPriority);
    if (currentPriorityInteger == null) {
        setPriorityIfNotPresent(dataDefinition, fieldDefinition, databaseEntity, targetPriority);
    }
    targetPriority = checkIfTargetPriorityIsNotTooLow(targetPriority);
    targetPriority = getIfTargetPriorityIsNotTooHigh(dataDefinition, databaseEntity, fieldDefinition, targetPriority);
    if (currentPriority < targetPriority) {
        changePriority(dataDefinition, fieldDefinition, databaseEntity, currentPriority + 1, targetPriority, -1);
    } else if (currentPriority > targetPriority) {
        changePriority(dataDefinition, fieldDefinition, databaseEntity, targetPriority, currentPriority - 1, 1);
    } else {
        return;
    }
    entityService.setField(databaseEntity, fieldDefinition, targetPriority);
    hibernateService.getCurrentSession().update(databaseEntity);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 100 with FieldDefinition

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

the class PriorityServiceImpl method prioritizeEntity.

@Override
public void prioritizeEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity) {
    if (!dataDefinition.isPrioritizable()) {
        return;
    }
    FieldDefinition fieldDefinition = dataDefinition.getPriorityField();
    int totalNumberOfEntities = getTotalNumberOfEntities(dataDefinition, fieldDefinition, databaseEntity);
    entityService.setField(databaseEntity, fieldDefinition, totalNumberOfEntities + 1);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition)

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