use of edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry in project dataverse by IQSS.
the class FileDownloadServiceBean method writeGuestbookResponseRecord.
public void writeGuestbookResponseRecord(GuestbookResponse guestbookResponse) {
try {
CreateGuestbookResponseCommand cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), guestbookResponse, guestbookResponse.getDataset());
commandEngine.submit(cmd);
DatasetVersion version = guestbookResponse.getDatasetVersion();
// Sometimes guestbookResponse doesn't have a version, so we grab the released version
if (null == version) {
version = guestbookResponse.getDataset().getReleasedVersion();
}
MakeDataCountEntry entry = new MakeDataCountEntry(FacesContext.getCurrentInstance(), dvRequestService, version, guestbookResponse.getDataFile());
// As the api download url is not available at this point we construct it manually
entry.setTargetUrl("/api/access/datafile/" + guestbookResponse.getDataFile().getId());
entry.setRequestUrl("/api/access/datafile/" + guestbookResponse.getDataFile().getId());
mdcLogService.logEntry(entry);
} catch (CommandException e) {
// if an error occurs here then download won't happen no need for response recs...
logger.warning("Exception writing GuestbookResponse for file: " + guestbookResponse.getDataFile().getId() + " : " + e.getLocalizedMessage());
}
}
use of edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry in project dataverse by IQSS.
the class FilePage method init.
public String init() {
if (fileId != null || persistentId != null) {
// ---------------------------------------
if (fileId != null) {
file = datafileService.find(fileId);
} else if (persistentId != null) {
file = datafileService.findByGlobalId(persistentId);
if (file != null) {
fileId = file.getId();
}
}
if (file == null || fileId == null) {
return permissionsWrapper.notFound();
}
// Is the Dataset harvested?
if (file.getOwner().isHarvested()) {
// if so, we'll simply forward to the remote URL for the original
// source of this harvested dataset:
String originalSourceURL = file.getOwner().getRemoteArchiveURL();
if (originalSourceURL != null && !originalSourceURL.equals("")) {
logger.fine("redirecting to " + originalSourceURL);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(originalSourceURL);
} catch (IOException ioex) {
// must be a bad URL...
// we don't need to do anything special here - we'll redirect
// to the local 404 page, below.
logger.warning("failed to issue a redirect to " + originalSourceURL);
}
}
return permissionsWrapper.notFound();
}
RetrieveDatasetVersionResponse retrieveDatasetVersionResponse;
Long getDatasetVersionID = null;
if (datasetVersionId == null) {
retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(file.getOwner().getVersions(), version);
getDatasetVersionID = retrieveDatasetVersionResponse.getDatasetVersion().getId();
} else {
getDatasetVersionID = datasetVersionId;
}
fileMetadata = datafileService.findFileMetadataByDatasetVersionIdAndDataFileId(getDatasetVersionID, fileId);
if (fileMetadata == null) {
logger.fine("fileMetadata is null! Checking finding most recent version file was in.");
fileMetadata = datafileService.findMostRecentVersionFileIsIn(file);
if (fileMetadata == null) {
return permissionsWrapper.notFound();
}
}
// If this DatasetVersion is unpublished and permission is doesn't have permissions:
// > Go to the Login page
//
// Check permisisons
Boolean authorized = (fileMetadata.getDatasetVersion().isReleased()) || (!fileMetadata.getDatasetVersion().isReleased() && this.canViewUnpublishedDataset());
if (!authorized) {
return permissionsWrapper.notAuthorized();
}
// termsOfAccess = fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().getTermsOfAccess();
// fileAccessRequest = fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().isFileAccessRequest();
this.guestbookResponse = this.guestbookResponseService.initGuestbookResponseForFragment(fileMetadata, session);
if (fileMetadata.getDatasetVersion().isPublished()) {
MakeDataCountEntry entry = new MakeDataCountEntry(FacesContext.getCurrentInstance(), dvRequestService, fileMetadata.getDatasetVersion());
mdcLogService.logEntry(entry);
}
// Find external tools based on their type, the file content type, and whether
// ingest has created a derived file for that type
// Currently, tabular data files are the only type of derived file created, so
// isTabularData() works - true for tabular types where a .tab file has been
// created and false for other mimetypes
String contentType = file.getContentType();
// For tabular data, indicate successful ingest by returning a contentType for the derived .tab file
if (file.isTabularData()) {
contentType = DataFileServiceBean.MIME_TYPE_TSV_ALT;
}
configureTools = externalToolService.findFileToolsByTypeAndContentType(ExternalTool.Type.CONFIGURE, contentType);
exploreTools = externalToolService.findFileToolsByTypeAndContentType(ExternalTool.Type.EXPLORE, contentType);
Collections.sort(exploreTools, CompareExternalToolName);
toolsWithPreviews = sortExternalTools();
if (!toolsWithPreviews.isEmpty()) {
setSelectedTool(toolsWithPreviews.get(0));
}
} else {
return permissionsWrapper.notFound();
}
return null;
}
Aggregations