}
public static List<UUID> createUUIDListFromStringPref(String prefKey) {
+ if (prefKey == null){
+ return null;
+ }
String prefValue = PreferencesUtil.getStringValue(prefKey);
if (prefValue == null){
return null;
CdmPreference pref = cache.get(PreferencePredicate.TaxonFeatures.getKey());
List<Feature> terms;
boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonFeatures.getKey()));
- if (pref != null && !override){
- List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(pref.getValue());
- terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
- }else if (override){
- terms= CdmStore.getTermManager().getPreferredTerms(TermType.Feature);
- TermVocabulary nameVocabulary = CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid());
- Set<Feature> nameFeature = nameVocabulary.getTerms();
- terms.removeAll(nameFeature);
-
- }else{
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.TaxonFeatures.getKey());
+ terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
+ if (terms == null || terms.isEmpty()){
terms= CdmStore.getTermManager().getPreferredTerms(TermType.Feature);
TermVocabulary nameVocabulary = CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid());
Set<Feature> nameFeature = nameVocabulary.getTerms();
return terms;
}
+ /**
+ *
+ * @param clazz
+ * @return
+ */
+ public List<TermDto> getPreferredTerms(TermVocabularyDto termVocabularyDto){
+ List terms = cachedTermMap.get(termVocabularyDto.getUuid());
+ if(terms==null){
+ terms = getFilteredTermDtos(new ArrayList<>(termVocabularyDto.getTerms()));
+ cachedTermMap.put(termVocabularyDto.getUuid(), terms);
+ }
+ return terms;
+ }
/**
*
return filteredTerms;
}
+ /**
+ * Generic method to get term preferences for a term vocabulary
+ *
+ * @param initialTerms a {@link java.util.List} object.
+ * @return a {@link java.util.List} object.
+ */
+ public List<TermDto> getFilteredTermDtos(List<TermDto> initialTerms){
+
+ List<TermDto> filteredTerms = new ArrayList();
+
+ for (TermDto term : initialTerms){
+
+ //TODO:inverse terms!!
+
+ if(PreferencesUtil.getBooleanValue(getPrefNameByDto(term))){
+ filteredTerms.add(term);
+ }
+ }
+ if (filteredTerms.isEmpty()){
+ return initialTerms;
+ }
+
+ return filteredTerms;
+ }
+
private <T extends TermBase> String getPrefName(T term) {
return term.getTermType()!=null?term.getTermType().toString()+term.getUuid().toString():""+term.getUuid().toString();
}
public <T extends DefinedTermBase> void setPreferredTermsByType(Collection<T> preferredTerms, TermType type){
- Collection<UUID> undesiredTermUuids = new ArrayList<UUID>();
+
List<DefinedTermBase> oldValues = getPreferredTerms(type);
for (DefinedTermBase term: oldValues){
PreferencesUtil.setBooleanValue(getPrefName(term), false);
}
clearTermMapForTermType(type);
+ List<DefinedTermBase> list = new ArrayList<>(preferredTerms);
+ cachedTermMap.put(type.getUuid(), list);
*/
public void setPreferredTermsByDto(Collection<TermDto> preferredTerms, TermVocabularyDto vocDto){
-
- Collection<UUID> undesiredTermUuids = new ArrayList<UUID>();
-
+ List<TermDto> oldValues = getPreferredTerms(vocDto);
+ for (TermDto term: oldValues){
+ PreferencesUtil.setBooleanValue(getPrefNameByDto(term), false);
+ }
for(TermDto term : preferredTerms){
- if(!preferredTerms.contains(term)){
- undesiredTermUuids.add(term.getUuid());
- PreferencesUtil.setBooleanValue(getPrefNameByDto(term), false);
- }else{
- PreferencesUtil.setBooleanValue(getPrefNameByDto(term), true);
- }
+ PreferencesUtil.setBooleanValue(getPrefNameByDto(term), true);
+
}
+
//if (initialTerms.iterator().hasNext()){
clearTermMapForTermVoc(vocDto.getUuid());
List<TermDto> list = new ArrayList<>(preferredTerms);