use of edu.harvard.iq.dataverse.datasetutility.FileReplacePageHelper in project dataverse by IQSS.
the class EditDatafilesPage method init.
public String init() {
fileMetadatas = new ArrayList<>();
newFiles = new ArrayList<>();
uploadedFiles = new ArrayList<>();
this.maxFileUploadSizeInBytes = systemConfig.getMaxFileUploadSize();
this.multipleUploadFilesLimit = systemConfig.getMultipleUploadFilesLimit();
if (dataset.getId() != null) {
// Set Working Version and Dataset by Datasaet Id and Version
// retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionById(dataset.getId(), null);
dataset = datasetService.find(dataset.getId());
// files!)
if (dataset == null || dataset.isHarvested()) {
return permissionsWrapper.notFound();
}
} else {
// that the dataset id is mandatory... But 404 will do for now.
return permissionsWrapper.notFound();
}
workingVersion = dataset.getEditVersion();
if (workingVersion == null || !workingVersion.isDraft()) {
// Sorry, we couldn't find/obtain a draft version for this dataset!
return permissionsWrapper.notFound();
}
if (!permissionService.on(dataset).has(Permission.EditDataset)) {
return permissionsWrapper.notAuthorized();
}
// -------------------------------------------
if (mode == FileEditMode.SINGLE_REPLACE) {
/*
http://localhost:8080/editdatafiles.xhtml?mode=SINGLE_REPLACE&datasetId=26&fid=726
*/
DataFile fileToReplace = loadFileToReplace();
if (fileToReplace == null) {
return permissionsWrapper.notFound();
}
// DataverseRequest dvRequest2 = createDataverseRequest(authUser);
AddReplaceFileHelper addReplaceFileHelper = new AddReplaceFileHelper(dvRequestService.getDataverseRequest(), ingestService, datasetService, datafileService, permissionService, commandEngine, systemConfig);
fileReplacePageHelper = new FileReplacePageHelper(addReplaceFileHelper, dataset, fileToReplace);
populateFileMetadatas();
singleFile = getFileToReplace();
} else if (mode == FileEditMode.EDIT || mode == FileEditMode.SINGLE) {
if (selectedFileIdsString != null) {
String[] ids = selectedFileIdsString.split(",");
for (String id : ids) {
Long test = null;
try {
test = new Long(id);
} catch (NumberFormatException nfe) {
// do nothing...
test = null;
}
if (test != null) {
if (mode == FileEditMode.SINGLE) {
singleFile = datafileService.find(test);
}
selectedFileIdsList.add(test);
}
}
}
if (selectedFileIdsList.size() < 1) {
logger.fine("No numeric file ids supplied to the page, in the edit mode. Redirecting to the 404 page.");
// If no valid file IDs specified, send them to the 404 page...
return permissionsWrapper.notFound();
}
logger.fine("The page is called with " + selectedFileIdsList.size() + " file ids.");
populateFileMetadatas();
// datafiles are not present in the version specified, etc.
if (fileMetadatas.size() < 1) {
return permissionsWrapper.notFound();
}
if (FileEditMode.SINGLE == mode) {
if (fileMetadatas.get(0).getDatasetVersion().getId() != null) {
versionString = "DRAFT";
}
}
}
saveEnabled = true;
if (mode == FileEditMode.UPLOAD) {
JH.addMessage(FacesMessage.SEVERITY_INFO, getBundleString("dataset.message.uploadFiles"));
}
if (settingsService.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false)) {
JH.addMessage(FacesMessage.SEVERITY_WARN, getBundleString("dataset.message.publicInstall"));
}
return null;
}
Aggregations