@Test public void shouldSetNotEmptyField() throws Exception { SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L); databaseEntity.setName("name"); entityService.setField(databaseEntity, fieldDefinitionName, "XXX"); assertEquals("XXX", databaseEntity.getName()); }
@Override public void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value) { if (!shouldAllowToSetField(fieldDefinition, value)) { return; } if (fieldDefinition.getType() instanceof BelongsToType && value != null) { Object belongsToValue = getBelongsToFieldValue( (InternalDataDefinition) ((BelongsToType) fieldDefinition.getType()).getDataDefinition(), value); setField(databaseEntity, fieldDefinition.getName(), belongsToValue); } else if (fieldDefinition.getType() instanceof HasManyType) { setField(databaseEntity, fieldDefinition.getName(), null); } else if (fieldDefinition.getType() instanceof TreeType) { setField(databaseEntity, fieldDefinition.getName(), null); } else { setField(databaseEntity, fieldDefinition.getName(), value); } }
EntityServiceImpl implements EntityService { @Override public void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value) { if (!shouldAllowToSetField(fieldDefinition, value)) { return; } if (fieldDefinition.getType() instanceof BelongsToType && value != null) { Object belongsToValue = getBelongsToFieldValue( (InternalDataDefinition) ((BelongsToType) fieldDefinition.getType()).getDataDefinition(), value); setField(databaseEntity, fieldDefinition.getName(), belongsToValue); } else if (fieldDefinition.getType() instanceof HasManyType) { setField(databaseEntity, fieldDefinition.getName(), null); } else if (fieldDefinition.getType() instanceof TreeType) { setField(databaseEntity, fieldDefinition.getName(), null); } else { setField(databaseEntity, fieldDefinition.getName(), value); } } }
EntityServiceImpl implements EntityService { @Override public void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value) { if (!shouldAllowToSetField(fieldDefinition, value)) { return; } if (fieldDefinition.getType() instanceof BelongsToType && value != null) { Object belongsToValue = getBelongsToFieldValue( (InternalDataDefinition) ((BelongsToType) fieldDefinition.getType()).getDataDefinition(), value); setField(databaseEntity, fieldDefinition.getName(), belongsToValue); } else if (fieldDefinition.getType() instanceof HasManyType) { setField(databaseEntity, fieldDefinition.getName(), null); } else if (fieldDefinition.getType() instanceof TreeType) { setField(databaseEntity, fieldDefinition.getName(), null); } else { setField(databaseEntity, fieldDefinition.getName(), value); } }  }
EntityServiceImpl implements EntityService { @Override public void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value) { if (!shouldAllowToSetField(fieldDefinition, value)) { return; } if (fieldDefinition.getType() instanceof BelongsToType && value != null) { Object belongsToValue = getBelongsToFieldValue( (InternalDataDefinition) ((BelongsToType) fieldDefinition.getType()).getDataDefinition(), value); setField(databaseEntity, fieldDefinition.getName(), belongsToValue); } else if (fieldDefinition.getType() instanceof HasManyType) { setField(databaseEntity, fieldDefinition.getName(), null); } else if (fieldDefinition.getType() instanceof TreeType) { setField(databaseEntity, fieldDefinition.getName(), null); } else { setField(databaseEntity, fieldDefinition.getName(), value); } }  @Override Long getId(final Object databaseEntity); Boolean getActive(final Object databaseEntity); void setActive(final Object databaseEntity, final boolean active); @Override void setId(final Object databaseEntity, final Long id); @Override void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value); @Override Object getField(final Object databaseEntity, final FieldDefinition fieldDefinition); Object getField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Entity performer); @Override Entity convertToGenericEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity); Entity convertToGenericEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity,
            final Entity performer); @SuppressWarnings("unchecked") @Override Object convertToDatabaseEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity,
            final Object existingDatabaseEntity); }
EntityServiceImpl implements EntityService { @Override public void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value) { if (!shouldAllowToSetField(fieldDefinition, value)) { return; } if (fieldDefinition.getType() instanceof BelongsToType && value != null) { Object belongsToValue = getBelongsToFieldValue( (InternalDataDefinition) ((BelongsToType) fieldDefinition.getType()).getDataDefinition(), value); setField(databaseEntity, fieldDefinition.getName(), belongsToValue); } else if (fieldDefinition.getType() instanceof HasManyType) { setField(databaseEntity, fieldDefinition.getName(), null); } else if (fieldDefinition.getType() instanceof TreeType) { setField(databaseEntity, fieldDefinition.getName(), null); } else { setField(databaseEntity, fieldDefinition.getName(), value); } }  @Override Long getId(final Object databaseEntity); Boolean getActive(final Object databaseEntity); void setActive(final Object databaseEntity, final boolean active); @Override void setId(final Object databaseEntity, final Long id); @Override void setField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Object value); @Override Object getField(final Object databaseEntity, final FieldDefinition fieldDefinition); Object getField(final Object databaseEntity, final FieldDefinition fieldDefinition, final Entity performer); @Override Entity convertToGenericEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity); Entity convertToGenericEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity,
            final Entity performer); @SuppressWarnings("unchecked") @Override Object convertToDatabaseEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity,
            final Object existingDatabaseEntity);  }