Plugin de ROR devuelve "undefined" en OJS 3.3.x

El plugin de ROR no está devolviendo el nombre completo de la institución, solamente devuelve un “undefined” mas el url del ROR.

Se probó en varias instalaciones de OJS versión 3.3.0.20

Anexo imagen:

Versión de ROR plugin v1.0.0.12 (la más actual disponible en la galería de plugins)

@Dulip_Withanage

Dear @dagosalas , dear @Dulip_Withanage

I can confirm this with OJS 3.3.0.17. On OJS 3.4.0.8 no search results are displayed at all.

Is that an outage at ORCID’s API?

all the best

Klaus

Hi @dagosalas and @klausru, due to recent changes in the ROR API, there is an issue in the ROR plugin in OJS 3.3 and 3.4. If you are comfortable doing so, you can apply this patch in the meantime until a new release of the plugin is available in the plugin gallery.

1 Like

Thanks @kaitlin,

Although the documentation mentions that the API URL doesn’t change, I just changed it by adding v1, and it works correctly. I came back to the forum to mention it, but you’re faster. :smiley:

1 Like

Si, de momento no existe actualización del plugin pero les comparto la ruta donde deben modificar y el archivo completo ya con el ajuste o (FIX) si recomiendo aplicar para que no se guarden registros en la DB con ‘Undefined’ en sus metadatos en sus nuevos envíos de OJS, para evitar tener que modificar nuevamente cada metadato o aplicar un script para aplicar masivamente en caso de que de la fecha del fallo al día de hoy se hayan colado varios de estos errores:
Ruta:

OJS/plugins/generic/ror/templates/affiliation.tpl

pueden hacer un BK antes de modificar.

Reemplazar todo el contenido por este con los ajustes citados en la solución:

<script>
    $(document).ready(function () {ldelim}
        var primaryLocale = "{$primaryLocale}";
        var results = null;
        const tagitInput = '.tagit-new > input';
        const rorPlaceHolder = "Search ror.org";

        var mainAffiliation = 'input[id^="affiliation-' + primaryLocale + '"]';
        if (!$(mainAffiliation).length) {
            mainAffiliation = 'input[id^="affiliation-"]';
        }

        $(mainAffiliation).tagit({ldelim}
            fieldName: 'affiliation-ROR[]',
            allowSpaces: true,
            tagLimit: 1,
            tagSource: function (search, r) {ldelim}
                $.ajax({ldelim}
                    url: 'https://api.ror.org/organizations',
                    dataType: 'json',
                    cache: true,
                    data: {ldelim}
                        affiliation: search.term + '*'
                    {rdelim},
                    success: function (data) {ldelim}
                        // parche: extraer correctamente de data.items y organization.names
                        results = data.items || [];

                        r($.map(results, function (item) {ldelim}
                            const org = item.organization || item;
                            const entry = (org.names || []).find(e => e.types.includes('ror_display'))
                                        || (org.names || [])[0]
                                        || {};
                            const name = entry.value || 'Sin nombre';
                            return {ldelim}
                                label: name + ' [' + org.id + ']',
                                value: name + ' [' + org.id + ']'
                            {rdelim}
                        {rdelim}));
                    {rdelim}
                {rdelim});
            {rdelim},
            beforeTagAdded: function (event, ui) {ldelim}{rdelim},
            afterTagAdded: function (event, ui) {ldelim}
                if (ui.duringInitialization === true) {
                    $(mainAffiliation).after(
                        '<div id="rorIdField" style="float:right; background:#eaedee;">' +
                        '<a href="{$rorId}" target="_blank">{$rorId}</a>' +
                        '</div>'
                    );
                } else {
                    const regex = /https:\/\/ror\.org\/(\d|\w)+/g;
                    const found = ui.tagLabel.match(regex);
                    if (found !== null) {
                        const rorId = found[0];
                        $.each(results, function (key, value) {ldelim}
                            if (value.organization.id === rorId) {
                                var supportedLocales = {$supportedLocales|json_encode};
                                $.each(supportedLocales, function (k, val) {ldelim}
                                    var locale = k.slice(0,2);
                                    if (locale.length === 2) {
                                        value.organization.labels.forEach(function (v) {ldelim}
                                            if (locale === v["iso639"]) {
                                                if (locale !== primaryLocale.slice(0,2)) {
                                                    $('input[id^="affiliation-' + locale + '"]')
                                                        .val(v.label)
                                                        .parent().css({ display: "block", width: "576px" });
                                                }
                                            }
                                        {rdelim});
                                    }
                                {rdelim});
                            }
                        {rdelim});
                    }
                }
                console.log("afterTagAdded");
            {rdelim},
            afterTagRemoved: function (event, ui) {ldelim}
                $('#rorIdField').remove();
                $('input[id^="affiliation-"]').val("");
                $('.localization_popover').hide();
                $(tagitInput).attr("placeholder", rorPlaceHolder);
            {rdelim},
            onTagClicked: function (event, ui) {ldelim}
                $(tagitInput).attr("placeholder", rorPlaceHolder);
            {rdelim},
            onTagRemoved: function (event, ui) {ldelim}
                $('#rorIdField').remove();
                $('input[id^="affiliation-"]').val("");
                $('.localization_popover').hide();
                $(tagitInput).attr("placeholder", rorPlaceHolder);
            {rdelim}
        {rdelim});

        if (!$('.tagit-label').val() || $('.tagit-label').length === 0) {
            $(tagitInput).attr("placeholder", rorPlaceHolder);
        }
    {rdelim});
</script>

¿Qué se modificó?

Antes: el AJAX hacía:

response($.map(data.items, item => ({
  label: item.organization.name + ' [' + item.organization.id + ']',
  value: item.organization.name + ' [' + item.organization.id + ']'
})));

Ahora: extrae correctamente de:

const org = item.organization;
const entry = (org.names || [])
  .find(e => e.types.includes('ror_display'))
  || org.names[0]
  || {};
const name = entry.value || 'Sin nombre';
response($.map(data.items, item => ({
  label: name + ' [' + org.id + ']',
  value: name + ' [' + org.id + ']'
})));

Causa raíz: migración de la API de ROR a un formato donde el nombre está anidado en organization.names, no en organization.name

Hi, do you have any estimate for when the ROR plugin update for OJS 3.3 will be released?

Hi @marcela.reinhardt, the updated plugin for 3.3 and 3.4 has just been released and is now available through the plugin gallery.

2 Likes