@Requirement(reqId="DOI_INTER_010", reqName="Interface avec Datacite Metadata Store") public class ClientMDS extends BaseClient
Modifier and Type | Class and Description |
---|---|
static class |
ClientMDS.Context
Options for each context
|
static class |
ClientMDS.DATACITE_API_RESPONSE
Datacite API.
|
private static class |
ClientMDS.MyValidationEventHandler
Metadata Validation.
|
Modifier and Type | Field and Description |
---|---|
private ClientMDS.Context |
context
Context.
|
static String |
DATA_CITE_MOCK_URL
Metadata store mock service endpoint "http://localhost:1080".
|
static String |
DATA_CITE_TEST_URL
Metadata store test service endpoint "https://mds.test.datacite.org".
|
static String |
DATA_CITE_URL
Metadata store service endpoint "https://mds.datacite.org".
|
static String |
DOI_RESOURCE
DOI resource "doi".
|
private static DoiSettings |
DOI_SETTINGS
Loads DOI settings.
|
static String |
MEDIA_RESOURCE
Media resource "media".
|
static String |
METADATA_RESOURCE
Metadata resource "metadata".
|
static String |
POST_DOI
DOI query parameter "doi".
|
static String |
POST_URL
URL query parameter "url".
|
static String |
SCHEMA_DATACITE
Default XML schema for Datacite: "https://schema.datacite.org/meta/kernel-4-1/metadata.xsd"
|
private static SchemaFactory |
SCHEMA_FACTORY
SCHEMA_FACTORY.
|
static String |
TEST_DOI_PREFIX
Test DOI prefix "10.80163".
|
static org.restlet.data.Parameter |
TEST_MODE
Test mode sets to true.
|
private org.restlet.data.Parameter |
testMode
Selected test mode.
|
DATACITE_MOCKSERVER_PORT
Constructor and Description |
---|
ClientMDS(ClientMDS.Context context)
Creates a client to handle DataCite server.
|
ClientMDS(ClientMDS.Context context,
String login,
String pwd)
Creates a client to handle DataCite with a HTTP Basic authentication.
|
ClientMDS(String login,
String pwd)
Creates a client to handle DataCite with a HTTP Basic authentication.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkIfAllCharsAreValid(String test)
DataCite recommends that only the following characters are used within a
DOI name:
0-9
a-z
A-Z
- (dash)
.
|
private void |
checkInputForm(org.restlet.data.Form form)
Checks the input parameters and specially the validity of the DOI name.
|
String |
createDoi(org.restlet.data.Form form)
Will mint new DOI if specified DOI doesn't exist.
|
private org.restlet.representation.Representation |
createEntity(org.restlet.data.Form mediaForm)
Creates an entity based on the form.
|
String |
createMedia(String doiName,
org.restlet.data.Form form)
Will add/update media type/urls pairs to a DOI.
|
String |
createMetadata(org.restlet.representation.Representation entity)
This request stores new version of metadata.
|
String |
createMetadata(Resource entity)
Creates metadata with 201 status when operation successful.
|
private org.restlet.data.Reference |
createReference(String segment)
Create reference.
|
private org.restlet.data.Reference |
createReferenceWithDOI(String segment,
String doiName)
Creates the URL to query.
|
private org.restlet.representation.Representation |
createRequest(org.restlet.data.Reference url,
org.restlet.data.Form form)
Creates the request and requests the DOI creation
|
org.restlet.representation.Representation |
deleteMetadata(String doiName)
This request marks a dataset as 'inactive'.
|
Resource |
deleteMetadataDoiAsObject(String doiName)
This request marks a dataset as 'inactive'.
|
String |
getDoi(String doiName)
This request returns an URL associated with a given DOI.
|
private String |
getDoiAccorgindToContext(String doiName)
Returns the right DOI according to the context (DEV, POST_DEV, ...).
|
List<String> |
getDois() |
List<String> |
getDois(String idProject)
Returns only the dois within the specified project from the search
result.
|
private List<String> |
getList(String segment)
Returns the response as a list of String of an URI.
|
String |
getMedia(String doiName)
This request returns list of pairs of media type and URLs associated with
a given DOI.
|
org.restlet.representation.Representation |
getMetadata(String doiName)
Returns the metadata based on its DOI name.
|
Resource |
getMetadataAsObject(String doiName)
This request returns the most recent version of metadata associated with
a given DOI.
|
private org.restlet.data.Parameter |
getTestMode()
Returns the
TEST_MODE or an empty parameter according to
isTestMode |
private String |
getText(org.restlet.representation.Representation rep)
Returns the text of a response.
|
private void |
initReference()
Init the client to the reference
DATA_CITE_URL or
DATA_CITE_TEST_URL |
private Resource |
parseDataciteResource(org.restlet.representation.Representation rep)
Parses the XML representation that implements the DATACITE schema.
|
Resource |
parseMetadata(org.restlet.representation.Representation entity)
Parses the metadata and returns the Resource object from DataCite.
|
private String |
useTestPrefix(String doiName)
Renames the current DOI prefix by the DOI test prefix.
|
getClient, getLog
public static final String DATA_CITE_URL
public static final String DATA_CITE_MOCK_URL
public static final String DATA_CITE_TEST_URL
public static final String DOI_RESOURCE
public static final String METADATA_RESOURCE
public static final String MEDIA_RESOURCE
public static final org.restlet.data.Parameter TEST_MODE
public static final String TEST_DOI_PREFIX
public static final String POST_DOI
public static final String POST_URL
public static final String SCHEMA_DATACITE
private static final SchemaFactory SCHEMA_FACTORY
private static final DoiSettings DOI_SETTINGS
private final org.restlet.data.Parameter testMode
private final ClientMDS.Context context
public ClientMDS(ClientMDS.Context context) throws ClientMdsException
It is important to understand that the Handle System (the technical infrastructure for DOIs) is a distributed network system. The consequence of this manifests is its inherent latency. For example, DOIs have TTL (time to live) defaulted to 24 hours, so your changes will be visible to the resolution infrastructure only when the TTL expires. Also, if you create a DOI and then immediately try to update its URL, you might get the error message HANDLE NOT EXISTS. This is because it takes some time for the system to register a handle for a DOI. Each API call can have optional query parametertestMode. If set to "true" or "1" the request will not change the database nor will the DOI handle will be registered or updated, e.g. POST /doi?testMode=true and the testing prefix will be used instead of the provided prefix
context
- Context usingClientMdsException
- Cannot the Datacite
schemapublic ClientMDS(ClientMDS.Context context, String login, String pwd) throws ClientMdsException
context
- Context usinglogin
- Loginpwd
- passwordClientMdsException
- Cannot the Datacite
schemapublic ClientMDS(String login, String pwd) throws ClientMdsException
login
- Loginpwd
- passwordClientMdsException
- Cannot the Datacite
schemapublic static void checkIfAllCharsAreValid(String test)
test
- DOI name to testIllegalArgumentException
- An exception is thrown when at least one
character is not part of 0-9a-zA-Z\\-._+:/ of a DOI nameprivate org.restlet.data.Parameter getTestMode()
TEST_MODE
or an empty parameter according to
isTestModeprivate String useTestPrefix(String doiName)
doiName
- real DOI nameprivate void initReference()
DATA_CITE_URL
or
DATA_CITE_TEST_URL
private org.restlet.data.Reference createReference(String segment)
segment
- segment to add to the end pointprivate org.restlet.data.Reference createReferenceWithDOI(String segment, String doiName)
segment
- segment to add to the end point servicedoiName
- doi nameprivate String getDoiAccorgindToContext(String doiName)
doiName
- DOI nameprivate void checkInputForm(org.restlet.data.Form form) throws IllegalArgumentException
context
.form
- query formIllegalArgumentException
- An exception is thrown when doi and url
are not provided or when one character at least in the DOI name is not
validprivate String getText(org.restlet.representation.Representation rep) throws ClientMdsException
rep
- Response of the serverClientMdsException
- An exception is thrown when cannot convert the
Representation to textprivate List<String> getList(String segment) throws ClientMdsException
segment
- resource nameClientMdsException
- - if an error happens when requesting
CrossCitepublic String getDoi(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public List<String> getDois() throws ClientMdsException
ClientMdsException
public List<String> getDois(String idProject) throws ClientMdsException
idProject
- project IDClientMdsException
- When an error happens
with Datacitepublic String createDoi(org.restlet.data.Form form) throws ClientMdsException
context
.form
- A form with the following attributes doi and urlClientMdsException
- - if an error happens private org.restlet.representation.Representation createRequest(org.restlet.data.Reference url, org.restlet.data.Form form)
url
- urlform
- formprivate Resource parseDataciteResource(org.restlet.representation.Representation rep) throws ClientMdsException
rep
- XML representationClientMdsException
- Will throw when a problem happens during the
parsingpublic Resource getMetadataAsObject(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public org.restlet.representation.Representation getMetadata(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public String createMetadata(org.restlet.representation.Representation entity) throws ClientMdsException
context
.entity
- A valid XMLClientMdsException
- - if an error happens public String createMetadata(Resource entity) throws ClientMdsException
context
.
The method is synchronized because marshall method is not thread-safe.entity
- MetadataClientMdsException
- - if an error happens public Resource parseMetadata(org.restlet.representation.Representation entity) throws ValidationException
entity
- metadataValidationException
- When validation failedpublic Resource deleteMetadataDoiAsObject(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public org.restlet.representation.Representation deleteMetadata(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public String getMedia(String doiName) throws ClientMdsException
context
.doiName
- DOI nameClientMdsException
- - if an error happens public String createMedia(String doiName, org.restlet.data.Form form) throws ClientMdsException
context
.doiName
- DOI identifierform
- Multiple lines in the following format{mime-type}={url} where
{mime-type} and {url} have to be replaced by your mime type and URL,
UFT-8 encoded.ClientMdsException
- - if an error happens private org.restlet.representation.Representation createEntity(org.restlet.data.Form mediaForm)
mediaForm
- formCopyright © 2017–2020 CNES. All rights reserved.