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

Closes #2479: Allow dataset download in read-only mode #2487

Merged
merged 2 commits into from
May 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public void setDatasetId(Long datasetId) {
public void setDownloadDate(Date downloadDate) {
this.downloadDate = downloadDate;
}

@Override
public String toString() {
return "DownloadDatasetLog [id=" + id + ", datasetId=" + datasetId + ", downloadDate=" + downloadDate + ']';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ public DownloadInstance tabularDatafileMetadataPreprocessed(@PathParam("fileId")
@Path("datafiles/{fileIds}")
@GET
@Produces({"application/zip"})
@ApiWriteOperation
public Response datafiles(@PathParam("fileIds") String fileIds, @QueryParam("gbrecs") Boolean gbrecs,
@Context UriInfo uriInfo, @Context HttpServletResponse response) throws WebApplicationException {
assertOrThrowBadRequest(() -> StringUtils.isNotBlank(fileIds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ public Response listVersionFiles(@PathParam("id") String datasetId, @PathParam("
@GET
@Path("{id}/versions/{versionId}/files/download")
@Produces({"application/zip"})
@ApiWriteOperation
public Response getVersionFiles(@PathParam("id") String datasetId, @PathParam("versionId") String versionId, @QueryParam("gbrecs") boolean gbrecs,
@Context HttpServletResponse response, @Context UriInfo uriInfo) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package edu.harvard.iq.dataverse.dataset;

import edu.harvard.iq.dataverse.persistence.dataset.DownloadDatasetLog;
import edu.harvard.iq.dataverse.util.SystemConfig;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Date;
import java.util.logging.Logger;

@Stateless
public class DownloadDatasetLogService {

private static final Logger logger = Logger.getLogger(DownloadDatasetLogService.class.getCanonicalName());

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

@EJB
protected SystemConfig systemConfig;

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

/**
Expand All @@ -22,6 +30,10 @@ public void logWholeSetDownload(Long datasetId) {
DownloadDatasetLog downloadDatasetLog = new DownloadDatasetLog();
downloadDatasetLog.setDatasetId(datasetId);
downloadDatasetLog.setDownloadDate(new Date());
em.persist(downloadDatasetLog);
if (systemConfig.isReadonlyMode()) {
logger.info(downloadDatasetLog.toString());
} else {
em.persist(downloadDatasetLog);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ public CreateGuestbookResponseCommand(DataverseRequest aRequest, GuestbookRespon
protected void executeImpl(CommandContext ctxt) {
Timestamp createDate = new Timestamp(new Date().getTime());
response.setResponseTime(createDate);

if (ctxt.systemConfig().isReadonlyMode()) {
log.info(response.toString());
} else {
ctxt.responses().save(response);
}

ctxt.responses().save(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import edu.harvard.iq.dataverse.persistence.user.AuthenticatedUser;
import edu.harvard.iq.dataverse.persistence.user.GuestUser;
import edu.harvard.iq.dataverse.persistence.user.User;
import edu.harvard.iq.dataverse.util.SystemConfig;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
Expand Down Expand Up @@ -93,6 +95,9 @@ public class GuestbookResponseServiceBean {
@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

@EJB
protected SystemConfig systemConfig;

public List<GuestbookResponse> findAll() {
return em.createQuery("select object(o) from GuestbookResponse as o order by o.responseTime desc", GuestbookResponse.class).getResultList();
}
Expand Down Expand Up @@ -701,7 +706,11 @@ public GuestbookResponse findById(Long id) {

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void save(GuestbookResponse guestbookResponse) {
em.persist(guestbookResponse);
if (systemConfig.isReadonlyMode()) {
logger.info(guestbookResponse.toString());
} else {
em.persist(guestbookResponse);
}
}


Expand Down
Loading