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