private DebtCharacteristic move(int characteristicId, boolean moveUpOrDown) {
checkPermission();
SqlSession session = dbClient.openSession(false);
try {
final CharacteristicDto dto = findCharacteristic(characteristicId, session);
if (dto.getParentId() != null) {
throw new BadRequestException("Sub characteristics can not be moved.");
}
int currentOrder = getOrder(dto);
CharacteristicDto dtoToSwitchOrderWith = findCharacteristicToSwitchWith(dto, moveUpOrDown, session);
// Do nothing when characteristic is already to the good location
if (dtoToSwitchOrderWith == null) {
return toCharacteristic(dto);
}
int nextOrder = getOrder(dtoToSwitchOrderWith);
dtoToSwitchOrderWith.setOrder(currentOrder);
dtoToSwitchOrderWith.setUpdatedAt(new Date(system2.now()));
dbClient.debtCharacteristicDao().update(dtoToSwitchOrderWith, session);
dto.setOrder(nextOrder);
dto.setUpdatedAt(new Date(system2.now()));
dbClient.debtCharacteristicDao().update(dto, session);