Sie zeigen eine alte Version dieser Seite an. Zeigen Sie die aktuelle Version an.

Unterschiede anzeigen Seitenhistorie anzeigen

Version 1 Nächste Version anzeigen »

Um die Anbindung eigener Anwendungen an den URN-Service bzw. die URN-Rest-API zu unterstützen, bieten wir einen Java-Client. 

Folgende Schnittstellen 


UrnNamespaceRepository

Interface for using the query- and creation-methods related to URN-Namespaces.

UrnOrganisationRepository

Interface for using the query-methods related to URN-Organisations.

UrnPoliciesRepository

Interface for using the query-methods related to URN-Policies.

UrnRepository

Interface for REST-API-Entry-Point to get information via RESTApiInfoResource about the URN-REST-API itself.

UrnUrnRepositoryInterface for using the query- and creation-methods related to URNs.

wurden hier implementiert:

UrnNamespaceRestClient

Entry point for the users of the URN client to access the RESTNamespaceResources.

UrnOrganisationRestClient

Entry point for the users of the URN client to access the RESTOrganisationResource.

UrnPoliciesRestClient

Entry point for the users of the URN client to access the RESTPoliciesResource.

UrnRestClient

Entry point for the users of the URN client to get information via RESTApiInfoResource about the URn-REST-API.

UrnUrnRestClient

Handles the task of making the connections and the requests to the Urn-Service's RestApi.

Schritt-für-Schritt-Anleitung

Technische Voraussetzungen:

  • Die Verwendung von Java 8 oder kompatiblere JVM Sprache in der entsprechenden Version.
  • Berechtigung zur Einspielung von URNS der eigenen Institutionen innerhalb des eigenen Namensraumes in Form von LOGIN / USER Credentials.
  • Die URL zur URN-Rest-API (z.B.: "http://api.nbn-resolving.org/sandbox/v2/").

UrnRestClient


private static final String V2_URI = "http://api.nbn-resolving.org/sandbox/v2/";

private static UrnRestClient urnRepository;

public static void main(String[] args) {

 	urnRepository = new UrnRestClient(V2_URI); 
	final ApiInfo info = urnRepository.getInfo();
}

liefert ein Objekt vom Typ ApiInfo mit folgenden Output (info.toString() ):


UrnNamespaceClient

Um die Namensräume gezielt abfragen zu können, werden Filter- und Sortierparameter benötigt. 

ORG_LOGIN und ORG_PASSWORD sind Platzhalter für das eigene LOGIN/PASSWORD.


getNamespaces()


getNamespaces()
private static final String V2_URI = "http://api.nbn-resolving.org/sandbox/v2/";
private static final String DEFAULT_NASP_WILDCARD = "urn:nbn:de*";
private static UrnNamespaceRestClient naspRepository;


public static void main(String[] args) {
 	naspRepository = new UrnNamespaceRestClient(V2_URI);
	
	  final Optional<NamespaceFilter> naspFilter = Optional
                .of(new NamespaceFilter(NamespaceFilterKey.NAME, DEFAULT_NASP_WILDCARD));
        final NamespaceSortParameters naspsortparams = new NamespaceSortParameters().getDefault();
        naspsortparams.setSortBy(NamespaceSortKey.NAME);
        final PagingParameters pagingParameters = new PagingParameters().getDefault();

        UrnRestResultNamespaceObject result = null;

        try {
            result = naspRepository.getNamespacesWithFilter(ORG_LOGIN, ORG_PASSWORD, naspFilter, naspsortparams,
                    pagingParameters);
        } catch (final UrnRestApiNotAvailableException e) {
            System.out.println("The client cannot connect to the URN-REST-API.");
        }
}


Diese Anfrage liefert ein Ergebnisobjekt vom Typ UrnRestResultNamespaceObject. Das UrnRestResultNamespaceObject "wrapt" das ursprüngliche RESTNamespaceRepresentation-Objekt und fügt weitere wichtige Informationen hinzu (Anfrage erfolreich, Anzahl Treffer, weitere Trefferseiten verfügbar, ...).Die Ergebnisse werden paginiert innerhalb einer ArrayList abgespeichert. 

Beispielantwort mittels toString() und Log4j

[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest - You will only see information enabled for your login.
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest - Request successful: true Count results: 428 Results have several pages: true
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest -
These items are on the first resultpage:
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest -
urn:nbn:de,
2003-10-01T06:00:00Z,
2006-04-25T09:36:22Z,
http://api.nbn-resolving.org/sandbox/v2/organisations/id/1,
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest -
urn:nbn:de:0001,
2003-10-17T12:39:18Z,
2003-10-17T12:39:18Z,
http://api.nbn-resolving.org/sandbox/v2/organisations/id/35,
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest -
urn:nbn:de:0002,
2003-10-17T12:36:50Z,
2003-10-17T12:36:50Z,
http://api.nbn-resolving.org/sandbox/v2/organisations/id/22,

....

....

....

getNamespace()

Führt eine Suche nach einem bestimmten Namensraum durch.

Notwendige Parameter sind wieder ORG_LOGIN, ORG_PASSWORD, Name des zu suchenden Namespace. Der letzte Parameter ist nur für Admins relevant (runAs) und kann leer bleiben. 

getNamespace()
private static final String V2_URI = "http://api.nbn-resolving.org/sandbox/v2/";
private static final String DEFAULT_NASP_WILDCARD = "urn:nbn:de*";
private static final String ORG_NAMESPACE = "urn:nbn:de:0007";
private static UrnNamespaceRestClient naspRepository;


public static void main(String[] args) {
 	naspRepository = new UrnNamespaceRestClient(V2_URI);
	
	UrnRestResultNamespaceObject result = null;

        try {
            result = naspRepository.getNamespaceViaName(ORG_LOGIN, ORG_PASSWORD, ORG_NAMESPACE, ORG_USER);
        } catch (final UrnRestApiNotAvailableException e) {
            LOGGER.error("The client cannot connect to the server. Is there an internet connection?");
        }

        LOGGER.info("Response End...");
}


Diese Anfrage liefert ein Ergebnisobjekt vom Typ UrnRestResultNamespaceObject. Die Ergebnisse werden paginiert ausgeliefert. Das UrnRestResultNamespaceObject "wrapt" das ursprüngliche RESTNamespaceRepresentation-Objekt und fügt weitere wichtige Informationen hinzu (Anfrage erfolreich, Anzahl Treffer, weitere Trefferseiten verfügbar, ...)

Beispielantwort mittels toString() und Log4j

[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest - getNamespace()...
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest -
UrnRestResultNamespaceObject [
urnNameSugg=[],
namespace=RESTNamespaceRepresentation [
self=http://api.nbn-resolving.org/sandbox/v2/namespaces/name/urn:nbn:de:0007,
name=urn:nbn:de:0007,
created=2023-07-11T09:13:37Z,
lastModified=2023-07-11T09:13:37Z,
allowsRegistration=true,
owner=http://api.nbn-resolving.org/sandbox/v2/organisations/id/19066,
urnNamingPolicy=http://api.nbn-resolving.org/sandbox/v2/policies/urn-naming/id/default,
urlPolicy=http://api.nbn-resolving.org/sandbox/v2/policies/url/id/only-http-ftp,
urns=http://api.nbn-resolving.org/sandbox/v2/namespaces/name/urn:nbn:de:0007/urns,
urnSuggestion=http://api.nbn-resolving.org/sandbox/v2/namespaces/name/urn:nbn:de:0007/urn-suggestion],
UrnRestResultObject [successful=true, httpStatusCode=200, ]]
[main] INFO de.dnb.resolvingdienste.urn.restapi.client.testurnclient.mainForTest - Response End...

Verwandte Artikel



  • Keine Stichwörter