<commit_before>package eu.bcvsolutions.idm.acc.service.impl;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.google.common.collect.ImmutableMap;

import eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto;
import eu.bcvsolutions.idm.acc.dto.filter.IdentityAccountFilter;
import eu.bcvsolutions.idm.acc.entity.AccIdentityAccount;
import eu.bcvsolutions.idm.acc.event.IdentityAccountEvent;
import eu.bcvsolutions.idm.acc.event.IdentityAccountEvent.IdentityAccountEventType;
import eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository;
import eu.bcvsolutions.idm.acc.service.api.AccAccountService;
import eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService;
import eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService;
import eu.bcvsolutions.idm.core.api.service.EntityEventManager;
import eu.bcvsolutions.idm.core.model.repository.IdmIdentityRoleRepository;
import eu.bcvsolutions.idm.core.security.api.domain.BasePermission;

/**
 * Identity accounts on target system
 * 
 * @author <NAME>
 * @author Svanda
 *
 */
@Service
public class DefaultAccIdentityAccountService extends
		AbstractReadWriteDtoService<AccIdentityAccountDto, AccIdentityAccount, IdentityAccountFilter> implements AccIdentityAccountService {

	private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(DefaultAccIdentityAccountService.class);
	
	private final AccAccountService accountService;
	private final IdmIdentityRoleRepository identityRoleRepository;
	private final EntityEventManager entityEventManager;

	@Autowired
	public DefaultAccIdentityAccountService(
			AccIdentityAccountRepository identityAccountRepository,
			AccAccountService accountService,
			IdmIdentityRoleRepository identityRoleRepository,
			EntityEventManager entityEventManager) {
		super(identityAccountRepository);
		//
		Assert.notNull(accountService);
		Assert.notNull(identityRoleRepository);
		Assert.notNull(entityEventManager);
		//
		this.accountService = accountService;
		this.identityRoleRepository = identityRoleRepository;
		this.entityEventManager = entityEventManager;
	}

	@Override
	@Transactional(readOnly = true)
	public AccIdentityAccount getEntity(Serializable id, BasePermission... permission) {
		// I don't want use excerpt, so I have to do manual load account and
		// identityRole
		AccIdentityAccount ia = super.getEntity(id, permission);
		if (ia != null && ia.getAccount() != null) {
			ia.setAccount(accountService.get(ia.getAccount().getId()));
		}
		if (ia != null && ia.getIdentityRole() != null) {
			ia.setIdentityRole(identityRoleRepository.findOne(ia.getIdentityRole().getId()));
		}
		return ia;
	}
	
	@Override
	public AccIdentityAccountDto save(AccIdentityAccountDto dto, BasePermission... permission) {
		Assert.notNull(dto);
		checkAccess(toEntity(dto, null), permission);
		//
		LOG.debug("Saving identity-account [{}]", dto);
		//
		if (isNew(dto)) { // create
			return entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.CREATE, dto)).getContent();
		}
		return entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.UPDATE, dto)).getContent();
	}
	

	@Override
	@Transactional
	public void delete(AccIdentityAccountDto dto, BasePermission... permission) {
		this.delete(dto, true, permission);
	}
	

	@Override
	@Transactional
	public void delete(AccIdentityAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
		this.delete(entity, deleteTargetAccount, false, permission);
	}
	
	@Override
	@Transactional
	public void forceDelete(AccIdentityAccountDto dto, BasePermission... permission) {
		this.delete(dto, true, true,permission);
	}

	private void delete(AccIdentityAccountDto entity, boolean deleteTargetAccount, boolean forceDelete, BasePermission... permission) {
		Assert.notNull(entity);
		checkAccess(this.getEntity(entity.getId()), permission);
		//
		LOG.debug("Deleting identity account [{}]", entity);
		entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.DELETE, entity,
				ImmutableMap.of(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY, deleteTargetAccount,
						AccIdentityAccountService.FORCE_DELETE_OF_IDENTITY_ACCOUNT_KEY, forceDelete)));
	}
	
	
}
<commit_msg>Added default name to Identity account service.<commit_after>package eu.bcvsolutions.idm.acc.service.impl;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.google.common.collect.ImmutableMap;

import eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto;
import eu.bcvsolutions.idm.acc.dto.filter.IdentityAccountFilter;
import eu.bcvsolutions.idm.acc.entity.AccIdentityAccount;
import eu.bcvsolutions.idm.acc.event.IdentityAccountEvent;
import eu.bcvsolutions.idm.acc.event.IdentityAccountEvent.IdentityAccountEventType;
import eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository;
import eu.bcvsolutions.idm.acc.service.api.AccAccountService;
import eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService;
import eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService;
import eu.bcvsolutions.idm.core.api.service.EntityEventManager;
import eu.bcvsolutions.idm.core.model.repository.IdmIdentityRoleRepository;
import eu.bcvsolutions.idm.core.security.api.domain.BasePermission;

/**
 * Identity accounts on target system
 * 
 * @author <NAME>
 * @author Svanda
 *
 */
@Service("accIdentityAccountService")
public class DefaultAccIdentityAccountService extends
		AbstractReadWriteDtoService<AccIdentityAccountDto, AccIdentityAccount, IdentityAccountFilter> implements AccIdentityAccountService {

	private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(DefaultAccIdentityAccountService.class);
	
	private final AccAccountService accountService;
	private final IdmIdentityRoleRepository identityRoleRepository;
	private final EntityEventManager entityEventManager;

	@Autowired
	public DefaultAccIdentityAccountService(
			AccIdentityAccountRepository identityAccountRepository,
			AccAccountService accountService,
			IdmIdentityRoleRepository identityRoleRepository,
			EntityEventManager entityEventManager) {
		super(identityAccountRepository);
		//
		Assert.notNull(accountService);
		Assert.notNull(identityRoleRepository);
		Assert.notNull(entityEventManager);
		//
		this.accountService = accountService;
		this.identityRoleRepository = identityRoleRepository;
		this.entityEventManager = entityEventManager;
	}

	@Override
	@Transactional(readOnly = true)
	public AccIdentityAccount getEntity(Serializable id, BasePermission... permission) {
		// I don't want use excerpt, so I have to do manual load account and
		// identityRole
		AccIdentityAccount ia = super.getEntity(id, permission);
		if (ia != null && ia.getAccount() != null) {
			ia.setAccount(accountService.get(ia.getAccount().getId()));
		}
		if (ia != null && ia.getIdentityRole() != null) {
			ia.setIdentityRole(identityRoleRepository.findOne(ia.getIdentityRole().getId()));
		}
		return ia;
	}
	
	@Override
	public AccIdentityAccountDto save(AccIdentityAccountDto dto, BasePermission... permission) {
		Assert.notNull(dto);
		checkAccess(toEntity(dto, null), permission);
		//
		LOG.debug("Saving identity-account [{}]", dto);
		//
		if (isNew(dto)) { // create
			return entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.CREATE, dto)).getContent();
		}
		return entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.UPDATE, dto)).getContent();
	}
	

	@Override
	@Transactional
	public void delete(AccIdentityAccountDto dto, BasePermission... permission) {
		this.delete(dto, true, permission);
	}
	

	@Override
	@Transactional
	public void delete(AccIdentityAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
		this.delete(entity, deleteTargetAccount, false, permission);
	}
	
	@Override
	@Transactional
	public void forceDelete(AccIdentityAccountDto dto, BasePermission... permission) {
		this.delete(dto, true, true,permission);
	}

	private void delete(AccIdentityAccountDto entity, boolean deleteTargetAccount, boolean forceDelete, BasePermission... permission) {
		Assert.notNull(entity);
		checkAccess(this.getEntity(entity.getId()), permission);
		//
		LOG.debug("Deleting identity account [{}]", entity);
		entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.DELETE, entity,
				ImmutableMap.of(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY, deleteTargetAccount,
						AccIdentityAccountService.FORCE_DELETE_OF_IDENTITY_ACCOUNT_KEY, forceDelete)));
	}
	
	
}

{'fraction_non_alphanumeric': 0.09797787956652888, 'fraction_numerical': 0.0004468774438610211, 'mean_word_length': 6.313725490196078, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7065468', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2532, 'n_words': 452}