Skip to content

Commit

Permalink
feat(collections): add business logic to determine dataset version pi…
Browse files Browse the repository at this point in the history
…d conduct IQSS#4499

This commit adds a public method DataverseServiceBean.wantsDatasetVersionPids()
that will determine how to deal with a dataset version (which belongs to a dataset
that lives within a collection) in terms of "should a PID be registered/updated?".

The background is: when a dataset is published, there will be the context of the
owning Dataverse collection. It's important to take into account the configured
conduct for the collection in the decision how to go ahead with a version's PID.
  • Loading branch information
poikilotherm committed Mar 22, 2023
1 parent 3cb82b4 commit b4644a0
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DataverseServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import edu.harvard.iq.dataverse.batch.util.LoggingUtil;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
import edu.harvard.iq.dataverse.pidproviders.VersionPidMode;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.search.SolrIndexServiceBean;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.util.StringUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.io.File;
Expand All @@ -30,7 +32,6 @@
import java.util.Map;
import java.util.logging.Logger;
import java.util.Properties;
import java.util.concurrent.Future;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
Expand Down Expand Up @@ -927,6 +928,41 @@ public List<Object[]> getDatasetTitlesWithinDataverse(Long dataverseId) {

return em.createNativeQuery(cqString).getResultList();
}


/**
* Check if a given Dataverse Collection has been configured to generate PIDs for any new version of a dataset
* contained in it.
* @param dataverse The collection to analyse
* @return true if enabled, false if disabled
* @throws java.util.NoSuchElementException When no or invalid configuration for version PID mode is given
*/
public boolean wantsDatasetVersionPids(Dataverse collection) {
VersionPidMode vpm = JvmSettings.PID_VERSIONS_MODE.lookup(VersionPidMode.class);

if (vpm.equals(VersionPidMode.GLOBAL)) {
return true;
} else if (vpm.equals(VersionPidMode.OFF)) {
return false;
}
// now mode = collection's choice - ask the collection and if necessary all ancestors what to do
return askForVersionPidConduct(collection);
}

/**
* Recursively scan all ancestors if someone defines a proper conduct for version PIDs.
* @param collection The collection to ask for advice
* @return true if someone in the hierarchy has state "ACTIVE", false otherwise
*/
private boolean askForVersionPidConduct(Dataverse collection) {
// Null safety here also matched the case where even root doesn't know, defaulting to save cycles.
if (collection == null) {
return false;
}
switch (collection.getDatasetVersionPidConduct()) {
case SKIP: return false;
case ACTIVE: return true;
case INHERIT: return askForVersionPidConduct(collection.getOwner());
}
return false;
}
}

0 comments on commit b4644a0

Please sign in to comment.