<commit_before>package ca.firstvoices.listeners;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.event.Event;
import org.nuxeo.ecm.core.event.EventContext;
import org.nuxeo.ecm.core.event.EventListener;
import org.nuxeo.ecm.core.work.api.WorkManager;
import org.nuxeo.runtime.api.Framework;

import java.io.Serializable;
import java.util.Map;

public class FVRegistrationCompletionListener implements EventListener {

   private static final Log log = LogFactory.getLog(ca.firstvoices.listeners.FVRegistrationCompletionListener.class);

   // accepts documentRemoved && registrationValidated
    protected WorkManager workManager = Framework.getService(WorkManager.class);

    @Override
    public void handleEvent(Event event)
    {
        EventContext ctx;

        switch (event.getName())
        {
            case "documentRemoved":
                log.info("GOT EVENT documentRemoved");
                break;
            case "registrationValidated":
                ctx = event.getContext();
                Object[] args = ctx.getArguments();

                for( Object o: args )
                {
                    if( o.getClass().getTypeName().equals("FVUserRegistration"))
                    {
                        DocumentModel reg = (DocumentModel)o;


                    }
                }
                log.info("GOT EVENT registrationValidated");
            break;

        }
    }
}<commit_msg>Listener to handle "registration validation" event ie. after user configured password.<commit_after>package ca.firstvoices.listeners;

import ca.firstvoices.utils.FVRegistrationUtilities;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.core.api.*;
import org.nuxeo.ecm.core.event.Event;
import org.nuxeo.ecm.core.event.EventContext;
import org.nuxeo.ecm.core.event.EventListener;
import org.nuxeo.ecm.core.event.impl.DocumentEventContext;

public class FVRegistrationCompletionListener implements EventListener {

    private static final Log log = LogFactory.getLog(ca.firstvoices.listeners.FVRegistrationCompletionListener.class);

    // accepts documentRemoved && registrationValidated

    @Override
    public void handleEvent(Event event) {
        EventContext ctx;
        ctx = event.getContext();
        if (!(ctx instanceof DocumentEventContext)) return;

        DocumentEventContext docCtx = (DocumentEventContext) ctx;
        DocumentModel registration = docCtx.getSourceDocument();

        FVRegistrationUtilities regUtil = new FVRegistrationUtilities();

        switch (event.getName()) {
            case "documentRemoved":
                // TODO: use it to make sure user name is not left in the system when registration is deleted on time out
                break;

            case "registrationValidated":
                Object[] args = docCtx.getArguments();
                String principal = docCtx.getCoreSession().getPrincipal().getName();

                for (Object o : args) {
                    if (o == null) break;

                    DocumentModel ureg = (DocumentModel) o;
                    String oT = ureg.getType();

                    if (oT.equals("FVUserRegistration")) {
                        regUtil.registrationValidationHandler(ureg);
                    }
                }
                break;
        }
    }
}
{'fraction_non_alphanumeric': 0.09132814750792279, 'fraction_numerical': 0.0, 'mean_word_length': 2.370873786407767, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '22670', 'n_tokens_mistral': 933, 'n_tokens_neox': 877, 'n_words': 195}