Skip to content

Latest commit

 

History

History
200 lines (148 loc) · 5.89 KB

README.md

File metadata and controls

200 lines (148 loc) · 5.89 KB

Cristin application for XP

Cristin is a service that gathers and makes available information about Norwegian research.

This application integrates with the Cristin APIs, to make it easy to create a relation between data in Cristin with content in XP.

Note You can use lib-xp-cristin in your application to interact with data from Cristin in your application.

Configuring your organization

This application is intended to cache data for one organization, which is specified in no.item.cristin.cfg.

Warning You need a config file XP_HOME/config/no.item.cristin.cfg with this configuration:

institution=<my-institution-number>

You may add an optional configuration to your config file, which will disable a scheduled job of type "import-result-contributors". Default behaviour is enabled:

importResultContributors=disabled

Using local copies of the Cristin data

We want to display data from Cristin on our XP site, and to make it quick, searchable and robust copies of data from the API is stored in local repos (Elastic Search Databases) in XP.

Upon installation of this application – and then on a nightly schedule – data from Cristin is copied into the local repositories

The follow repos are created:

  • "no.item.cristin.persons"
  • "no.item.cristin.institutions"
  • "no.item.cristin.projects"
  • "no.item.cristin.units"
  • "no.item.cristin.results"
  • "no.item.cristin.resultcontributors"

Creating a relation between Cristin data and XP Content

This application exposes four services that you can use with Custom Selectors to associate Cristin Ids with your XP Content.

Note For most of these services you can pass the Cristin ID of your institution as a parameter to filter.

<param value="institution">[my-institution-number]</param>

Person

Use the no.item.cristin:person CustomSelector-service to select a researcher from Cristin, and store their CristinID on the Content.

<input name="cristinProfileId" type="CustomSelector">
  <label>Profile from Cristin</label>
  <occurrences minimum="0" maximum="1"/>
  <config>
    <service>no.item.cristin:person</service>
    <param value="institution">186</param>
  </config>
</input>

Project

Use the no.item.cristin:project CustomSelector-service to get the CristinID of a Project.

<input name="cristinProjectId" type="CustomSelector">
  <label>Project from Cristin</label>
  <occurrences minimum="0" maximum="1"/>
  <config>
    <service>no.item.cristin:project</service>
    <param value="institution">186</param>
  </config>
</input>

Result

Use the no.item.cristin:result CustomSelector-service to get the CristinID of a Result.

<input name="cristinResultId" type="CustomSelector">
  <label>Publications from Cristin</label>
  <occurrences minimum="0" maximum="0"/>
  <config>
    <service>no.item.cristin:result</service>
    <param value="institution">186</param>
  </config>
</input>

Result Category

This CustomSelector-service can be used to create a filter in a part that returns which categories of Results should be displayed on the page.

<input name="cristinCategories" type="CustomSelector">
  <label>Publication categories</label>
  <help-text>Select the categories you want to appear in the list</help-text>
  <occurrences minimum="0" maximum="0"/>
  <config>
    <service>no.item.cristin:result-category</service>
  </config>
</input>

Events

Events that can be emitted from this library:

  • custom.cristin.result.create

*In Enonic XP you may listen to the events emitted from this library by defining a `listener: *

listener<CristinNode & Node>({
  type: "custom.cristin.result.*",
  callback: (event) => {
    // Handle event
  },
});

What do I use all these Cristin IDs for?

You can use lib-xp-cristin in your application to fetch the data related to the Cristin IDs.

Example usage of getCristinPerson() in an XP service (in TypeScript):

import { get as getOne } from "/lib/xp/content";
import { getCristinPerson } from "/lib/cristin";
import type { Employee } from "../../content-types"; 

export function get(req: XP.Request): XP.Response {
  const employee = getOne<Employee>({
    key: req.params.id!
  });

  if (employee) {
    const cristinPerson = getCristinPerson(employee.data.cristinProfileId);
    
    return {
      status: 200,
      body: {
        employee,
        cristinPerson
      }
    }
  } else {
    return {
      status: 404
    }
  }
}

The getCristinPerson() function does the following:

  1. Check if the data for the researcher (employee) is found in the local repo
  2. If not, fetch it from the Cristin API and save it to the repo
  3. Return the data (or void if it doesn't exist)

Development

Generating TypeScript-types for Cristin

JSON-Schemas from the Cristin APIs are downloaded and placed in the resources/schemas-directory. They are used to generate TypeScript-types in the resources/types-directory, by running the following script:

npm run json2ts

Deploying

Building

To build he project run the following code

enonic project build

Deploy locally

Deploy locally for testing purposes:

enonic project deploy

Deploy to Jitpack

Go to the Jitpack page for xp-cristin to deploy from Github.