Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Alzpeta committed Aug 29, 2024
1 parent 45955da commit 0f3e839
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# OARepo DOI

### configuration example
### Configuration example

```
DATACITE_URL = 'https://api.test.datacite.org/dois'
DATACITE_MAPPING = {'local://documents-1.0.0.json':"common.mapping.DataCiteMappingNRDocs"}
Expand All @@ -11,10 +12,57 @@ DATACITE_MODE = "AUTOMATIC_DRAFT"
DATACITE_CREDENTIALS = {"generric": {"mode": "AUTOMATIC_DRAFT", "prefix": "10.23644" , "password": "yyyy", "username": "xxx"}}
DATACITE_CREDENTIALS_DEFAULT = {"mode": "AUTOMATIC_DRAFT", "prefix": "10.23644" , "password": "yyy", "username": "xxxx"}

```

mode types:
- AUTOMATIC_DRAFT - dois will be assigned automatically when draft is creadet
- AUTOMATIC - dois will be assigned automatically after publish
- ON_EVENT - dois are assigned after request
- `AUTOMATIC_DRAFT` - dois will be assigned automatically when draft is creadet
- `AUTOMATIC` - dois will be assigned automatically after publish
- `ON_EVENT` - dois are assigned after request

### Mapping example

```python
class DataCiteMappingNRDocs:

def metadata_check(self, data, errors=[]):

data = data["metadata"]
if "title" not in data:
errors.append("Title is mandatory")

return errors

def create_datacite_payload(self, data):
titles = {"title": "xy"}


payload = {
"data": {
"type": "dois",
"attributes": {
}
}
}
payload["data"]["attributes"]["titles"] = titles

return payload

def get_doi(self, record):
object_identifiers = record["metadata"].get("objectIdentifiers", [])
doi = None
for id in object_identifiers:
if id["scheme"] == "DOI":
doi = id["identifier"]
return doi

def add_doi(self, record, data, doi_value):
doi = {"scheme": "DOI", "identifier": doi_value}

if "objectIdentifiers" in data["metadata"]:
data["metadata"]["objectIdentifiers"].append(doi)
else:
data["metadata"]["objectIdentifiers"] = [doi]

record.update(data)
record.commit()
```

0 comments on commit 0f3e839

Please sign in to comment.