Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IQSS-5505 - only update DOI metadata at PIDprovider when it changes #5506

Merged
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@
<artifactId>opennlp-tools</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,9 @@ public Response updateDatasetPIDMetadata(@Context ContainerRequestContext crc, @
}

return response(req -> {
execCommand(new UpdateDvObjectPIDMetadataCommand(findDatasetOrDie(id), req));
List<String> args = Arrays.asList(id);
Dataset dataset = findDatasetOrDie(id);
execCommand(new UpdateDvObjectPIDMetadataCommand(dataset, req));
List<String> args = Arrays.asList(dataset.getIdentifier());
return ok(BundleUtil.getStringFromBundle("datasets.api.updatePIDMetadata.success.for.single.dataset", args));
}, getRequestUser(crc));
}
Expand All @@ -695,7 +696,14 @@ public Response updateDatasetPIDMetadataAll(@Context ContainerRequestContext crc
return response( req -> {
datasetService.findAll().forEach( ds -> {
try {
logger.fine("ReRegistering: " + ds.getId() + " : " + ds.getIdentifier());
if (!ds.isReleased() || (!ds.isIdentifierRegistered() || (ds.getIdentifier() == null))) {
if (ds.isReleased()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails because the datasets is not released then nothing will go into the log. Do we want to put something in the logs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not, we just want to skip it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - we currently don't update the PID service after every edit. We could but there's also not a lot of value since the PID isn't searchable.

logger.warning("Dataset id=" + ds.getId() + " is in an inconsistent state (publicationdate but no identifier/identifier not registered");
}
} else {
execCommand(new UpdateDvObjectPIDMetadataCommand(findDatasetOrDie(ds.getId().toString()), req));
}
} catch (WrappedResponse ex) {
Logger.getLogger(Datasets.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
PidProvider pidProvider = PidUtil.getPidProvider(target.getGlobalId().getProviderId());

try {
Boolean doiRetString = pidProvider.publicizeIdentifier(target);
Boolean doiRetString = pidProvider.updateIdentifier(target);
if (doiRetString) {
target.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
ctxt.em().merge(target);
Expand All @@ -71,7 +71,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
(!(df.getIdentifier() == null || df.getIdentifier().isEmpty()) || // identifier exists, or
canCreatePidsForFiles) // we can create PIDs for files
) {
doiRetString = pidProvider.publicizeIdentifier(df);
doiRetString = pidProvider.updateIdentifier(df);
if (doiRetString) {
df.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
ctxt.em().merge(df);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,10 @@ public JsonObject getProviderSpecification() {
providerSpecification.add("excludedSet", Strings.join(",", excludedSet.toArray()));
return providerSpecification.build();
}

@Override
public boolean updateIdentifier(DvObject dvObject) {
//By default, these are the same
return publicizeIdentifier(dvObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface PidProvider {

boolean publicizeIdentifier(DvObject studyIn);

boolean updateIdentifier(DvObject dvObject);

boolean isGlobalIdUnique(GlobalId globalId);

String getUrlPrefix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
import edu.harvard.iq.dataverse.pidproviders.AbstractPidProvider;
import edu.harvard.iq.dataverse.pidproviders.doi.XmlMetadataTemplate;

import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.builder.Input.Builder;
import org.xmlunit.diff.Diff;
import org.xmlunit.diff.Difference;

/**
*
* @author luopc
Expand Down Expand Up @@ -69,6 +75,35 @@ public String registerIdentifier(String identifier, Map<String, String> metadata

return retString;
}


public String reRegisterIdentifier(String identifier, Map<String, String> metadata, DvObject dvObject) throws IOException {
String retString = "";
String numericIdentifier = identifier.substring(identifier.indexOf(":") + 1);
String xmlMetadata = getMetadataFromDvObject(identifier, metadata, dvObject);
String target = metadata.get("_target");
String currentMetadata = client.getMetadata(numericIdentifier);
Diff myDiff = DiffBuilder.compare(xmlMetadata)
.withTest(currentMetadata).ignoreWhitespace().checkForSimilar()
.build();

if (myDiff.hasDifferences()) {
for(Difference d : myDiff.getDifferences()) {

logger.fine(d.toString());
}
retString = "metadata:\\r" + client.postMetadata(xmlMetadata) + "\\r";
}
if (!target.equals(client.getUrl(numericIdentifier))) {
logger.info("Updating target URL to " + target);
client.postUrl(numericIdentifier, target);
retString = retString + "url:\\r" + target;

}

return retString;
}


public String deactivateIdentifier(String identifier, Map<String, String> metadata, DvObject dvObject) throws IOException {
String retString = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,31 @@ String getPidStatus(DvObject dvObject) {
return status;
}



@Override
public boolean updateIdentifier(DvObject dvObject) {
logger.log(Level.FINE,"updateIdentifierStatus");
if(dvObject.getIdentifier() == null || dvObject.getIdentifier().isEmpty() ){
dvObject = generatePid(dvObject);
}
String identifier = getIdentifier(dvObject);
Map<String, String> metadata = getUpdateMetadata(dvObject);
metadata.put("_status", "public");
metadata.put("datacite.publicationyear", generateYear(dvObject));
metadata.put("_target", getTargetUrl(dvObject));
try {
String updated = doiDataCiteRegisterService.reRegisterIdentifier(identifier, metadata, dvObject);
if(updated.length()!=0) {
logger.info(identifier + "updated: " + updated );
return true;
} else {
logger.info("No updated needed for " + identifier);
return false; //No update needed
}
} catch (Exception e) {
logger.log(Level.WARNING, "updateIdentifier failed: " + e.getMessage(), e);
return false;
}
}

}
Loading