Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,22 @@ public boolean registerWhenPublished() {

@Override
public boolean alreadyExists(DvObject dvObject) {
if(dvObject==null) {
logger.severe("Null DvObject sent to alreadyExists().");
return false;
}
return alreadyExists(dvObject.getGlobalId());
}

@Override
public boolean alreadyExists(GlobalId pid) {
logger.log(Level.FINE,"alreadyExists");
if(pid==null) {
logger.severe("No identifier sent.");
return false;
}
boolean alreadyExists;
String identifier = getIdentifier(dvObject);
String identifier = pid.asString();
try{
alreadyExists = doiDataCiteRegisterService.testDOIExists(identifier);
} catch (Exception e){
Expand All @@ -43,7 +56,6 @@ public boolean alreadyExists(DvObject dvObject) {
return alreadyExists;
}



@Override
public String createIdentifier(DvObject dvObject) throws Exception {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,31 @@ public boolean registerWhenPublished() {

@Override
public boolean alreadyExists(DvObject dvObject) throws Exception {
if(dvObject==null) {
logger.severe("Null DvObject sent to alreadyExists().");
return false;
}
return alreadyExists(dvObject.getGlobalId());
}

@Override
public boolean alreadyExists(GlobalId pid) throws Exception {
logger.log(Level.FINE,"alreadyExists");
try {
HashMap<String, String> result = ezidService.getMetadata(getIdentifier(dvObject));
HashMap<String, String> result = ezidService.getMetadata(pid.asString());
return result != null && !result.isEmpty();
// TODO just check for HTTP status code 200/404, sadly the status code is swept under the carpet
} catch (EZIDException e ){
//No such identifier is treated as an exception
//but if that is the case then we want to just return false
if(dvObject.getIdentifier() == null){
if(pid.getIdentifier() == null){
return false;
}
if (e.getLocalizedMessage().contains("no such identifier")){
return false;
}
logger.log(Level.WARNING, "alreadyExists failed");
logger.log(Level.WARNING, "getIdentifier(dvObject) {0}", getIdentifier(dvObject));
logger.log(Level.WARNING, "getIdentifier(dvObject) {0}", pid.asString());
logger.log(Level.WARNING, "String {0}", e.toString());
logger.log(Level.WARNING, "localized message {0}", e.getLocalizedMessage());
logger.log(Level.WARNING, "cause", e.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ public boolean isGlobalIdUnique(String userIdentifier, DataFile datafile, Global
.getResultList().isEmpty();

try{
if (idServiceBean.alreadyExists(datafile)) {
if (idServiceBean.alreadyExists(new GlobalId(testProtocol, testAuthority, userIdentifier))) {
u = false;
}
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface GlobalIdServiceBean {
static final Logger logger = Logger.getLogger(GlobalIdServiceBean.class.getCanonicalName());

boolean alreadyExists(DvObject dvo) throws Exception;

boolean alreadyExists(GlobalId globalId) throws Exception;

boolean registerWhenPublished();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ public boolean alreadyExists(DvObject dvObject) throws Exception {
return isHandleRegistered(handle);
}

@Override
public boolean alreadyExists(GlobalId pid) throws Exception {
String handle = pid.getAuthority() + "/" + pid.getIdentifier();
return isHandleRegistered(handle);
}

@Override
public Map<String,String> getIdentifierMetadata(DvObject dvObject) {
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import edu.harvard.iq.dataverse.AbstractGlobalIdServiceBean;
import edu.harvard.iq.dataverse.DvObject;
import edu.harvard.iq.dataverse.GlobalId;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -15,6 +17,11 @@ public class FakePidProviderServiceBean extends AbstractGlobalIdServiceBean {
public boolean alreadyExists(DvObject dvo) throws Exception {
return true;
}

@Override
public boolean alreadyExists(GlobalId globalId) throws Exception {
return true;
}

@Override
public boolean registerWhenPublished() {
Expand Down