Skip to content

Commit

Permalink
Merge branch 'develop' into openaire IQSS#4257 IQSS#3697
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed May 30, 2018
2 parents a51743b + e600c29 commit 272290c
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 257 deletions.
6 changes: 5 additions & 1 deletion src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,15 @@ dataset.message.locked.editNotAllowedInReview=Dataset cannot be edited due to In
dataset.message.locked.downloadNotAllowedInReview=Dataset file(s) may not be downloaded due to In Review dataset lock.
dataset.message.locked.downloadNotAllowed=Dataset file(s) may not be downloaded due to dataset lock.
dataset.message.locked.editNotAllowed=Dataset cannot be edited due to dataset lock.
dataset.message.createSuccess=This dataset has been created.
dataset.message.createSuccess=This dataset has been created
dataset.message.createSuccess.failedToSaveFiles=Partial Success: The dataset has been created. But the file(s) could not be saved. Please try uploading the file(s) again.
dataset.message.createSuccess.partialSuccessSavingFiles=Partial Success: The dataset has been created. But only {0} out of {1} files have been saved. Please try uploading the missing file(s) again.
dataset.message.linkSuccess= {0} has been successfully linked to {1}.
dataset.message.metadataSuccess=The metadata for this dataset has been updated.
dataset.message.termsSuccess=The terms for this dataset has been updated.
dataset.message.filesSuccess=The files for this dataset have been updated.
dataset.message.addFiles.Failure=Failed to add files to the dataset. Please try uploading the file(s) again.
dataset.message.addFiles.partialSuccess=Partial success: only {0} files out of {1} have been saved. Please try uploading the missing file(s) again.
dataset.message.publishSuccess=This dataset has been published.
dataset.message.only.authenticatedUsers=Only authenticated users may release Datasets.
dataset.message.deleteSuccess=This dataset has been deleted.
Expand Down
42 changes: 37 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2549,10 +2549,10 @@ public String save() {
return "";
}

// Use the API to save the dataset:
// Use the Create or Update command to save the dataset:
Command<Dataset> cmd;
try {
if (editMode == EditMode.CREATE) {
if (editMode == EditMode.CREATE) {
if ( selectedTemplate != null ) {
if ( isSessionUserAuthenticated() ) {
cmd = new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), false, null, selectedTemplate);
Expand Down Expand Up @@ -2595,10 +2595,42 @@ public String save() {
return returnToDraftVersion();
}

newFiles.clear();
if (editMode != null) {
if (editMode.equals(EditMode.CREATE)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.createSuccess"));
// We allow users to upload files on Create:
int nNewFiles = newFiles.size();
logger.fine("NEW FILES: "+nNewFiles);

if (nNewFiles > 0) {
// Save the NEW files permanently and add the to the dataset:

List<DataFile> filesAdded = ingestService.saveAndAddFilesToDataset(dataset.getEditVersion(), newFiles);
newFiles.clear();

// and another update command:
boolean addFilesSuccess = false;
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), new ArrayList<FileMetadata>());
try {
dataset = commandEngine.submit(cmd);
addFilesSuccess = true;
} catch (Exception ex) {
addFilesSuccess = false;
}
if (addFilesSuccess && dataset.getFiles().size() > 0) {
if (nNewFiles == dataset.getFiles().size()) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.createSuccess"));
} else {
String partialSuccessMessage = JH.localize("dataset.message.createSuccess.partialSuccessSavingFiles");
partialSuccessMessage = partialSuccessMessage.replace("{0}", "" + dataset.getFiles().size() + "");
partialSuccessMessage = partialSuccessMessage.replace("{1}", "" + nNewFiles + "");
JsfHelper.addWarningMessage(partialSuccessMessage);
}
} else {
JsfHelper.addWarningMessage(JH.localize("dataset.message.createSuccess.failedToSaveFiles"));
}
} else {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.createSuccess"));
}
}
if (editMode.equals(EditMode.METADATA)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.metadataSuccess"));
Expand Down Expand Up @@ -2631,7 +2663,7 @@ public String save() {
//After dataset saved, then persist prov json data
if(systemConfig.isProvCollectionEnabled()) {
try {
provPopupFragmentBean.saveStagedProvJson(false);
provPopupFragmentBean.saveStagedProvJson(false, dataset.getLatestVersion().getFileMetadatas());
} catch (AbstractApiBean.WrappedResponse ex) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("file.metadataTab.provenance.error"));
Logger.getLogger(DatasetPage.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
131 changes: 77 additions & 54 deletions src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public List<FileMetadata> getFileMetadatas() {
if (fileReplacePageHelper.wasPhase1Successful()){
logger.fine("Replace: File metadatas 'list' of 1 from the fileReplacePageHelper.");
return fileReplacePageHelper.getNewFileMetadatasBeforeSave();
}else{
} else {
logger.fine("Replace: replacement file not yet uploaded.");
return null;
}
Expand Down Expand Up @@ -1091,8 +1091,22 @@ public String save() {
}


// Save the NEW files permanently:
ingestService.finalizeFiles(workingVersion, newFiles);
int nOldFiles = workingVersion.getFileMetadatas().size();
int nNewFiles = newFiles.size();
int nExpectedFilesTotal = nOldFiles + nNewFiles;

if (nNewFiles > 0) {
// Try to save the NEW files permanently:
List<DataFile> filesAdded = ingestService.saveAndAddFilesToDataset(workingVersion, newFiles);

// reset the working list of fileMetadatas, as to only include the ones
// that have been added to the version successfully:
fileMetadatas.clear();
for (DataFile addedFile : filesAdded) {
fileMetadatas.add(addedFile.getFileMetadata());
}
filesAdded = null;
}
//boolean newDraftVersion = false;

Boolean provJsonChanges = false;
Expand All @@ -1101,7 +1115,16 @@ public String save() {
Boolean provFreeChanges = provPopupFragmentBean.updatePageMetadatasWithProvFreeform(fileMetadatas);

try {
provJsonChanges = provPopupFragmentBean.saveStagedProvJson(false);
// Note that the user may have uploaded provenance metadata file(s)
// for some of the new files that have since failed to be permanently saved
// in storage (in the ingestService.saveAndAddFilesToDataset() step, above);
// these files have been dropped from the fileMetadatas list, and we
// are not adding them to the dataset; but the
// provenance update set still has entries for these failed files,
// so we are passing the fileMetadatas list to the saveStagedProvJson()
// method below - so that it doesn't attempt to save the entries
// that are no longer valid.
provJsonChanges = provPopupFragmentBean.saveStagedProvJson(false, fileMetadatas);
} catch (AbstractApiBean.WrappedResponse ex) {
JsfHelper.addErrorMessage(getBundleString("file.metadataTab.provenance.error"));
Logger.getLogger(EditDatafilesPage.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -1111,7 +1134,7 @@ public String save() {
//This was the simplest way to work around this issue for prov. --MAD 4.8.6.
datasetUpdateRequired = datasetUpdateRequired || provFreeChanges || provJsonChanges;
}

if (workingVersion.getId() == null || datasetUpdateRequired) {
logger.fine("issuing the dataset update command");
// We are creating a new draft version;
Expand Down Expand Up @@ -1155,6 +1178,8 @@ public String save() {
// similarly to what we've just done, above, for the filemetadatas.
// Otherwise, when we call UpdateDatasetCommand, it's not going
// to update the tags in the database (issue #2798).
// TODO: Is the above still true/is this still necessary?
// (and why?...)

if (tabularDataTagsUpdated) {
for (int i = 0; i < dataset.getFiles().size(); i++) {
Expand All @@ -1169,8 +1194,7 @@ public String save() {
tabularDataTagsUpdated = false;
}
}



Command<Dataset> cmd;
try {
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
Expand All @@ -1191,8 +1215,8 @@ public String save() {
populateDatasetUpdateFailureMessage();
return null;
} catch (CommandException ex) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
logger.severe(ex.getMessage());
//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
logger.log(Level.INFO, "Couldn''t save dataset: {0}", ex.getMessage());
populateDatasetUpdateFailureMessage();
return null;
}
Expand Down Expand Up @@ -1284,6 +1308,7 @@ public String save() {
}
}


if (newFiles.size() > 0) {
logger.fine("clearing newfiles list.");
newFiles.clear();
Expand All @@ -1304,7 +1329,17 @@ public String save() {
JsfHelper.addSuccessMessage(getBundleString("file.message.editSuccess"));

} else {
JsfHelper.addSuccessMessage(getBundleString("dataset.message.filesSuccess"));
int nFilesTotal = workingVersion.getFileMetadatas().size();
if (nNewFiles == 0 || nFilesTotal == nExpectedFilesTotal) {
JsfHelper.addSuccessMessage(getBundleString("dataset.message.filesSuccess"));
} else if (nFilesTotal == nOldFiles) {
JsfHelper.addErrorMessage(getBundleString("dataset.message.addFiles.Failure"));
} else {
String warningMessage = getBundleString("dataset.message.addFiles.partialSuccess");
warningMessage = warningMessage.replace("{0}", "" + (nFilesTotal - nOldFiles));
warningMessage = warningMessage.replace("{1}", "" + nNewFiles);
JsfHelper.addWarningMessage(warningMessage);
}
}


Expand Down Expand Up @@ -1664,10 +1699,6 @@ public void uploadFinished() {
// Add the file(s) added during this last upload event, single or multiple,
// to the full list of new files, and the list of filemetadatas
// used to render the page:

if (mode == FileEditMode.CREATE) {
ingestService.addFilesToDataset(workingVersion, uploadedFiles);
}

for (DataFile dataFile : uploadedFiles) {
fileMetadatas.add(dataFile.getFileMetadata());
Expand Down Expand Up @@ -2298,7 +2329,6 @@ public boolean isThumbnailIsFromDatasetLogoRatherThanDatafile() {

public void setFileMetadataSelectedForTagsPopup(FileMetadata fm){
fileMetadataSelectedForTagsPopup = fm;
fileMetadataSelectedForTagsPopup.setDatasetVersion(this.getDataset().getLatestVersion());
}

public FileMetadata getFileMetadataSelectedForTagsPopup() {
Expand Down Expand Up @@ -2460,6 +2490,10 @@ public String saveNewCategory() {
* "file categories" (which are also considered "tags" in 4.0)
*/
public void saveFileTagsAndCategories() {
if (fileMetadataSelectedForTagsPopup == null) {
logger.fine("No FileMetadata selected for the categories popup");
return;
}
// 1. File categories:
/*
In order to get the cancel button to work we had to separate the selected tags
Expand All @@ -2468,68 +2502,57 @@ public void saveFileTagsAndCategories() {
*/

fileMetadataSelectedForTagsPopup.setCategories(new ArrayList<>());

// New, custom file category (if specified):
if (newCategoryName != null) {
logger.fine("Adding new category, " + newCategoryName + " for file " + fileMetadataSelectedForTagsPopup.getLabel());
fileMetadataSelectedForTagsPopup.addCategoryByName(newCategoryName);
} else {
logger.fine("no category specified");
}
// 2. Tabular DataFile Tags:
newCategoryName = null;

// File Categories selected from the list of existing categories:
if (selectedTags != null) {
for (String selectedTag : selectedTags) {

fileMetadataSelectedForTagsPopup.addCategoryByName(selectedTag);
}
}


logger.fine("New category name: " + newCategoryName);

if (fileMetadataSelectedForTagsPopup != null && newCategoryName != null) {
logger.fine("Adding new category, for file " + fileMetadataSelectedForTagsPopup.getLabel());
fileMetadataSelectedForTagsPopup.addCategoryByName(newCategoryName);
} else {
logger.fine("No FileMetadata selected, or no category specified!");
}
newCategoryName = null;

}

// 2. Tabular DataFile Tags:

if (fileMetadataSelectedForTagsPopup.getDataFile() != null && tabularDataTagsUpdated && selectedTabFileTags != null) {
fileMetadataSelectedForTagsPopup.getDataFile().setTags(null);
for (String selectedTabFileTag : selectedTabFileTags) {
DataFileTag tag = new DataFileTag();
try {
tag.setTypeByLabel(selectedTabFileTag);
tag.setDataFile(fileMetadataSelectedForTagsPopup.getDataFile());
fileMetadataSelectedForTagsPopup.getDataFile().addTag(tag);

if (tabularDataTagsUpdated && selectedTabFileTags != null) {
if (fileMetadataSelectedForTagsPopup != null && fileMetadataSelectedForTagsPopup.getDataFile() != null) {
fileMetadataSelectedForTagsPopup.getDataFile().setTags(null);
for (String selectedTabFileTag : selectedTabFileTags) {
DataFileTag tag = new DataFileTag();
try {
tag.setTypeByLabel(selectedTabFileTag);
tag.setDataFile(fileMetadataSelectedForTagsPopup.getDataFile());
fileMetadataSelectedForTagsPopup.getDataFile().addTag(tag);

} catch (IllegalArgumentException iax) {
// ignore
}
} catch (IllegalArgumentException iax) {
// ignore
}

datasetUpdateRequired = true;

// success message:
String successMessage = getBundleString("file.assignedTabFileTags.success");
logger.fine(successMessage);
successMessage = successMessage.replace("{0}", fileMetadataSelectedForTagsPopup.getLabel());
JsfHelper.addFlashMessage(successMessage);
}
// reset:
selectedTags = null;

datasetUpdateRequired = true;
}

fileMetadataSelectedForTagsPopup = null;

}

public void handleSelection(final AjaxBehaviorEvent event) {
tabularDataTagsUpdated = true;
public void handleFileCategoriesSelection(final AjaxBehaviorEvent event) {
if (selectedTags != null) {
selectedTags = selectedTags.clone();
}
}

public void handleTabularTagsSelection(final AjaxBehaviorEvent event) {
tabularDataTagsUpdated = true;
}


/*
* Items for the "Advanced (Ingest) Options" popup.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/FileMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public void addCategoryByName(String newCategoryName) {
// just in case:
fileCategory = this.getDatasetVersion().getDataset().getCategoryByName(newCategoryName);
} catch (Exception ex) {
fileCategory = null;
// If we failed to obtain an existing category, we'll create a new one:
fileCategory = new DataFileCategory();
fileCategory.setName(newCategoryName);
}


Expand Down
Loading

0 comments on commit 272290c

Please sign in to comment.