class ContractPositionNameGenerator extends AbstractValueGenerator<IdmIdentityContractDto> {

	@Override
	public IdmIdentityContractDto generate(IdmIdentityContractDto dto, IdmGenerateValueDto generatorConfiguration) {
		// if exists email and configuration doesn't allow regenerate return dto
		if (!generatorConfiguration.isRegenerateValue() && StringUtils.isNotEmpty(dto.getPosition())) {
			return dto;
		}

		IdmIdentityDto identityDto = DtoUtils.getEmbedded(dto, IdmIdentityContract_.identity, IdmIdentityDto.class, null);
		if (identityDto == null) {
			// embedded is not filled
			identityDto = identityService.get(dto.getIdentity());
		}

		if (identityDto == null) {
			// this is possible, when create identity contract by rest
			LOG.error("New contract hasn't correctly filed identity ID [{}]", dto.getIdentity());
			return dto;
		}

		String username = identityDto.getUsername();
		
		StringBuilder result = new StringBuilder();
		
		String prefix = this.getPrefix(generatorConfiguration);
		String suffix = this.getSuffix(generatorConfiguration);
		
		if (StringUtils.isNotEmpty(prefix)) {
			result.append(prefix);
		}
		result.append(username);
		if (StringUtils.isNotEmpty(suffix)) {
			result.append(suffix);
		}

		dto.setPosition(result.toString());
		return dto;
	}

}