Skip to content

Commit

Permalink
Implement DataCite API support
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Feb 4, 2016
1 parent bebf135 commit 22a5e93
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 15 deletions.
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@
<version>0.7.5.201505241946</version>
</dependency>
<!-- Added for DataCite -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -328,6 +343,31 @@
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public String createIdentifier(String identifier, HashMap<String, String> metada
metadata.get("datacite.title"), metadata.get("datacite.publisher"),
metadata.get("datacite.publicationyear")});
String xmlMetadata = metadataTemplate.generateXML();
logger.log(Level.INFO, "xmlMetadata 70 " + xmlMetadata.toString() );
String status = metadata.get("_status").trim();
String target = metadata.get("_target");
String retString = "";
Expand Down Expand Up @@ -206,6 +207,7 @@ public DataCiteMetadataTemplate(String xmlMetaData){
}

public String generateXML() {
System.out.print("in generate xml...");
xmlMetadata = template.replace("${identifier}", this.identifier.trim())
.replace("${title}", this.title)
.replace("${publisher}", this.publisher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public String createIdentifier(Dataset dataset) {
HashMap metadata = getMetadataFromStudyForCreateIndicator(dataset);
metadata.put("_status", "reserved");
try {
logger.log(Level.INFO, "doiDataCiteRegisterService.toString : " + doiDataCiteRegisterService.toString());
retString = doiDataCiteRegisterService.createIdentifier(identifier, metadata);
logger.log(Level.INFO, "create DOI identifier retString : " + retString);
} catch (Exception e) {
Expand Down Expand Up @@ -140,7 +141,7 @@ public void deleteIdentifier(Dataset datasetIn) {
return;
}
if (idStatus.equals("public")) {
//if public then it has been released set to unavaialble and reset target to n2t url
//if public then it has been released set to unavailable and reset target to n2t url
updateIdentifierStatus(datasetIn, "unavailable");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
package edu.harvard.iq.dataverse;


import java.io.IOException;

import java.io.UnsupportedEncodingException;

import java.util.logging.Level;
Expand Down Expand Up @@ -43,7 +45,7 @@ public class DataCiteRESTfullClient {
private CloseableHttpClient httpClient;
private HttpClientContext context;
private String encoding = "utf-8";

public DataCiteRESTfullClient(String url, String username, String password) {
this.url = url;
try {
Expand Down Expand Up @@ -149,10 +151,14 @@ public String postMetadata(String metadata) throws UnsupportedEncodingException
HttpPost httpPost = new HttpPost(this.url + "/metadata");
httpPost.setHeader("Content-Type", "application/xml;charset=UTF-8");
httpPost.setEntity(new StringEntity(metadata, "utf-8"));

System.out.print("in post metadata entity: " + httpPost.getEntity().toString());
System.out.print("In PostMetadata httpClient " + httpClient.toString());
System.out.print("In PostMetadata credentials " + context.getCredentialsProvider().getCredentials(AuthScope.ANY));
try {
HttpResponse response = httpClient.execute(httpPost,context);

String data = EntityUtils.toString(response.getEntity(), encoding);
System.out.print("response " + data);
if (response.getStatusLine().getStatusCode() != 201) {
String errMsg = "Response code: " + response.getStatusLine().getStatusCode() + ", " + data;
logger.log(Level.SEVERE, errMsg);
Expand Down Expand Up @@ -190,7 +196,7 @@ public String inactiveDataset(String doi) {

public static void main(String[] args) throws Exception {
String doi = "10.5072/DVN/274533";
DataCiteRESTfullClient client = new DataCiteRESTfullClient("https://mds.test.datacite.org", "TIB.PUB", "62751062");
DataCiteRESTfullClient client = new DataCiteRESTfullClient("https://mds.test.datacite.org", "DATACITE.HARVARD", "DVNapitest");
// System.out.println(client.getUrl(doi));
// System.out.println(client.getMetadata(doi));
// System.out.println(client.postMetadata(readAndClose("C:/Users/luopc/Desktop/datacite.xml", "utf-8")));
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ public String saveGuestbookResponse(String type) {
} else {
for (FileMetadata fmd : this.selectedFiles) {
DataFile df = fmd.getDataFile();
if (df != null) {
if (df != null && canDownloadFile(fmd)) {
this.guestbookResponse.setDataFile(df);
cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), this.guestbookResponse, dataset);
commandEngine.submit(cmd);
Expand Down Expand Up @@ -2089,8 +2089,19 @@ public String getSelectedFilesIdsString() {
}
downloadIdString += fmd.getDataFile().getId();
}
return downloadIdString;

return downloadIdString;
}

// helper Method
public String getSelectedFilesIdsStringForDownload() {
String downloadIdString = "";
for (FileMetadata fmd : this.selectedFiles){
if (!StringUtil.isEmpty(downloadIdString)) {
downloadIdString += ",";
}
downloadIdString += fmd.getDataFile().getId();
}
return downloadIdString;
}

public void updateFileCounts(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ public DatasetVersion execute(CommandContext ctxt) throws CommandException {

theVersion.setVersionState(DatasetVersion.VersionState.DEACCESSIONED);

if (deleteDOIIdentifier){
String nonNullDefaultIfKeyNotFound = "";
if (deleteDOIIdentifier) {
String nonNullDefaultIfKeyNotFound = "";

String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound);

if (doiProvider.equals("EZID")) ctxt.doiEZId().deleteIdentifier(ds);
if (doiProvider.equals("DataCite")) ctxt.doiDataCite().deleteIdentifier(ds);
}
String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound);

if (doiProvider.equals("EZID")) {
ctxt.doiEZId().deleteIdentifier(ds);
}
if (doiProvider.equals("DataCite")) {
ctxt.doiDataCite().deleteIdentifier(ds);
}
}
DatasetVersion managed = ctxt.em().merge(theVersion);

boolean doNormalSolrDocCleanUp = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import edu.harvard.iq.dataverse.actionlogging.ActionLogRecord;
import edu.harvard.iq.dataverse.actionlogging.ActionLogServiceBean;
import edu.harvard.iq.dataverse.api.ApiBlockingFilter;
//import edu.harvard.iq.dataverse.api.ApiBlockingFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd"
xmlns="http://datacite.org/schema/kernel-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<identifier identifierType="DOI">${identifier}</identifier>
<creators>${creators}</creators>
<titles>
<title>${title}</title>
</titles>
<publisher>${publisher}</publisher>
<publicationYear>${publisherYear}</publicationYear>
</resource>

0 comments on commit 22a5e93

Please sign in to comment.