Skip to content

Commit

Permalink
Merge branch 'develop' into fdias-2509-notification-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
diasf authored Sep 20, 2024
2 parents 8a9b1ad + 3c65c14 commit da7b9ef
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import edu.harvard.iq.dataverse.globalid.DOIDataCiteServiceBean;
import edu.harvard.iq.dataverse.globalid.DOIEZIdServiceBean;
import edu.harvard.iq.dataverse.globalid.FakePidProviderServiceBean;
import edu.harvard.iq.dataverse.globalid.GlobalIdServiceBeanResolver;
import edu.harvard.iq.dataverse.globalid.HandlenetServiceBean;
import edu.harvard.iq.dataverse.guestbook.GuestbookResponseServiceBean;
import edu.harvard.iq.dataverse.guestbook.GuestbookServiceBean;
Expand Down Expand Up @@ -210,6 +211,8 @@ public class EjbDataverseEngine {
@Inject
DatasetFieldValidationService fieldValidationService;

@Inject
GlobalIdServiceBeanResolver globalIdServiceBeanResolver;

@Resource
EJBContext ejbCtxt;
Expand Down Expand Up @@ -552,6 +555,11 @@ public DownloadDatasetLogDao downloadDatasetDao() {
public DatasetFieldValidationService fieldValidationService() {
return fieldValidationService;
}

@Override
public GlobalIdServiceBeanResolver globalIdServiceBeanResolver() {
return globalIdServiceBeanResolver;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.harvard.iq.dataverse.api.dto.DatasetDTO;
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
import edu.harvard.iq.dataverse.engine.command.impl.CreateHarvestedDatasetCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DestroyDatasetCommand;
import edu.harvard.iq.dataverse.persistence.datafile.DataFile;
import edu.harvard.iq.dataverse.persistence.dataset.Dataset;
Expand Down Expand Up @@ -112,6 +113,30 @@ public Dataset doImportHarvestedDataset(DataverseRequest dataverseRequest, Harve
}
}

@TransactionAttribute(REQUIRES_NEW)
public void doDeleteHarvestedDataset(DataverseRequest request, HarvestingClient harvestingClient, String identifier) throws ImportException {
Dataset dataset = datasetDao.getDatasetByHarvestInfo(harvestingClient.getDataverse(), identifier);
if (dataset != null) {
// Purge all the SOLR documents associated with this client from the
// index server:
indexService.deleteHarvestedDocuments(dataset);

// files from harvested datasets are removed unceremoniously,
// directly in the database. no need to bother calling the
// DeleteFileCommand on them.
for (DataFile harvestedFile : dataset.getFiles()) {
DataFile merged = em.merge(harvestedFile);
em.remove(merged);
}

dataset.setFiles(null);
Dataset merged = em.merge(dataset);
engineSvc.submit(new DeleteDatasetCommand(request, merged));
} else {
throw new ImportException("No dataset found for " + identifier + ", skipping delete. ");
}
}

private Dataset importDatasetDTOJson(DataverseRequest dataverseRequest, HarvestingClient harvestingClient, String harvestIdentifier, String json) throws ImportException {
try {
Dataset ds = harvestedJsonParser.parseDataset(json);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package edu.harvard.iq.dataverse.dataset.deaccession;

import edu.harvard.iq.dataverse.DataverseRequestServiceBean;
import edu.harvard.iq.dataverse.EjbDataverseEngine;
import edu.harvard.iq.dataverse.annotations.PermissionNeeded;
import edu.harvard.iq.dataverse.annotations.processors.permissions.extractors.DatasetFromVersion;
import edu.harvard.iq.dataverse.globalid.GlobalIdServiceBeanResolver;
import edu.harvard.iq.dataverse.interceptors.LoggedCall;
import edu.harvard.iq.dataverse.interceptors.Restricted;
import edu.harvard.iq.dataverse.persistence.DvObject;
import edu.harvard.iq.dataverse.persistence.dataset.Dataset;
import edu.harvard.iq.dataverse.persistence.dataset.DatasetVersion;
import edu.harvard.iq.dataverse.persistence.user.Permission;
import edu.harvard.iq.dataverse.search.index.IndexServiceBean;
import io.vavr.control.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.Stateless;
import javax.inject.Inject;
Expand All @@ -20,12 +27,23 @@
@Stateless
public class DatasetDeaccessionService {

private static final Logger log = LoggerFactory.getLogger(DatasetDeaccessionService.class);

@PersistenceContext
private EntityManager em;

@Inject
private IndexServiceBean indexService;

@Inject
private EjbDataverseEngine commandEngine;

@Inject
private DataverseRequestServiceBean dvRequestService;

@Inject
private GlobalIdServiceBeanResolver globalIdServiceBeanResolver;

// -------------------- LOGIC --------------------

@LoggedCall
Expand All @@ -51,17 +69,34 @@ public List<DatasetVersion> deaccessReleasedVersions(

// -------------------- PRIVATE --------------------

private DatasetVersion deaccessDatasetVersion(DatasetVersion deaccessionVersion,
String deaccessionReason, String deaccessionForwardURLFor) {
deaccessionVersion.setVersionNote(deaccessionReason);
deaccessionVersion.setArchiveNote(deaccessionForwardURLFor);
deaccessionVersion.setVersionState(DatasetVersion.VersionState.DEACCESSIONED);
deaccessionVersion.setLastUpdateTime(new Date());
DatasetVersion merged = em.merge(deaccessionVersion);
private DatasetVersion deaccessDatasetVersion(DatasetVersion version, String deaccessionReason, String deaccessionForwardURLFor) {
version.setVersionNote(deaccessionReason);
version.setArchiveNote(deaccessionForwardURLFor);
version.setVersionState(DatasetVersion.VersionState.DEACCESSIONED);
version.setLastUpdateTime(new Date());
DatasetVersion merged = em.merge(version);

Dataset dataset = merged.getDataset();
indexService.indexDataset(dataset, true);
em.merge(dataset);

dataset.getFiles().stream()
.filter(df -> df.getFileMetadatas().stream()
.allMatch(fm -> fm.getDatasetVersion().isDeaccessioned()))
.forEach(this::unregisterGlobalId);

if (dataset.isDeaccessioned()) {
unregisterGlobalId(dataset);
}

return merged;
}

private void unregisterGlobalId(DvObject object) {
if (object.isIdentifierRegistered()) {
Option.of(globalIdServiceBeanResolver.resolve(object.getProtocol())).toTry()
.andThenTry(service -> service.deleteIdentifier(object))
.onFailure(e -> log.warn("Failed to unregister identifier {}", object.getGlobalId(), e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import edu.harvard.iq.dataverse.globalid.DOIDataCiteServiceBean;
import edu.harvard.iq.dataverse.globalid.DOIEZIdServiceBean;
import edu.harvard.iq.dataverse.globalid.FakePidProviderServiceBean;
import edu.harvard.iq.dataverse.globalid.GlobalIdServiceBeanResolver;
import edu.harvard.iq.dataverse.globalid.HandlenetServiceBean;
import edu.harvard.iq.dataverse.guestbook.GuestbookResponseServiceBean;
import edu.harvard.iq.dataverse.guestbook.GuestbookServiceBean;
Expand Down Expand Up @@ -154,4 +155,6 @@ public interface CommandContext {
DownloadDatasetLogDao downloadDatasetDao();

DatasetFieldValidationService fieldValidationService();

GlobalIdServiceBeanResolver globalIdServiceBeanResolver();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ public String reserveIdentifier(String identifier, Map<String, String> metadata,

public void registerIdentifier(String identifier, Map<String, String> metadata, DvObject dvObject) throws IOException {
String xmlMetadata = getMetadataFromDvObject(identifier, metadata, dvObject);
DOIDataCiteRegisterCache rc = findByDOI(identifier);
DOIDataCiteRegisterCache rc = Optional.ofNullable(findByDOI(identifier))
.orElseGet(DOIDataCiteRegisterCache::new);
String target = metadata.get("_target");
if (rc != null) {
rc.setDoi(identifier);
rc.setXml(xmlMetadata);
rc.setStatus("public");
if (target == null || target.trim().length() == 0) {
target = rc.getUrl();
} else {
rc.setUrl(target);
}
rc.setDoi(identifier);
rc.setXml(xmlMetadata);
rc.setStatus("public");
if (target == null || target.trim().length() == 0) {
target = rc.getUrl();
} else {
rc.setUrl(target);
}
em.merge(rc);
registerDOI(identifier.split(":")[1], target, xmlMetadata);
}

Expand All @@ -121,6 +121,7 @@ public String getMetadataForDeactivateId(String identifier) {
resource.setTitles(Collections.singletonList("This item has been removed from publication"));
resource.setPublisher(":unav");
resource.setPublicationYear("9999");
resource.setCreators(Collections.singletonList(new DataCiteResource.Creator(":unav")));
return convertToXml(resource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
import edu.harvard.iq.dataverse.persistence.GlobalId;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;

import static edu.harvard.iq.dataverse.globalid.GlobalIdServiceBean.logger;

public interface GlobalIdServiceBean {

Logger logger = Logger.getLogger(GlobalIdServiceBean.class.getCanonicalName());
Expand Down Expand Up @@ -56,45 +51,19 @@ public interface GlobalIdServiceBean {

boolean publicizeIdentifier(DvObject studyIn);

/**
* @deprecated use {@link GlobalIdServiceBeanResolver} instead
*/
@Deprecated
static GlobalIdServiceBean getBean(String protocol, CommandContext ctxt) {
final Function<CommandContext, GlobalIdServiceBean> protocolHandler = BeanDispatcher.DISPATCHER.get(protocol);
if (protocolHandler != null) {
return protocolHandler.apply(ctxt);
} else {
logger.log(Level.SEVERE, "Unknown protocol: {0}", protocol);
return null;
}
return ctxt.globalIdServiceBeanResolver().resolve(protocol);
}

/**
* @deprecated use {@link GlobalIdServiceBeanResolver} instead
*/
static GlobalIdServiceBean getBean(CommandContext ctxt) {
return getBean(ctxt.settings().getValueForKey(Key.Protocol), ctxt);
}

}

/**
* Static utility class for dispatching implementing beans, based on protocol and providers.
*
* @author michael
*/
class BeanDispatcher {
static final Map<String, Function<CommandContext, GlobalIdServiceBean>> DISPATCHER = new HashMap<>();

static {
DISPATCHER.put("hdl", ctxt -> ctxt.handleNet());
DISPATCHER.put("doi", ctxt -> {
String doiProvider = ctxt.settings().getValueForKey(Key.DoiProvider);
switch (doiProvider) {
case "EZID":
return ctxt.doiEZId();
case "DataCite":
return ctxt.doiDataCite();
case "FAKE":
return ctxt.fakePidProvider();
default:
logger.log(Level.SEVERE, "Unknown doiProvider: {0}", doiProvider);
return null;
}
});
}
}
Loading

0 comments on commit da7b9ef

Please sign in to comment.