{
  "name": "Journal extraction",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -640,
        0
      ],
      "id": "a798ff0e-f2c1-45ca-99fd-cf96cb7e0880",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "compare": "selectedFields",
        "fieldsToCompare": "sm_issn",
        "options": {
          "removeOtherFields": true
        }
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1456,
        -16
      ],
      "id": "0973769e-4758-4449-9a46-65109a7ef9ac",
      "name": "Remove Duplicates"
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "sm_issn"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        -640,
        224
      ],
      "id": "b38b7098-2e5e-4d23-96b2-e3206643ce73",
      "name": "Sort ISSN"
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction readCSV(data) {\n  // Split on '\\n' to read line by line\n  let lines = data.split(\"\\n\");\n  let columnNames = [];\n  let final = [];\n  for (let i=0;i<lines.length-1;i++) {\n    let columns = lines[i].split(/(?<!\\\\),/);\n    if (i==0) {\n      columnNames = columnNames.concat(columns);\n    } else {\n      let obj = {};\n      for (let c=0;c<columns.length;c++) {\n        obj[columnNames[c]] = columns[c];\n      }\n      final.push({'json': obj});\n    }\n  }\n  return final;\n}\n\n// console.log($input);\nlet results = []\nfor (let item of $input.all()) {\n  results = readCSV(item.json.data);\n}\n\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -112,
        -304
      ],
      "id": "582b8954-e9ca-40e9-b9fa-aa21fbaef501",
      "name": "Convert result to multiple items",
      "disabled": true
    },
    {
      "parameters": {
        "url": "https://kermit.bib.uclouvain.be/kermit-base/rest/search/bibliographic",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ 'identifiers.identifier:\"' + $json.sm_issn + '\"' }}"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 20
            }
          },
          "allowUnauthorizedCerts": true,
          "timeout": 10000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -432,
        224
      ],
      "id": "4aff1c41-4c10-41f6-96f9-d466d7fed124",
      "name": "Get kermit data",
      "retryOnFail": true
    },
    {
      "parameters": {
        "url": "https://dial.uclouvain.be/solr/repository/select",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "fl",
              "value": "ss_pid,sm_doi,sm_issn,sm_eissn,sm_journal.title,sm_publisher.name"
            },
            {
              "name": "fq",
              "value": "sm_contentmodel:\"boreal-system:ResearchPublicationCM\""
            },
            {
              "name": "indent",
              "value": "on"
            },
            {
              "name": "q",
              "value": "sm_journal.title:*"
            },
            {
              "name": "rows",
              "value": "200000"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -432,
        0
      ],
      "id": "f96b6cd9-2f84-42ef-8ca7-785fa2cca927",
      "name": "DIAL.pr get journals",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d85acfab-2956-4700-a62e-4dca9f9f8422",
              "leftValue": "={{ $json.results }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "exists",
                "singleValue": true
              }
            },
            {
              "id": "eb1150dd-9645-4b16-bbc9-3763688f1923",
              "leftValue": "={{ $json.results }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -224,
        224
      ],
      "id": "750997ba-9f29-4015-90ec-d4abc5622f08",
      "name": "Keep only successful calls"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6050c7b9-e098-490b-907d-2a4dd5f49b97",
              "name": "title",
              "value": "={{ $json.results[0].title }}",
              "type": "string"
            },
            {
              "id": "bc76fd01-0b6f-491e-8d46-f9bdae5e9bd7",
              "name": "issn",
              "value": "={{ $json.results[0].issn }}",
              "type": "string"
            },
            {
              "id": "90ccb4e0-045c-438f-a86e-084de5368a70",
              "name": "eissn",
              "value": "={{ $json.results[0].eissn }}",
              "type": "string"
            },
            {
              "id": "1894d6e0-7aaa-4839-ac21-d5df5d10ab18",
              "name": "publisher",
              "value": "={{ $json.results[0].publisher }}",
              "type": "string"
            },
            {
              "id": "8be4ac00-622b-4a6a-8d1d-36cb56f79f1e",
              "name": "publisherLocation",
              "value": "={{ $json.results[0].publisherCity }}",
              "type": "string"
            },
            {
              "id": "53744ccf-d8db-491c-9bf4-d72fbe9c20f9",
              "name": "peerReviewed",
              "value": "={{ $json.results[0].peerReviewed }}",
              "type": "string"
            },
            {
              "id": "301f2000-b8c9-4c4f-ab41-6cefe489cef7",
              "name": "statusCode",
              "value": "={{ $json.results[0].statusCode }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        16,
        224
      ],
      "id": "34028872-271f-47e1-9e47-097981a4810f",
      "name": "Keep only useful metadata"
    },
    {
      "parameters": {
        "content": "## Get Kermit data \nSet batch to 1 with a delay of 20ms between calls to prevent errors."
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        416
      ],
      "typeVersion": 1,
      "id": "7e88fb62-370c-4c10-b254-2cbc3755e7e8",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "7caf7185-1a9a-4bda-9dc5-f52969ce27f4",
              "leftValue": "={{ $json.sm_issn }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "exists",
                "singleValue": true
              }
            },
            {
              "id": "eba50966-6358-4af0-ab04-27dee759baa5",
              "leftValue": "={{ $json.sm_issn }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        16,
        0
      ],
      "id": "f98625a1-c34e-4d23-a690-32010b41e93b",
      "name": "Keep not empty ISSN"
    },
    {
      "parameters": {
        "content": "## FIX ISSN\nIf an ISSN does not match the initial regexp, try to fix it.",
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -528
      ],
      "typeVersion": 1,
      "id": "83c499e9-2658-4e64-aa03-6d98f6ad6f4c",
      "name": "Sticky Note2",
      "disabled": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "eb1652b3-75a9-4685-a63d-c4f1760c0c71",
              "name": "sm_issn",
              "value": "={{ $json.sm_issn.toUpperCase() }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1008,
        0
      ],
      "id": "1a40ece1-5855-4a83-a878-0af6fd745a11",
      "name": "Uppercase for x"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "412e9229-807b-4eda-859e-45393ef1be06",
              "name": "sm_issn",
              "value": "={{ $json.sm_issn.slice(0, 4) + \"-\" + $json.sm_issn.slice(4, 8) }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1008,
        -176
      ],
      "id": "6d01e280-b765-43f9-90a4-31b00b405280",
      "name": "Add separator"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1280,
        -240
      ],
      "id": "ad32898a-8dd6-4b1e-bbbd-9556c0faf685",
      "name": "Merge"
    },
    {
      "parameters": {
        "fieldToSplitOut": "response.docs",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -224,
        0
      ],
      "id": "81965128-5712-4990-bbfa-aef89974e6d2",
      "name": "Split Out"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "ff72731d-65a0-4e43-89dd-3c1a98390921",
              "name": "sm_issn",
              "value": "={{ $json.sm_issn[0] }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        272,
        0
      ],
      "id": "4e0bec8b-539b-496e-a59b-74b98d2b2eea",
      "name": "Keep only ISSN"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "be346a04-edf6-43fc-83a9-037d31264ec8",
              "leftValue": "={{ $json.sm_issn }}",
              "rightValue": "^\\d{4}-\\d{3}[\\dX]$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        656,
        -352
      ],
      "id": "0ed8049c-9a0c-4ee6-b71c-3867fef73655",
      "name": "Keep only valid ISSN"
    },
    {
      "parameters": {
        "url": "https://dial.uclouvain.be/solr/repository/select",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "fl",
              "value": "ss_pid,sm_doi,sm_issn,sm_eissn,sm_journal.title,sm_publisher.name"
            },
            {
              "name": "fq",
              "value": "sm_contentmodel:\"boreal-system:ResearchPublicationCM\""
            },
            {
              "name": "indent",
              "value": "on"
            },
            {
              "name": "q",
              "value": "sm_journal.title:*"
            },
            {
              "name": "rows",
              "value": "10000"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "start",
                    "value": "={{ parseInt($response.body.response.start) + parseInt($response.body.responseHeader.params.rows) }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $response.body.response.numFound == 0 }}",
              "requestInterval": 5
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -400,
        -320
      ],
      "id": "a49be691-dbfd-4930-bc06-4f6f45cd46e5",
      "name": "DIAL.pr get journals (paginated)",
      "alwaysOutputData": false,
      "disabled": true
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.sm_issn }}",
                    "rightValue": "^\\d{4}\\d{3}[\\dX]$",
                    "operator": {
                      "type": "string",
                      "operation": "regex"
                    },
                    "id": "42657391-a9b5-4f40-8ecf-3ea3553abf87"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "2703359b-51fa-4d66-b636-2abea6c82bac",
                    "leftValue": "={{ $json.sm_issn }}",
                    "rightValue": "^\\d{4}-\\d{3}[\\dx]$",
                    "operator": {
                      "type": "string",
                      "operation": "regex"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        816,
        -96
      ],
      "id": "23dbc507-971d-47ba-8aec-af109ad7caaa",
      "name": "Fix common issues"
    },
    {
      "parameters": {
        "compare": "selectedFields",
        "fieldsToCompare": "sm_issn",
        "options": {
          "removeOtherFields": true
        }
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        512,
        0
      ],
      "id": "7a94ba65-1dc9-43fe-893f-ffdad32369ef",
      "name": "Remove Duplicates2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "91683a97-0ff1-4b2a-9d63-b7674393fd41",
              "name": "statusCode",
              "value": "={{ $json.statusCode === \"Ceased\" ? \"Ceased\": \"Active\" }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        272,
        224
      ],
      "id": "d0878d35-d5e1-4a7f-817d-4d1921deb516",
      "name": "Convert to only active and ceased"
    },
    {
      "parameters": {
        "options": {
          "fileName": "={{ 'JournalToExport' + $now + '.csv' }}",
          "headerRow": false
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        816,
        224
      ],
      "id": "60f3f23b-8c83-4cf9-8f83-18013a388863",
      "name": "Convert to CSV"
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map(item => {\n  return {\n    json: {\n      ...item.json,\n      title: `\"${item.json.title.replace(/\"/g, '\"\"')}\"`\n    }\n  };\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        512,
        224
      ],
      "id": "1d23d7d0-43dc-4b4a-9288-057e7f8f912a",
      "name": "Escape titles special characters"
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "DIAL.pr get journals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Sort ISSN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert result to multiple items": {
      "main": [
        []
      ]
    },
    "Sort ISSN": {
      "main": [
        [
          {
            "node": "Get kermit data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DIAL.pr get journals": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get kermit data": {
      "main": [
        [
          {
            "node": "Keep only successful calls",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only successful calls": {
      "main": [
        [
          {
            "node": "Keep only useful metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only useful metadata": {
      "main": [
        [
          {
            "node": "Convert to only active and ceased",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep not empty ISSN": {
      "main": [
        [
          {
            "node": "Keep only ISSN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add separator": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Uppercase for x": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Keep not empty ISSN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only ISSN": {
      "main": [
        [
          {
            "node": "Remove Duplicates2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only valid ISSN": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fix common issues",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix common issues": {
      "main": [
        [
          {
            "node": "Add separator",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Uppercase for x",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates2": {
      "main": [
        [
          {
            "node": "Keep only valid ISSN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to only active and ceased": {
      "main": [
        [
          {
            "node": "Escape titles special characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Escape titles special characters": {
      "main": [
        [
          {
            "node": "Convert to CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9225b915-7c9b-4b8e-9fe7-3d3b38df77a7",
  "meta": {
    "templateId": "self-building-ai-agent",
    "templateCredsSetupCompleted": true,
    "instanceId": "fd159add586de105547293eb2411b1bd997bcfcaffe5b8410bd4582d3feb0008"
  },
  "id": "Ec8rom8fkze4YFag",
  "tags": []
}