npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@item-enonic-types/lib-cristin

v1.3.1

Published

Library for retrieving and storing data from Cristin

Downloads

173

Readme

Cristin Library for Enonic XP

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

Note This library is a companion to the xp-cristin application

This library is used to fetch data from the Cristin APIs, or read the data stored in a local repo by xp-cristin.

Installation

To install this library you need to add a new dependency to your app's build.gradle file.

Gradle

repositories {
  maven { url 'https://jitpack.io' }
}

dependencies {
  include "com.enonic.xp:lib-portal:${xpVersion}"
  include "com.enonic.xp:lib-repo:${xpVersion}"
  include "com.enonic.xp:lib-node:${xpVersion}"
  include "com.enonic.xp:lib-value:${xpVersion}"
  include "com.enonic.lib:lib-http-client:3.1.0"
  include "no.item:lib-xp-cristin:1.0.15"
}

Usage

Getting Cristin data by ID

For most cases using the functions in "/lib/cristin" is the most effective way to get Cristin data.

When calling these functions the following happens:

  1. Check if the data with that Cristin ID 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)

The following functions to get a single entity are exported from "/lib/cristin":

  • getCristinPerson(id)
  • getCristinInstitution(id)
  • getCristinProject(id)
  • getCristinUnit(id)
  • getCristinResult(id)
  • getCristinResultContributors(id) (Returns an Array of contributors for a single Result)

The following functions to get Arrays of entries are exported from "/lib/cristin":

  • getCristinPersons(ids)
  • getCristinInstitutions(ids)
  • getCristinProjects(ids)
  • getCristinUnits(ids)
  • getCristinResults(ids)

Example usage in an XP service:

var cristinLib = require('/lib/cristin');

exports.get = function() {
  const person = cristinLib.getCristinPerson("12345")
  
  return {
    status: 200,
    body: {
      person: person
    }
  }
}

Fetch only from API

It is also possible to not use the local repo, and only get the data fresh from the API

The following functions to get a single entry are exported from "/lib/cristin/service":

  • fetchPersons({ id })
  • fetchProject({ id })
  • fetchResult({ id })
  • fetchResultContributors({ id })
  • fetchInstitution({ id })
  • fetchUnit({ id })

The following functions to get an Array of entries are exported from "/lib/cristin/service":

  • fetchPersons(params)
  • fetchProjects(params)
  • fetchResults(params)
  • fetchPersonResults(params)
  • fetchInstitutions(params)
  • fetchResultCategories(params)
  • fetchUnits(params)

Only get from local repo (no API usage)

The following functions to get a single entry are exported from "/lib/cristin/storage":

  • lookupPerson(id)
  • lookupInstitution(id)
  • lookupProject(id)
  • lookupUnit(id)
  • lookupResult(id)
  • lookupResultContributors(id)

The following functions to get an Array of entries are exported from "/lib/cristin/storage":

  • lookupPerson(ids)
  • lookupInstitution(ids)
  • lookupProject(ids)
  • lookupUnit(ids)
  • lookupResult(ids)
  • lookupResultContributors(ids)

Graphql Schemas

This library also exports GraphQL-definitions for use with the Guillotine library.

Names as strings

The following names as strings are exported from "/lib/cristin/graphql":

  • GRAPHQL_OBJECT_NAME_CRISTIN_UNIT
  • GRAPHQL_OBJECT_NAME_CRISTIN_INSTITUTION
  • GRAPHQL_OBJECT_NAME_CRISTIN_PERSON
  • GRAPHQL_OBJECT_NAME_CRISTIN_PROJECT
  • GRAPHQL_OBJECT_NAME_CRISTIN_RESULT

The following functions to create GraphQL object types are exported from "/lib/cristin/graphql":

  • createObjectTypeCristinPerson(context, options)
  • createObjectTypeCristinInstitution(context, options)
  • createObjectTypeCristinProject(context, options)
  • createObjectTypeCristinResult(context, options)
  • createObjectTypeCristinResultCategory(context, options)
  • createObjectTypeCristinUnit(context, options)

The following reference() types are exported from "/lib/cristin/graphql" (for usage after the object types has been registered):

  • GraphQLCristinPerson
  • GraphQLCristinInstitution
  • GraphQLCristinProject
  • GraphQLCristinResult
  • GraphQLCristinUnit

Example usage in Guillotine controller:

var guillotineLib = require("/lib/guillotine");
var cristinLib = require("/lib/cristin");
var cristinGraphqlLib = require("/lib/cristin/graphql");

var schema = guillotineLib.createSchema({
  applications: ["com.myapp"],
  creationCallbacks: {
    com_myapp_Employee_Data: function(context, params) {
      // Register GraphQL object types for Cristin objects needed
      context.addDictionaryType(cristinGraphqlLib.createObjectTypeCristinInstitution(context));
      context.addDictionaryType(cristinGraphqlLib.createObjectTypeCristinPerson(context));
      
      params.fields.cristinProfile = {
        // Use the reference type (`reference("no_item_cristin_Person")`)
        type: cristinGraphqlLib.GraphQLCristinPerson,
        resolve: function(env) {
          return cristinLib.getCristinPerson(env.source.cristinProfileId);
        }
      };
    },
  }
});

Deploying

Building

To build he project run the following code

./gradlew build

Deploy locally

Deploy locally for testing purposes:

./gradlew publishToMavenLocal

Deploy to Jitpack

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