<commit_before>package eu.bcvsolutions.idm.core.model.event.processor.identity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import eu.bcvsolutions.idm.core.CoreModuleDescriptor;
import eu.bcvsolutions.idm.core.api.domain.CoreResultCode;
import eu.bcvsolutions.idm.core.api.dto.IdmAccountDto;
import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;
import eu.bcvsolutions.idm.core.api.event.CoreEventProcessor;
import eu.bcvsolutions.idm.core.api.event.DefaultEventResult;
import eu.bcvsolutions.idm.core.api.event.EntityEvent;
import eu.bcvsolutions.idm.core.api.event.EventResult;
import eu.bcvsolutions.idm.core.api.event.processor.IdentityProcessor;
import eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType;
import eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel;
import eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto;
import eu.bcvsolutions.idm.core.notification.api.service.NotificationManager;
import eu.bcvsolutions.idm.core.security.api.domain.Enabled;

/**
 * Identity's password change notification
 * 
 * @author <NAME>
 *
 */
@Component
@Enabled(CoreModuleDescriptor.MODULE_ID)
@Description("Sends notification to identity of changed password.")
public class IdentityPasswordChangeNotificationProcessor extends CoreEventProcessor<IdmIdentityDto>
		implements IdentityProcessor {

	public static final String PROCESSOR_NAME = "identity-password-change-notification";

	private final NotificationManager notificationManager;

	@Autowired
	public IdentityPasswordChangeNotificationProcessor(NotificationManager notificationManager) {
		super(IdentityEventType.PASSWORD);
		//
		Assert.notNull(notificationManager);
		//
		this.notificationManager = notificationManager;
	}

	@Override
	public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
		IdmIdentityDto identity = event.getContent();
		List<EventResult<IdmIdentityDto>> results = event.getContext().getResults();
		List<String> systems = new ArrayList<>();
		for (EventResult<IdmIdentityDto> result : results) {
			result.getResults().stream().filter(res -> {
				return res.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
			}).forEach(res -> {
				IdmAccountDto account = (IdmAccountDto) res.getModel().getParameters().get("account");
				if (!account.isIdm()) {
					systems.add(account.getSystemName());
				} else {
					systems.add("CzechIdM");
				}
			});
		}
		if (!systems.isEmpty()) {
			sendNotification(identity, systems);
		}
		return new DefaultEventResult<>(event, this);

	}

	@Override
	public int getOrder() {
		return super.getOrder() + 1500;
	}

	private void sendNotification(IdmIdentityDto identity, List<String> accounts) {
		notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED,
				new IdmMessageDto.Builder().setLevel(NotificationLevel.INFO)
						.addParameter("username", identity.getUsername()).addParameter("accounts", accounts).build(),
				identity);
	}
}
<commit_msg>#716 minor fixes<commit_after>package eu.bcvsolutions.idm.core.model.event.processor.identity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import eu.bcvsolutions.idm.core.CoreModuleDescriptor;
import eu.bcvsolutions.idm.core.api.domain.CoreResultCode;
import eu.bcvsolutions.idm.core.api.dto.IdmAccountDto;
import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;
import eu.bcvsolutions.idm.core.api.event.CoreEventProcessor;
import eu.bcvsolutions.idm.core.api.event.DefaultEventResult;
import eu.bcvsolutions.idm.core.api.event.EntityEvent;
import eu.bcvsolutions.idm.core.api.event.EventResult;
import eu.bcvsolutions.idm.core.api.event.processor.IdentityProcessor;
import eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType;
import eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel;
import eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto;
import eu.bcvsolutions.idm.core.notification.api.service.NotificationManager;
import eu.bcvsolutions.idm.core.security.api.domain.Enabled;

/**
 * Identity's password change notification
 * 
 * @author <NAME>
 *
 */
@Component
@Enabled(CoreModuleDescriptor.MODULE_ID)
@Description("Sends notification to identity of changed password.")
public class IdentityPasswordChangeNotificationProcessor extends CoreEventProcessor<IdmIdentityDto>
		implements IdentityProcessor {

	private static final String CZECHIDM_NAME = "CzechIdM";
	public static final String PROCESSOR_NAME = "identity-password-change-notification";

	private final NotificationManager notificationManager;

	@Autowired
	public IdentityPasswordChangeNotificationProcessor(NotificationManager notificationManager) {
		super(IdentityEventType.PASSWORD);
		//
		Assert.notNull(notificationManager);
		//
		this.notificationManager = notificationManager;
	}

	@Override
	public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
		IdmIdentityDto identity = event.getContent();
		List<EventResult<IdmIdentityDto>> results = event.getContext().getResults();
		List<String> systems = new ArrayList<>();
		for (EventResult<IdmIdentityDto> result : results) {
			result.getResults().stream().filter(res -> {
				return res.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
			}).forEach(res -> {
				IdmAccountDto account = (IdmAccountDto) res.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
				if (!account.isIdm()) {
					systems.add(account.getSystemName());
				} else {
					systems.add(CZECHIDM_NAME);
				}
			});
		}
		if (!systems.isEmpty()) {
			sendNotification(identity, systems);
		}
		return new DefaultEventResult<>(event, this);

	}

	@Override
	public int getOrder() {
		return super.getOrder() + 1500;
	}

	private void sendNotification(IdmIdentityDto identity, List<String> accounts) {
		notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED,
				new IdmMessageDto.
					Builder()
						.setLevel(NotificationLevel.INFO)
						.addParameter("username", identity.getUsername())
						.addParameter("accounts", accounts)
					.build(),
				identity);
	}
}

{'fraction_non_alphanumeric': 0.1148442272449603, 'fraction_numerical': 0.001679902260232132, 'mean_word_length': 5.850418410041841, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '5534184', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1951, 'n_words': 296}