<commit_before>package org.opensingular.requirement.sei30.features;

import java.util.Optional;
import javax.annotation.Nonnull;

import org.opensingular.form.SInstance;
import org.opensingular.form.SType;
import org.opensingular.form.view.richtext.RichTextAction;
import org.opensingular.form.view.richtext.RichTextInsertContext;
import org.opensingular.lib.commons.lambda.IFunction;
import org.opensingular.lib.commons.ui.Icon;

public class InsertLinkSEIButtonRichText implements RichTextAction<RichTextInsertContext> {

    private IFunction<SILinkSEI, String> functionActionLink;

    public InsertLinkSEIButtonRichText(@Nonnull IFunction<SILinkSEI, String> functionActionLink) {
        this.functionActionLink = functionActionLink;
    }

    @Override
    public String getLabel() {
        return "Inserir um Link para processo ou documento do SEI!";
    }

    @Override
    public Icon getIcon() {
        return (Icon) () -> "sei-icon";
    }

    @Override
    public Optional<Class<? extends SType<?>>> getForm() {
        return Optional.of(STypeLinkSEI.class);
    }

    @Override
    public boolean getLabelInline() {
        return false;
    }

    @Override
    public Class<? extends RichTextInsertContext> getType() {
        return RichTextInsertContext.class;
    }

    @Override
    public void onAction(RichTextInsertContext richTextActionContext, Optional<SInstance> optional) {
        optional.ifPresent(instance -> {
            SILinkSEI instanceLinkSei = (SILinkSEI) instance;
            String protocolo = instanceLinkSei.getProtocolo();
            if(protocolo != null) {
                //This insert is exactly the same of used in the SEI service.
                String idProtocolo = functionActionLink.apply(instanceLinkSei);
                String retornoFormatado = "<span contenteditable=\"false\" style=\"text-indent:0px;\">"
                        + "<a id=lnkSei" + idProtocolo + " class=\"ancoraSei\" style=\"text-indent:0px;\">" + protocolo + "</a>"
                        + "</span>";
                richTextActionContext.setReturnValue(retornoFormatado);
            }
        });
    }
}<commit_msg>[SGL_680] - Implementação da captura de exceção da integração do SEI nos botões do richText<commit_after>package org.opensingular.requirement.sei30.features;

import java.util.Optional;
import javax.annotation.Nonnull;

import org.opensingular.form.SInstance;
import org.opensingular.form.SType;
import org.opensingular.form.view.richtext.RichTextAction;
import org.opensingular.form.view.richtext.RichTextInsertContext;
import org.opensingular.lib.commons.lambda.IFunction;
import org.opensingular.lib.commons.ui.Icon;

public class InsertLinkSEIButtonRichText implements RichTextAction<RichTextInsertContext> {

    private IFunction<SILinkSEI, String> functionActionLink;

    public InsertLinkSEIButtonRichText(@Nonnull IFunction<SILinkSEI, String> functionActionLink) {
        this.functionActionLink = functionActionLink;
    }

    @Override
    public String getLabel() {
        return "Inserir um Link para processo ou documento do SEI!";
    }

    @Override
    public Icon getIcon() {
        return (Icon) () -> "sei-icon";
    }

    @Override
    public Optional<Class<? extends SType<?>>> getForm() {
        return Optional.of(STypeLinkSEI.class);
    }

    @Override
    public boolean getLabelInline() {
        return false;
    }

    @Override
    public Class<? extends RichTextInsertContext> getType() {
        return RichTextInsertContext.class;
    }

    @Override
    public void onAction(RichTextInsertContext richTextActionContext, Optional<SInstance> optional) {
        optional.ifPresent(instance -> {
            SILinkSEI instanceLinkSei = (SILinkSEI) instance;
            String protocolo = instanceLinkSei.getProtocolo();
            String idProtocolo = functionActionLink.apply(instanceLinkSei);
            if(protocolo != null && idProtocolo != null) {
                //This insert is exactly the same of used in the SEI service.
                String retornoFormatado = "<span contenteditable=\"false\" style=\"text-indent:0px;\">"
                        + "<a id=lnkSei" + idProtocolo + " class=\"ancoraSei\" style=\"text-indent:0px;\">" + protocolo + "</a>"
                        + "</span>";
                richTextActionContext.setReturnValue(retornoFormatado);
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.10188336737009303, 'fraction_numerical': 0.002496029044701611, 'mean_word_length': 3.0440366972477064, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '3879414', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1235, 'n_words': 261}