Skip to content

Commit

Permalink
Merge pull request #2995 from IQSS/2391-file-edit-tags
Browse files Browse the repository at this point in the history
2391 Edit File Tags
  • Loading branch information
scolapasta committed Mar 22, 2016
2 parents b39c957 + bf67eef commit 7d6b946
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 109 deletions.
14 changes: 11 additions & 3 deletions doc/sphinx-guides/source/user/dataset-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ We currently only support the following HTML tags for any of our textbox meatdat
<br>, <code>, <del>, <dd>, <dl>, <dt>, <em>, <hr>, <h1>-<h3>, <i>, <img>, <kbd>, <li>, <ol>, <p>, <pre>, <s>, <sup>, <sub>,
<strong>, <strike>, <ul>.

Edit Dataset
Edit Files
==================

Go to the dataset you would like to edit where you will see the listing of files. Select the files you would like to edit by using either the Select All checkbox or individually selecting files. Next, click on the Edit button above the files and select if you would like to:
Expand All @@ -150,10 +150,18 @@ Go to the dataset you would like to edit where you will see the listing of files

All of these actions, besides editing file metadata, will happen within this page and not bring you to another page. If you restrict files, you will also be asked to fill out the Terms of Access for the files. If Terms of Access already exist, you will be asked to confirm them.

File Tags
--------------------------------------------------------------

The File Tags are comprised of custom, category (i.e. Documentation, Data, Code) and tabular data tags (i.e. Event, Genomics, Geospatial, Network, Panel, Survey, Time Series). Use the dropdown select menus as well as the custom file tag input to apply these tags to the selected files. There is also a Delete Tags feature that, if checked, will allow you to delete unused file tags within that dataset.



Upload New Files
===================
---------------------------------------------------------------

To upload new files to a dataset, go to the dataset you want to update and click on the Upload Files button in the files tab. From there you will be brought to the Upload Files page for the dataset. Once you have uploaded files, you will be able to edit the file metadata, restrict, add tags, or delete them before saving.

To upload new files to a dataset, go the dataset you want to update and click on the Upload Files Button in the files tab. From there you will be brought to the Upload page for the dataset. Once you have uploaded files, you will be able to edit the file metadata, restrict, add tags, or delete them before saving.

.. _license-terms:

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ download=Download
deaccession=Deaccession
linked=Linked
harvested=Harvested
apply=Apply
add=Add
delete=Delete
yes=Yes
Expand Down Expand Up @@ -896,10 +897,17 @@ file.metaData.viewOnWorldMap=Explore on WorldMap
file.addDescription=Add file description...
file.tags=Tags
file.editTags=Edit Tags
file.editTagsDialog.tip=Select existing file tags or create new tags to describe your files. Creating a new tag will add it as a tag option for all files in this dataset. Each file can have more than one tag.
file.editTagsDialog.tip=Select existing file tags or create new tags to describe your files. Each file can have more than one tag.
file.editTagsDialog.select=File Tags
file.editTagsDialog.selectedTags=Selected Tags
file.editTagsDialog.selectedTags.none=No tags selected
file.editTagsDialog.add=Custom File Tag
file.editTagsDialog.add.tip=Creating a new tag will add it as a tag option for all files in this dataset.
file.editTagsDialog.newName=Add new file tag...
dataset.removeUnusedFileTags.label=Delete Tags
dataset.removeUnusedFileTags.tip=Select to delete Custom File Tags not used by the files in the dataset.
dataset.removeUnusedFileTags.check=Delete tags not being used

file.setThumbnail=Set Thumbnail
file.setThumbnail.header=Set Dataset Thumbnail
file.datasetThumbnail=Dataset Thumbnail
Expand All @@ -910,8 +918,7 @@ file.advancedIngestOptions=Advanced Ingest Options
file.assignedDataverseImage.success={0} has been saved as the thumbnail for this dataset.
file.assignedTabFileTags.success=The tag(s) were successfully added for {0}.
file.tabularDataTags=Tabular Data Tags
file.tabularDataTags.title=Select a tag to describe the type(s) of data this is (survey, time series, geospatial, etc). This tag is for excel, SPSS, Stata, or R Data files only.
file.tabularDataTags.tip=Data file specific tags for identifying what type(s) of data a file is.
file.tabularDataTags.tip=Select a tag to describe the type(s) of data this is (survey, time series, geospatial, etc).
file.spss-savEncoding=Language Encoding
file.spss-savEncoding.title=Select the language used for encoding this SPSS (sav) Data file.
file.spss-savEncoding.current=Current Selection:
Expand Down
142 changes: 109 additions & 33 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import edu.harvard.iq.dataverse.ingest.IngestRequest;
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.metadataimport.ForeignMetadataImportServiceBean;
import edu.harvard.iq.dataverse.search.FacetCategory;
import edu.harvard.iq.dataverse.search.FileView;
import edu.harvard.iq.dataverse.search.SearchFilesServiceBean;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.search.SortBy;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.BundleUtil;
Expand All @@ -37,9 +34,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
Expand All @@ -62,28 +57,25 @@
import javax.inject.Named;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonArray;
import javax.json.JsonReader;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.primefaces.context.RequestContext;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import javax.faces.model.SelectItem;
import java.util.logging.Level;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;

import javax.faces.event.AjaxBehaviorEvent;

import javax.faces.context.ExternalContext;

import org.primefaces.component.tabview.TabView;
import org.primefaces.event.TabChangeEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
*
Expand Down Expand Up @@ -215,6 +207,15 @@ public enum DisplayMode {

private String dataverseSiteUrl = "";

private boolean removeUnusedTags;

public boolean isRemoveUnusedTags() {
return removeUnusedTags;
}

public void setRemoveUnusedTags(boolean removeUnusedTags) {
this.removeUnusedTags = removeUnusedTags;
}

private List<FileMetadata> fileMetadatas;
private String fileSortField;
Expand Down Expand Up @@ -3562,16 +3563,9 @@ public void setTabFileTagsByName(List<String> tabFileTagsByName) {
}

private void refreshCategoriesByName(){

categoriesByName= new ArrayList<>();
for (FileMetadata fm : selectedFiles) {
if (fm.getCategories() != null) {
for (int i = 0; i < fm.getCategories().size(); i++) {
if (!categoriesByName.contains(fm.getCategories().get(i).getName())) {
categoriesByName.add(fm.getCategories().get(i).getName());
}
}
}
for (String category: dataset.getCategoriesByName() ){
categoriesByName.add(category);
}
refreshSelectedTags();
}
Expand Down Expand Up @@ -3612,16 +3606,13 @@ public void setSelectedTabFileTags(String[] selectedTabFileTags) {

private String[] selectedTags = {};

private void refreshSelectedTags() {
selectedTags = null;
selectedTags = new String[0];
if (categoriesByName.size() > 0) {
selectedTags = new String[categoriesByName.size()];
for (int i = 0; i < categoriesByName.size(); i++) {
selectedTags[i] = categoriesByName.get(i);
}
public void handleSelection(final AjaxBehaviorEvent event) {
if (selectedTags != null) {
selectedTags = selectedTags.clone();
}
}



private void refreshTabFileTagsByName(){

Expand All @@ -3647,6 +3638,7 @@ private void refreshSelectedTabFileTags() {
selectedTabFileTags[i] = tabFileTagsByName.get(i);
}
}
Arrays.sort(selectedTabFileTags);
}

private boolean tabularDataSelected = false;
Expand All @@ -3659,7 +3651,8 @@ public void setTabularDataSelected(boolean tabularDataSelected) {
this.tabularDataSelected = tabularDataSelected;
}

public String[] getSelectedTags() {
public String[] getSelectedTags() {

return selectedTags;
}

Expand All @@ -3681,6 +3674,46 @@ public void setNewCategoryName(String newCategoryName) {
this.newCategoryName = newCategoryName;
}

public String saveNewCategory() {
if (newCategoryName != null && !newCategoryName.isEmpty()) {
categoriesByName.add(newCategoryName);
}
//Now increase size of selectedTags and add new category
String[] temp = new String[selectedTags.length + 1];
System.arraycopy(selectedTags, 0, temp, 0, selectedTags.length);
selectedTags = temp;
selectedTags[selectedTags.length - 1] = newCategoryName;
//Blank out added category
newCategoryName = "";
return "";
}

private void refreshSelectedTags() {
selectedTags = null;
selectedTags = new String[0];

List selectedCategoriesByName= new ArrayList<>();
for (FileMetadata fm : selectedFiles) {
if (fm.getCategories() != null) {
for (int i = 0; i < fm.getCategories().size(); i++) {
if (!selectedCategoriesByName.contains(fm.getCategories().get(i).getName())) {
selectedCategoriesByName.add(fm.getCategories().get(i).getName());
}

}

}
}

if (selectedCategoriesByName.size() > 0) {
selectedTags = new String[selectedCategoriesByName.size()];
for (int i = 0; i < selectedCategoriesByName.size(); i++) {
selectedTags[i] = (String) selectedCategoriesByName.get(i);
}
}
Arrays.sort(selectedTags);
}

/* This method handles saving both "tabular file tags" and
* "file categories" (which are also considered "tags" in 4.0)
*/
Expand Down Expand Up @@ -3738,9 +3771,52 @@ public String saveFileTagsAndCategories() {

newCategoryName = null;


if (removeUnusedTags){
removeUnusedFileTagsFromDataset();
}
save();
return returnToDraftVersion();
return returnToDraftVersion();
}

/*
Remove unused file tags
When updating datafile tags see if any custom tags are not in use.
Remove them
*/
private void removeUnusedFileTagsFromDataset() {
categoriesByName = new ArrayList<>();
for (FileMetadata fm : workingVersion.getFileMetadatas()) {
if (fm.getCategories() != null) {
for (int i = 0; i < fm.getCategories().size(); i++) {
if (!categoriesByName.contains(fm.getCategories().get(i).getName())) {
categoriesByName.add(fm.getCategories().get(i).getName());
}
}
}
}
List<DataFileCategory> datasetFileCategoriesToRemove = new ArrayList();

for (DataFileCategory test : dataset.getCategories()) {
boolean remove = true;
for (String catByName : categoriesByName) {
if (catByName.equals(test.getName())) {
remove = false;
break;
}
}
if (remove) {
datasetFileCategoriesToRemove.add(test);
}
}

if (!datasetFileCategoriesToRemove.isEmpty()) {
for (DataFileCategory remove : datasetFileCategoriesToRemove) {
dataset.getCategories().remove(remove);
}

}

}


Expand Down
Loading

0 comments on commit 7d6b946

Please sign in to comment.