<commit_before>/* global sails, ScopusExternalImporter, PublicationsExternalImporter, User, Group, DocumentOrigins, DocumentKinds */
// ExternalImporter.js - in api/services

"use strict";

module.exports = {
    updateUserExternal: async (id, origin) => {
        const user = await User.findOneById(id);
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateUser(user);
        if (!origin || origin === DocumentOrigins.PUBLICATIONS)
            await PublicationsExternalImporter.updateUser(user);
    },
    updateGroupExternal: async (id, origin) => {
        const group = await Group.findOneById(id);
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateGroup(group);
        if (!origin || origin === DocumentOrigins.PUBLICATIONS)
            await PublicationsExternalImporter.updateGroup(group);
    },
    updateAllExternal: async (origin) => {
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateAll();
    },
    updateDocument: async (origin, id) => {
        if (origin === DocumentOrigins.SCOPUS)
            return await ScopusExternalImporter.updateDocument(id);
    },
    search: async (origin, searchKey, searchValue) => {
        if (origin !== DocumentOrigins.SCOPUS)
            throw 'Not implemented';

        const filedsMapper = {};
        filedsMapper[DocumentOrigins.SCOPUS] = {
            'originId': 'scopusId',
            'doi': 'doi'
        };

        let document;

        const criteria = {
            kind: DocumentKinds.EXTERNAL
        };
        criteria[filedsMapper[origin][searchKey]] = searchValue;
        document = await Document.findOne(criteria);

        if (!document && searchKey === 'doi') {
            if (!document) {
                const documentData = await Connector.getDocumentByDoi(origin, searchValue);
                document = await ExternalImporter.createExternalDocument(origin, documentData);
            }
        }
        if (!document && searchKey === 'originId') {<commit_msg>Fixed bug on doi search<commit_after>/* global sails, ScopusExternalImporter, PublicationsExternalImporter, User, Group, DocumentOrigins, DocumentKinds */
// ExternalImporter.js - in api/services

"use strict";

module.exports = {
    updateUserExternal: async (id, origin) => {
        const user = await User.findOneById(id);
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateUser(user);
        if (!origin || origin === DocumentOrigins.PUBLICATIONS)
            await PublicationsExternalImporter.updateUser(user);
    },
    updateGroupExternal: async (id, origin) => {
        const group = await Group.findOneById(id);
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateGroup(group);
        if (!origin || origin === DocumentOrigins.PUBLICATIONS)
            await PublicationsExternalImporter.updateGroup(group);
    },
    updateAllExternal: async (origin) => {
        if (!origin || origin === DocumentOrigins.SCOPUS)
            await ScopusExternalImporter.updateAll();
    },
    updateDocument: async (origin, id) => {
        if (origin === DocumentOrigins.SCOPUS)
            return await ScopusExternalImporter.updateDocument(id);
    },
    search: async (origin, searchKey, searchValue) => {
        if (origin !== DocumentOrigins.SCOPUS)
            throw 'Not implemented';

        const filedsMapper = {};
        filedsMapper[DocumentOrigins.SCOPUS] = {
            'originId': 'scopusId',
            'doi': 'doi'
        };

        let document;

        const criteria = {
            kind: DocumentKinds.EXTERNAL,
            origin: origin
        };
        criteria[filedsMapper[origin][searchKey]] = searchValue;
        document = await Document.findOne(criteria);

        if (!document && searchKey === 'doi') {
            if (!document) {
                const documentData = await Connector.getDocumentByDoi(origin, searchValue);
                document = await ExternalImporter.createExternalDocument(origin, documentData);
            }
        }
        if (!document && searchKey === 'originId') {
{'fraction_non_alphanumeric': 0.11439287388654477, 'fraction_numerical': 0.0, 'mean_word_length': 2.6130397967823877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4642808', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1130, 'n_words': 250}