class TreeNodeCodeGenerator extends AbstractValueGenerator<IdmTreeNodeDto> {

	@Override
	public IdmTreeNodeDto generate(IdmTreeNodeDto dto, IdmGenerateValueDto valueGenerator) {
		Assert.notNull(dto, "DTO is required.");
		Assert.notNull(valueGenerator, "Value generator is required.");

		// Code is based from name
		String code = dto.getName();

		if (code == null) {
			return dto;
		}
	
		// if exists email and configuration doesn't allow regenerate return dto
		if (!valueGenerator.isRegenerateValue() && StringUtils.isNotEmpty(dto.getCode())) {
			return dto;
		}
		
		code = StringUtils.stripAccents(code);
		code = StringUtils.deleteWhitespace(code);
		code = code.toLowerCase();

		dto.setCode(code);
		return dto;
	}

}