forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2554: Generalize Suggestion box to support controlled vocabul…
…ary values
- Loading branch information
Showing
13 changed files
with
410 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...erse/dataset/metadata/inputRenderer/suggestion/ControlledVocabularySuggestionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package edu.harvard.iq.dataverse.dataset.metadata.inputRenderer.suggestion; | ||
|
||
import com.google.common.collect.Lists; | ||
import edu.harvard.iq.dataverse.ControlledVocabularyValueServiceBean; | ||
import edu.harvard.iq.dataverse.dataset.metadata.inputRenderer.Suggestion; | ||
|
||
import javax.ejb.Stateless; | ||
import javax.inject.Inject; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* This suggestion handler provides suggestions based on controlled vocabulary values. | ||
* | ||
* @author Filipe Dias Lewandowski, Krzysztof Mądry, Daniel Korbel, Sylwester Niewczas | ||
*/ | ||
@Stateless | ||
public class ControlledVocabularySuggestionHandler implements SuggestionHandler { | ||
|
||
public static final String CONTROLLED_VOCABULARY_NAME_COLUMN = "controlledVocabularyName"; | ||
private ControlledVocabularyValueServiceBean controlledVocabularyValueServiceBean; | ||
|
||
// -------------------- CONSTRUCTORS -------------------- | ||
|
||
@Deprecated | ||
public ControlledVocabularySuggestionHandler() { | ||
} | ||
|
||
@Inject | ||
public ControlledVocabularySuggestionHandler(ControlledVocabularyValueServiceBean controlledVocabularyValueServiceBean) { | ||
this.controlledVocabularyValueServiceBean = controlledVocabularyValueServiceBean; | ||
} | ||
|
||
// -------------------- LOGIC -------------------- | ||
|
||
/** | ||
* {@inheritDoc} | ||
* <p> | ||
* This implementation always returns class name. | ||
*/ | ||
@Override | ||
public String getName() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
|
||
/** | ||
* This is not dependent on siblings input values. All values will be taken | ||
* to build matching suggestions list. | ||
*/ | ||
@Override | ||
public boolean isDependentOnSiblings() { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* <p> | ||
* This implementation filers out base on controlled vocabulary (input) name, | ||
* a.k.a. dictionary name | ||
*/ | ||
@Override | ||
public List<String> getAllowedFilters() { | ||
return Lists.newArrayList(CONTROLLED_VOCABULARY_NAME_COLUMN); | ||
} | ||
|
||
@Override | ||
public List<Suggestion> generateSuggestions(Map<String, String> filters, String suggestionSourceFieldValue) { | ||
return controlledVocabularyValueServiceBean | ||
.findByDatasetFieldTypeNameAndValueLike(filters.get(CONTROLLED_VOCABULARY_NAME_COLUMN), suggestionSourceFieldValue, 10) | ||
.stream().map(vocabulary -> new Suggestion(vocabulary.getStrValue(), vocabulary.getIdentifier())) | ||
.collect(toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.