X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/7061e7247b92b91352eca80dff58d5b4cba71b7a..ad368340431e674a9bb12adff2fb2ae7eb8e8405:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java index 5a077c2e4..3ffac1baf 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java @@ -22,11 +22,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.StringTokenizer; import java.util.UUID; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; @@ -34,11 +37,14 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; import eu.etaxonomy.cdm.api.application.ICdmRepository; import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator; -import eu.etaxonomy.cdm.api.service.IFeatureTreeService; import eu.etaxonomy.cdm.api.service.ITermService; +import eu.etaxonomy.cdm.api.service.ITermTreeService; +import eu.etaxonomy.cdm.api.service.IVocabularyService; import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl; import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator; import eu.etaxonomy.cdm.common.CdmUtils; @@ -47,27 +53,34 @@ import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator; import eu.etaxonomy.cdm.model.common.ICdmBase; import eu.etaxonomy.cdm.model.common.Language; import eu.etaxonomy.cdm.model.common.MarkerType; +import eu.etaxonomy.cdm.model.description.Feature; import eu.etaxonomy.cdm.model.metadata.CdmPreference; import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey; import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate; import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; import eu.etaxonomy.cdm.model.metadata.PreferenceSubject; import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum; +import eu.etaxonomy.cdm.model.metadata.TermOrder; import eu.etaxonomy.cdm.model.name.NomenclaturalCode; -import eu.etaxonomy.cdm.model.term.FeatureTree; import eu.etaxonomy.cdm.model.term.IDefinedTerm; import eu.etaxonomy.cdm.model.term.ISimpleTerm; import eu.etaxonomy.cdm.model.term.TermBase; +import eu.etaxonomy.cdm.model.term.TermTree; +import eu.etaxonomy.cdm.model.term.TermType; +import eu.etaxonomy.cdm.model.term.TermVocabulary; +import eu.etaxonomy.cdm.model.term.VocabularyEnum; import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy; import eu.etaxonomy.cdm.strategy.match.FieldMatcher; import eu.etaxonomy.cdm.strategy.match.IMatchStrategy; import eu.etaxonomy.cdm.strategy.match.MatchException; import eu.etaxonomy.cdm.strategy.match.MatchMode; +import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.TermStore; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog; @@ -81,126 +94,142 @@ import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog; * @created 05.12.2008 */ public class PreferencesUtil implements IPreferenceKeys { + private final static String EDITOR_PREFERENCES_NODE = "eu.etaxonomy.taxeditor"; - /** - * - */ - public static final String PREFERRED_TERMS_CHANGE = "preferred_terms"; + public static final String PREFERRED_TERMS_CHANGE = "preferred_terms"; - public static final String P2_REPOSITORIES_DELIM = ","; - public static final String P2_REPOSITORY_FIELDS_DELIM = ";"; + public static final String P2_REPOSITORIES_DELIM = ","; + public static final String P2_REPOSITORY_FIELDS_DELIM = ";"; + public static final String SUBJECT_DELIM = "/"; - private final static Logger logger = Logger.getLogger(PreferencesUtil.class); + private static TermTree preferredNameFeatureTree; + private static TermTree preferredTaxonFeatureTree; + private final static Logger logger = Logger.getLogger(PreferencesUtil.class); + public static IPreferenceStore getPreferenceStore() { + return TaxeditorStorePlugin.getDefault().getPreferenceStore(); + } + + public static String[] extractSubjectParts(String subject){ + String[] result = subject.split("/"); + return result; + } + + public static IEclipsePreferences getEditorPreferences(){ + return ConfigurationScope.INSTANCE.getNode(EDITOR_PREFERENCES_NODE); + } + + public static String getPreferenceValue(PrefKey prefKey){ + try { + if(getEditorPreferences().nodeExists(prefKey.getPredicate())){ + Preferences predicateNode = getEditorPreferences().node(prefKey.getPredicate()); + String[] splittedSubject = extractSubjectParts(prefKey.getSubject()); + String value = predicateNode.get(splittedSubject[splittedSubject.length-1], PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue() != null? PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue().toString(): ""); + int index = splittedSubject.length -2; + while (value != null && index >= 0){ + value = predicateNode.get(splittedSubject[index], prefKey.getPredicate()); + index--; + } + return value; + } + + } catch (BackingStoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + public static List getPreference(PreferencePredicate prefPredicate){ + try { + List prefs = new ArrayList(); + CdmPreference pref; + PreferenceSubject subject; + if(getEditorPreferences().nodeExists(prefPredicate.getKey())){ + Preferences predicateNode = getEditorPreferences().node(prefPredicate.getKey()); + for (String childName: predicateNode.childrenNames()){ + Preferences child = predicateNode.node(childName); + String subjectString = ""; + subjectString = createSubjectStringForChildNodes(childName, child); + String value = child.get(subjectString, ""); + subject = PreferenceSubject.NewInstance(subjectString); + pref = CdmPreference.NewInstance(subject, prefPredicate, value); + prefs.add(pref); + } + + } + + } catch (BackingStoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + /** + * @param childName + * @param child + */ + private static String createSubjectStringForChildNodes(String subject, Preferences parent) { + try { + for (String childName: parent.childrenNames()){ + subject = childName+SUBJECT_DELIM+subject; + Preferences child = parent.node(childName); + createSubjectStringForChildNodes(subject, child); + } + } catch (BackingStoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return subject; - /** - *

- * getPreferenceStore - *

- * - * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object. - */ - public static IPreferenceStore getPreferenceStore() { - return TaxeditorStorePlugin.getDefault().getPreferenceStore(); - } + } - static String prefKey(String name) { - return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(); - } + private static String prefKey(String name) { + return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(); + } - public static String prefOverrideKey(String name) { + public static String prefOverrideKey(String name) { return name + "_OVERRIDE_"; } - /** - *

- * setStringValue - *

- * - * - **/ public static void setStringValue(String name, String value) { if (value != null){ getPreferenceStore().setValue(prefKey(name), value); }else{ - getPreferenceStore().setToDefault(name); + getPreferenceStore().setToDefault(prefKey(name)); } } - /** - *

- * setIntValue - *

- * - * - **/ public static void setIntValue(String name, int value) { getPreferenceStore().setValue(prefKey(name), value); } - /** - *

- * setBooleanValue - *

- * - * - **/ public static void setBooleanValue(String name, boolean value) { getPreferenceStore().setValue(prefKey(name), value); } - /** - *

- * setBooleanValue - *

- * - * - **/ public static void setDoubleValue(String name, double value) { getPreferenceStore().setValue(prefKey(name), value); } - /** - *

- * setFloatValue - *

- * - * - **/ public static void setFloatValue(String name, float value) { getPreferenceStore().setValue(prefKey(name), value); } - /** - *

- * setFloatValue - *

- * - * - **/ public static void setLongValue(String name, long value) { getPreferenceStore().setValue(prefKey(name), value); } - /** - *

- * getStringValue - *

- * - * - **/ public static String getStringValue(String name, boolean local) { CdmPreference pref = getDBPreferenceValue(name); String prefValue = null; String overrideKey = createPreferenceString(createOverridePreferenceString(name)); - boolean override = true; - if (getPreferenceStore().contains(overrideKey)){ - override = getPreferenceStore().getBoolean(overrideKey); - } + boolean override = getPreferenceStore().getBoolean(overrideKey); + if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){ String dbSpecific = prefKey(name); if (getPreferenceStore().contains(dbSpecific)){ @@ -225,29 +254,22 @@ public class PreferencesUtil implements IPreferenceKeys { CdmPreference pref = null; // pref = cache.get(name); - if (pref == null ){ - //get default value for Predicate - IPreferencePredicate pred = PreferencePredicate.getByKey(name); - if (pred != null){ - if (pred.getDefaultValue() != null){ - pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString()); - }else{ - pref = CdmPreference.NewTaxEditorInstance(pred, null); - } - pref.setAllowOverride(true); - } - } +// if (pref == null ){ +// //get default value for Predicate +// IPreferencePredicate pred = PreferencePredicate.getByKey(name); +// if (pred != null){ +// if (pred.getDefaultValue() != null){ +// pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString()); +// }else{ +// pref = CdmPreference.NewTaxEditorInstance(pred, null); +// } +// pref.setAllowOverride(true); +// } +// } return pref; } - /** - *

- * setIntValue - *

- * - * - **/ - public static int getIntValue(String name) { + public static int getIntValue(String name, boolean local) { CdmPreference pref= getDBPreferenceValue(name); String prefValue = null; if (pref != null){ @@ -259,7 +281,13 @@ public class PreferencesUtil implements IPreferenceKeys { }catch(NumberFormatException e){ logger.debug("Preference value of " + name + " is not a number"); } - if (result == null){ + + String overrideKey = createPreferenceString(createOverridePreferenceString(name)); + boolean override = true; + if (getPreferenceStore().contains(overrideKey)){ + override = getPreferenceStore().getBoolean(overrideKey); + } + if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){ String dbSpecific = prefKey(name); if (getPreferenceStore().contains(dbSpecific)){ result = getPreferenceStore().getInt(dbSpecific); @@ -270,33 +298,33 @@ public class PreferencesUtil implements IPreferenceKeys { } return result; - } public static boolean getBooleanValue(String name) { - return getBooleanValue(name, false); + Boolean result = getBooleanValue(name, false); + if (result == null){ + return false; + }else{ + return result; + } + } - /** - *

- * getBooleanValue - *

- * - * - **/ - public static boolean getBooleanValue(String name, boolean local) { + public static Boolean getBooleanValue(String name, boolean local) { if (CdmStore.isActive()){ CdmPreference pref = getDBPreferenceValue(name); - String prefValue = null; - if (pref == null || local){ + + String overrideKey = createPreferenceString(createOverridePreferenceString(name)); + boolean override = getPreferenceStore().getBoolean(overrideKey); + + if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){ String dbSpecific = prefKey(name); if (getPreferenceStore().contains(dbSpecific)){ return getPreferenceStore().getBoolean(dbSpecific); }else{ - return getPreferenceStore(). - getBoolean(name); + return null; } - }else{ + }else{ return Boolean.valueOf(pref.getValue()); } @@ -306,13 +334,6 @@ public class PreferencesUtil implements IPreferenceKeys { } - /** - *

- * setBooleanValue - *

- * - * - **/ public static double getDoubleValue(String name) { CdmPreference pref = getDBPreferenceValue(name); String prefValue = null; @@ -338,14 +359,7 @@ public class PreferencesUtil implements IPreferenceKeys { } - /** - *

- * getFloatValue - *

- * - * - **/ - public static float getFloatValue(String name) { + public static float getFloatValue(String name, boolean local) { CdmPreference pref = getDBPreferenceValue(name); String prefValue = null; if (pref != null){ @@ -357,7 +371,12 @@ public class PreferencesUtil implements IPreferenceKeys { }catch(NumberFormatException e){ logger.debug("Preference value of " + name + " is not a number"); } - if (result == null){ + String overrideKey = createPreferenceString(createOverridePreferenceString(name)); + boolean override = true; + if (getPreferenceStore().contains(overrideKey)){ + override = getPreferenceStore().getBoolean(overrideKey); + } + if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){ String dbSpecific = prefKey(name); if (getPreferenceStore().contains(dbSpecific)){ result = getPreferenceStore().getFloat(dbSpecific); @@ -370,13 +389,6 @@ public class PreferencesUtil implements IPreferenceKeys { } - /** - *

- * getLongValue - *

- * - * - **/ public static long getLongValue(String name) { CdmPreference pref = getDBPreferenceValue(name); String prefValue = null; @@ -401,67 +413,48 @@ public class PreferencesUtil implements IPreferenceKeys { return result; } - - /** - *

- * setPreferredNomenclaturalCode - *

- * - * @param preferredCode - * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} - * object. - */ - public static CdmPreference setPreferredNomenclaturalCode( - String preferenceValue, boolean local) { - if (local){ - setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY, - preferenceValue); - } - else{ - ICdmRepository controller; - controller = CdmStore.getCurrentApplicationConfiguration(); - if (controller == null){ + public static CdmPreference setPreferredNomenclaturalCode( + String preferenceValue, boolean local) { + if (local){ + setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY, + preferenceValue); + } + else{ + ICdmRepository controller; + controller = CdmStore.getCurrentApplicationConfiguration(); + if (controller == null){ return null; } - PrefKey key = null; - try{ - key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); - }catch (Exception e){ - System.out.println(e.getStackTrace()); - } - CdmPreference preference = null; - - if (preferenceValue == null){ - preference = controller.getPreferenceService().find(key); - if (preference == null){ - return null; - } else{ - setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY, - preference.getValue()); - - return preference; - } - } else{ - preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue); - controller.getPreferenceService().set(preference); - - } - } + PrefKey key = null; + try{ + key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); + }catch (Exception e){ + System.out.println(e.getStackTrace()); + } + CdmPreference preference = null; + + if (preferenceValue == null){ + preference = controller.getPreferenceService().find(key); + if (preference == null){ + return null; + } else{ + setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY, + preference.getValue()); + + return preference; + } + } else{ + preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue); + controller.getPreferenceService().set(preference); + + } + } return null; - } + } - /** - *

- * setPreferredNomenclaturalCode - *

- * - * @param preferredCode - * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} - * object. - */ public static void setPreferredNomenclaturalCode( CdmPreference preference) { @@ -470,86 +463,73 @@ public class PreferencesUtil implements IPreferenceKeys { if (controller == null){ return; } - PrefKey key = null; - try{ - key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); - }catch (Exception e){ - System.out.println(e.getStackTrace()); - } - controller.getPreferenceService().set(preference); + if (preference == null){ + PrefKey key = null; + try{ + key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); + }catch (Exception e){ + System.out.println(e.getStackTrace()); + } + controller.getPreferenceService().remove(key); + }else{ + controller.getPreferenceService().set(preference); + } } + public static NomenclaturalCode getPreferredNomenclaturalCode() { + CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode); - /** - *

- * getPreferredNomenclaturalCode - *

- * - * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. - */ - public static NomenclaturalCode getPreferredNomenclaturalCode() { - - CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode); - + String preferredCode; + if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){ + preferredCode = getStringValue( + PreferencePredicate.NomenclaturalCode.getKey()); - String preferredCode; - if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){ - preferredCode = getStringValue( - PreferencePredicate.NomenclaturalCode.getKey(), true); - - }else{ - preferredCode = pref.getValue(); - } - if (StringUtils.isBlank(preferredCode)){ - preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue()); - } + }else{ + preferredCode = pref.getValue(); + } + if (StringUtils.isBlank(preferredCode)){ + preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue()); + } - return getPreferredNomenclaturalCode(preferredCode); + return getPreferredNomenclaturalCode(preferredCode); - } + } - /** - *

- * getPreferredNomenclaturalCode - *

- * - * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. - */ public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) { for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) { - if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) { + if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode) || code.getKey().equals(preferenceKeyNomenclaturalCode)) { return code; } } return null; } - public static boolean isShowTaxonAssociations(){ + public static boolean isShowTaxonAssociations(){ boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey()); return result; } - public static boolean isShowLifeForm(){ - boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey()); - return result; + public static boolean isShowLifeForm(){ + boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey()); + return result; } - public static boolean isDeterminationOnlyForFieldUnits(){ - boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()); + public static boolean isDeterminationOnlyForFieldUnits(){ + boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()); return result; } - public static boolean isCollectingAreaInGeneralSection(){ - boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()); + public static boolean isCollectingAreaInGeneralSection(){ + boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()); return result; - } + } - public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){ + public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){ ICdmRepository controller; CdmPreference pref = null; @@ -567,7 +547,7 @@ public class PreferencesUtil implements IPreferenceKeys { } - public static List getPreferencesFromDB(IPreferencePredicate predicate){ + public static List getPreferencesFromDB(IPreferencePredicate predicate){ ICdmRepository controller; List prefs = null; @@ -585,7 +565,27 @@ public class PreferencesUtil implements IPreferenceKeys { } - public static CdmPreference getPreferenceFromDB(PrefKey key){ + public static void setPreferencesToDB(CdmPreference preference, boolean setDefault){ + ICdmRepository controller; + try{ + if(CdmStore.isActive()){ + controller = CdmStore.getCurrentApplicationConfiguration(); + + if (setDefault){ + controller.getPreferenceService().remove(preference.getKey()); + }else{ + controller.getPreferenceService().set(preference); + } + } + }catch(Exception e){ + e.printStackTrace(); + } + + + + } + + public static CdmPreference getPreferenceFromDB(PrefKey key){ ICdmRepository controller; CdmPreference pref = null; @@ -602,14 +602,16 @@ public class PreferencesUtil implements IPreferenceKeys { } - - public static void setPreferenceToDB(CdmPreference preference){ ICdmRepository controller; try{ if(CdmStore.isActive()){ controller = CdmStore.getCurrentApplicationConfiguration(); - controller.getPreferenceService().set(preference); + if (preference.getValue() == null && preference.isAllowOverride()){ + controller.getPreferenceService().remove(preference.getKey()); + }else{ + controller.getPreferenceService().set(preference); + } CdmPreferenceCache.instance().put(preference); } }catch(Exception e){ @@ -618,347 +620,322 @@ public class PreferencesUtil implements IPreferenceKeys { } + public static String getPreferredDefaultLangugae(){ + String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR); + if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){ + return preferredLanguage; + } + return null; + } - - public static String getPreferredDefaultLangugae(){ - String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR); - if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){ - return preferredLanguage; - } - return null; - } - - public static boolean isShowMediaPreview(){ + public static boolean isShowMediaPreview(){ boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW); return isShowMediaPreview; } - /** - * Get the match strategy for the given class that was stored in preferences - * or the default strategy if it was not stored in preferences - * - * @param clazz - * a {@link java.lang.Class} object. - * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. - */ - public static IMatchStrategy getMatchStrategy(Class clazz) { - String className = clazz.getName(); - if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) { - IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz); - - //TODO CacheMatchers (or multiple field matchers in future) are missing here - for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) { - String fieldName = fieldMatcher.getPropertyName(); - String matchModeName = getStringValue( - getMatchStrategyFieldName(className, fieldName)); - MatchMode matchMode = MatchMode.valueOf(matchModeName); - try { - matchStrategy.setMatchMode(fieldName, matchMode); - } catch (MatchException e) { - MessagingUtils.error(PreferencesUtil.class, e); - throw new RuntimeException(e); - } - } - - return matchStrategy; - } - return getDefaultMatchStrategy(clazz); - } - - /** - * Stores a matchStrategy into the preference store. - * - * @param matchStrategy - * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} - * object. - */ - public static void setMatchStrategy(IMatchStrategy matchStrategy) { - String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use - setBooleanValue(MATCH_STRATEGY_PREFIX + className, true); - - List fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false); - - for (FieldMatcher fieldMatcher : fieldMatchers) { - String fieldName = fieldMatcher.getPropertyName(); - setStringValue( - getMatchStrategyFieldName(className, fieldName), - fieldMatcher.getMatchMode().name()); - } - } - - /** - * Helper method to create the preference property for a match field. - * - * @param className - * @param fieldName - * @return - */ - private static String getMatchStrategyFieldName(String className, - String fieldName) { - return MATCH_STRATEGY_PREFIX + className + "." + fieldName; - } - - /** - * Returns the default match strategy for a given class. - * - * @param clazz - * a {@link java.lang.Class} object. - * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. - */ - public static IMatchStrategy getDefaultMatchStrategy(Class clazz) { - return DefaultMatchStrategy.NewInstance(clazz); - } - - /** - *

- * getDateFormatPattern - *

- * - * @return a {@link java.lang.String} object. - */ - public static String getDateFormatPattern() { - // TODO make this configurable in properties - String pattern = "Y-M-d H:m"; - return pattern; - } - - /** - *

- * addTermToPreferredTerms - *

- * - * @param term - * a T object. - * @param - * a T object. - */ - public static void addTermToPreferredTerms(T term) { - - // VocabularyEnum vocabulary = - // VocabularyEnum.getVocabularyEnum(term.getClass()); - // - // getPreferenceStore().setValue(getPreferenceKey(term), - // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term)); - // - // firePreferencesChanged(term.getClass()); - } - - /** - * Construct a unique key using the CdmBase object's uuid - * - * @param cdmBase - * @return - */ - private static String getPreferenceKey(ICdmBase cdmBase) { - cdmBase = HibernateProxyHelper.deproxy(cdmBase); - - String key = cdmBase.getClass().getName().concat(".") - .concat(cdmBase.getUuid().toString()); - if (key.contains("javassist")) { - MessagingUtils.info("proxy"); - } - return key; - } - - /** - * Construct a unique key using the CdmBase object's uuid - * - * @param cdmBase - * @return - */ - public static String getPreferenceKey(ISimpleTerm simpleTerm) { - simpleTerm = HibernateProxyHelper.deproxy(simpleTerm); - String key = simpleTerm.getClass().getName().concat(".") - .concat(simpleTerm.getUuid().toString()); - if (key.contains("javassist")) { - MessagingUtils.warn(PreferencesUtil.class, - "Trying to persist a preference based on a proxy class."); - } - return key; - } - - - - /** - * Construct a unique key using the CdmBase object's uuid - * - * @param cdmBase - * @return - */ - public static String getPreferenceKey(IDefinedTerm definedTerm) { - definedTerm = HibernateProxyHelper.deproxy(definedTerm); - String key = definedTerm.getClass().getName().concat(".") - .concat(definedTerm.getUuid().toString()); - if (key.contains("javassist")) { - MessagingUtils.warn(PreferencesUtil.class, - "Trying to persist a preference based on a proxy class."); - } - return key; - } - - /** - * Retrieves search preferences from the preference store - * - * @return an {@link ITaxonServiceConfigurator} to pass to search methods - */ - public static IFindTaxaAndNamesConfigurator getSearchConfigurator() { - IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator(); - - configurator.setDoTaxa(getBooleanValue( - TAXON_SERVICE_CONFIGURATOR_TAXA)); - configurator.setDoSynonyms(getBooleanValue( - TAXON_SERVICE_CONFIGURATOR_SYNONYMS)); - configurator.setDoNamesWithoutTaxa(getBooleanValue( - TAXON_SERVICE_CONFIGURATOR_NAMES)); - configurator.setDoTaxaByCommonNames(getBooleanValue( - TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)); - //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE))); - - return configurator; - } - - /** - * create new preferences, setting all search options to true - * - * @return a - * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} - * object. - */ - public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() { - IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance(); - - configurator.setDoTaxa(true); - configurator.setDoSynonyms(true); - configurator.setDoNamesWithoutTaxa(true); - configurator.setDoTaxaByCommonNames(true); - - configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache", - "name", "name.$", "relationsFromThisTaxon.$")); - - configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache", - "name", "name.$", "synonyms.relatedTo.*")); - - // DEFAULT VALUES - // match mode is a simple like, actually all other match modes are kind - // of bogus - configurator - .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE); - // we set page number and size here as this should always be unlimited - configurator.setPageNumber(0); - // TODO currently limit results to 10000 - configurator.setPageSize(10000); - //setSearchConfigurator(configurator) ; - return configurator; - } - - /** - * Store search preferences - * - * @param configurator - * a - * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} - * object. - */ - public static void setSearchConfigurator( - IFindTaxaAndNamesConfigurator configurator) { - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, - configurator.isDoTaxa()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, - configurator.isDoSynonyms()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, - configurator.isDoNamesWithoutTaxa()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, - configurator.isDoTaxaByCommonNames()); - } - - /** - *

- * firePreferencesChanged - *

- * - * @param clazz - * a {@link java.lang.Class} object. - */ - public static void firePreferencesChanged(Class clazz) { - getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE, - null, clazz); - } - - public static String createPreferenceString(String property){ - return prefKey(property); - - } - public static String createOverridePreferenceString(String property){ - return prefOverrideKey(property); - - } - - /** - * Set default values for preferences - */ - public static void setDefaults() { - getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true); - getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, - true); - getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT), - "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php"); - //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution - getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false); - getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT), - "http://www.biodiversitylibrary.org/openurl"); - getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000"); - getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000"); - //Distribution Editor: - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString())); -// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString()); -// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString()); - - - //Name Details - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString()); - - //Navigator preferences - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey()); - - //getPreferenceStore().setDefault(createPreferenceString(Prefe), true); - - getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false); + /** + * Get the match strategy for the given class that was stored in preferences + * or the default strategy if it was not stored in preferences + * + * @param clazz + * a {@link java.lang.Class} object. + * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. + */ + public static IMatchStrategy getMatchStrategy(Class clazz) { + String className = clazz.getName(); + if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) { + IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz); + + //TODO CacheMatchers (or multiple field matchers in future) are missing here + for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) { + String fieldName = fieldMatcher.getPropertyName(); + String matchModeName = getStringValue( + getMatchStrategyFieldName(className, fieldName)); + MatchMode matchMode = MatchMode.valueOf(matchModeName); + try { + matchStrategy.setMatchMode(fieldName, matchMode); + } catch (MatchException e) { + MessagingUtils.error(PreferencesUtil.class, e); + throw new RuntimeException(e); + } + } + + return matchStrategy; + } + return getDefaultMatchStrategy(clazz); + } + + /** + * Stores a matchStrategy into the preference store. + * + * @param matchStrategy + * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} + * object. + */ + public static void setMatchStrategy(IMatchStrategy matchStrategy) { + String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use + setBooleanValue(MATCH_STRATEGY_PREFIX + className, true); + + List fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false); + + for (FieldMatcher fieldMatcher : fieldMatchers) { + String fieldName = fieldMatcher.getPropertyName(); + setStringValue( + getMatchStrategyFieldName(className, fieldName), + fieldMatcher.getMatchMode().name()); + } + } + + /** + * Helper method to create the preference property for a match field. + * + * @param className + * @param fieldName + * @return + */ + private static String getMatchStrategyFieldName(String className, + String fieldName) { + return MATCH_STRATEGY_PREFIX + className + "." + fieldName; + } + + /** + * Returns the default match strategy for a given class. + * + * @param clazz + * a {@link java.lang.Class} object. + * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. + */ + public static IMatchStrategy getDefaultMatchStrategy(Class clazz) { + return DefaultMatchStrategy.NewInstance(clazz); + } + + public static String getDateFormatPattern() { + // TODO make this configurable in properties + String pattern = "Y-M-d H:m"; + return pattern; + } + + public static void addTermToPreferredTerms(T term) { + + // VocabularyEnum vocabulary = + // VocabularyEnum.getVocabularyEnum(term.getClass()); + // + // getPreferenceStore().setValue(getPreferenceKey(term), + // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term)); + // + // firePreferencesChanged(term.getClass()); + } + + /** + * Construct a unique key using the CdmBase object's uuid + * + * @param cdmBase + * @return + */ + private static String getPreferenceKey(ICdmBase cdmBase) { + cdmBase = HibernateProxyHelper.deproxy(cdmBase); + + String key = cdmBase.getClass().getName().concat(".") + .concat(cdmBase.getUuid().toString()); + if (key.contains("javassist")) { + MessagingUtils.info("proxy"); + } + return key; + } + + /** + * Construct a unique key using the CdmBase object's uuid + * + * @param cdmBase + * @return + */ + public static String getPreferenceKey(ISimpleTerm simpleTerm) { + simpleTerm = HibernateProxyHelper.deproxy(simpleTerm); + String key = simpleTerm.getClass().getName().concat(".") + .concat(simpleTerm.getUuid().toString()); + if (key.contains("javassist")) { + MessagingUtils.warn(PreferencesUtil.class, + "Trying to persist a preference based on a proxy class."); + } + return key; + } + + + + /** + * Construct a unique key using the CdmBase object's uuid + * + * @param cdmBase + * @return + */ + public static String getPreferenceKey(IDefinedTerm definedTerm) { + definedTerm = HibernateProxyHelper.deproxy(definedTerm); + String key = definedTerm.getClass().getName().concat(".") + .concat(definedTerm.getUuid().toString()); + if (key.contains("javassist")) { + MessagingUtils.warn(PreferencesUtil.class, + "Trying to persist a preference based on a proxy class."); + } + return key; + } + + /** + * Retrieves search preferences from the preference store + * + * @return an {@link ITaxonServiceConfigurator} to pass to search methods + */ + public static IFindTaxaAndNamesConfigurator getSearchConfigurator() { + IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator(); + + configurator.setDoTaxa(getBooleanValue( + TAXON_SERVICE_CONFIGURATOR_TAXA)); + configurator.setDoSynonyms(getBooleanValue( + TAXON_SERVICE_CONFIGURATOR_SYNONYMS)); + configurator.setDoNamesWithoutTaxa(getBooleanValue( + TAXON_SERVICE_CONFIGURATOR_NAMES)); + configurator.setDoTaxaByCommonNames(getBooleanValue( + TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)); + //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE))); + + return configurator; + } + + /** + * create new preferences, setting all search options to true + * + * @return a + * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} + * object. + */ + public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() { + IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance(); + + configurator.setDoTaxa(true); + configurator.setDoSynonyms(true); + configurator.setDoNamesWithoutTaxa(true); + configurator.setDoTaxaByCommonNames(true); + + configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache", + "name", "name.$", "relationsFromThisTaxon.$")); + + configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache", + "name", "name.$", "synonyms.relatedTo.*")); + + // DEFAULT VALUES + // match mode is a simple like, actually all other match modes are kind + // of bogus + configurator + .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE); + // we set page number and size here as this should always be unlimited + configurator.setPageNumber(0); + // TODO currently limit results to 10000 + configurator.setPageSize(10000); + //setSearchConfigurator(configurator) ; + return configurator; + } + + /** + * Store search preferences + * + * @param configurator + * a + * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} + * object. + */ + public static void setSearchConfigurator( + IFindTaxaAndNamesConfigurator configurator) { + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, + configurator.isDoTaxa()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, + configurator.isDoSynonyms()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, + configurator.isDoNamesWithoutTaxa()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, + configurator.isDoTaxaByCommonNames()); + } + + public static void firePreferencesChanged(Class clazz) { + getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE, + null, clazz); + } + + + public static String createPreferenceString(String property){ + return prefKey(property); + + } + public static String createOverridePreferenceString(String property){ + return prefOverrideKey(property); + + } + + /** + * Set default values for preferences + */ + public static void setDefaults() { + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, + true); + getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT), + "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php"); + //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution + getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceAccessPoint.getKey()), + "http://www.biodiversitylibrary.org/openurl"); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceMaxWidth.getKey()), "1000"); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceMaxHeight.getKey()), "1000"); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_NAMES, true); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, true); + + //Distribution Editor: +// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString())); +// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString()); +// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString()); + + + //Name Details + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString()); + + //Navigator preferences + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey()); + + //getPreferenceStore().setDefault(createPreferenceString(Prefe), true); + + getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false); getPreferenceStore().setDefault(createPreferenceString(SHOW_MEDIA_PREVIEW), false); - //override db preferences - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true); - getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false); - getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false); - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString())); - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString())); - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString())); - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString())); - getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString())); - - } - - /** - *

- * checkNomenclaturalCode - *

- */ - public static void checkNomenclaturalCode() { - // First time Editor is opened, no nomenclatural code has been set - if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { - PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true); - } - - - - } - public static void setNomenclaturalCodePreferences(){ - ICdmRepository controller; + //override db preferences + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true); + getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.CommonNameReferencesWithMarker.getKey()), false); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString())); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString())); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString())); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString())); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString())); + getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowSpecimen.getKey()), Boolean.valueOf(PreferencePredicate.ShowSpecimen.getDefaultValue().toString())); + + } + + public static void checkNomenclaturalCode() { + // First time Editor is opened, no nomenclatural code has been set + if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { + PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true); + } + + + + } + public static void setNomenclaturalCodePreferences(){ + ICdmRepository controller; controller = CdmStore.getCurrentApplicationConfiguration(); PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); CdmPreference preference = null; @@ -978,210 +955,147 @@ public class PreferencesUtil implements IPreferenceKeys { setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY, getPreferenceKey(preferredCode)); - } - - public static void checkDefaultLanguage(){ - if(PreferencesUtil.getPreferredDefaultLangugae() == null){ - Shell shell = AbstractUtility.getShell(); - int open = new DefaultLanguageDialog(shell).open(); - if(open == Window.OK){ - PlatformUI.getWorkbench().restart(); - } - }else{ - //TODO:In case of a reinstall, the config.ini will be overwritten - // here you create config.ini with the stored key from preferences - } - } - - /** - *

- * getMapServiceAccessPoint - *

- * - * @return a {@link java.lang.String} object. - */ - public static String getMapServiceAccessPoint() { - return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT); - } - - /** - *

- * shouldConnectAtStartUp - *

- * - * @return a boolean. - */ - public static boolean shouldConnectAtStartUp() { - //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution - //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP); - return false; - } - - /** - *

- * getDefaultFeatureTreeForTextualDescription - *

- * - * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object. - */ - public static FeatureTree getDefaultFeatureTreeForTextualDescription() { - String uuidString = getStringValue( - FEATURE_TREE_DEFAULT_TEXT); - if (StringUtils.isBlank(uuidString)) { + } + + public static void checkDefaultLanguage(){ + if(PreferencesUtil.getPreferredDefaultLangugae() == null){ + Shell shell = AbstractUtility.getShell(); + int open = new DefaultLanguageDialog(shell).open(); + if(open == Window.OK){ + PlatformUI.getWorkbench().restart(); + } + }else{ + //TODO:In case of a reinstall, the config.ini will be overwritten + // here you create config.ini with the stored key from preferences + } + } + + public static String getMapServiceAccessPoint() { + return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT); + } + + public static boolean shouldConnectAtStartUp() { + //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution + //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP); + return false; + } + + public static TermTree getDefaultFeatureTreeForTextualDescription() { + String uuidString = getStringValue( + FEATURE_TREE_DEFAULT_TEXT); + if (StringUtils.isBlank(uuidString)) { return null; } - FeatureTree tree = CdmStore.getService( - IFeatureTreeService.class).load(UUID.fromString(uuidString)); - if (tree.getId() == 0) { + TermTree tree = CdmStore.getService( + ITermTreeService.class).load(UUID.fromString(uuidString)); + + if (tree == null || tree.getId() == 0) { return null; } - return tree; - } - - /** - *

- * getDefaultFeatureTreeForStructuredDescription - *

- * - * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object. - */ - public static FeatureTree getDefaultFeatureTreeForStructuredDescription() { - String uuidString = getStringValue( - FEATURE_TREE_DEFAULT_STRUCTURE); - return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService( - IFeatureTreeService.class).load(UUID.fromString(uuidString)); - } - - /** - *

- * setSortRanksHierarchichally - *

- * - * @param selection - * a boolean. - */ - public static void setSortRanksHierarchichally(boolean selection) { - setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection); - } - - /** - *

- * getSortRanksHierarchichally - *

- * - * @return a boolean. - */ - public static boolean getSortRanksHierarchichally() { - return getBooleanValue(SORT_RANKS_HIERARCHICHALLY); - } - - public static boolean isMultilanguageTextEditingCapability() { - return getBooleanValue( - MULTILANGUAGE_TEXT_EDITING_CAPABILITY); - } - - public static Language getGlobalLanguage() { - - - String languageUuidString = getStringValue( - GLOBAL_LANGUAGE_UUID); - - if(!CdmStore.isActive()) { + return tree; + } + + public static TermTree getDefaultFeatureTreeForStructuredDescription() { + String uuidString = getStringValue( + FEATURE_TREE_DEFAULT_STRUCTURE); + return StringUtils.isBlank(uuidString) ? null : CdmStore.getService( + ITermTreeService.class).load(UUID.fromString(uuidString)); + } + + public static void setSortRanksHierarchichally(boolean selection) { + setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection); + } + + public static boolean getSortRanksHierarchichally() { + return getBooleanValue(SORT_RANKS_HIERARCHICHALLY); + } + + public static boolean isMultilanguageTextEditingCapability() { + return getBooleanValue( + MULTILANGUAGE_TEXT_EDITING_CAPABILITY); + } + + public static Language getGlobalLanguage() { + + + String languageUuidString = getStringValue( + GLOBAL_LANGUAGE_UUID); + + if(!CdmStore.isActive()) { MessagingUtils.noDataSourceWarningDialog(languageUuidString); return null; } - if (CdmUtils.isBlank(languageUuidString)) { - return Language.getDefaultLanguage(); - } - - UUID languageUuid = UUID.fromString(languageUuidString); - return (Language) CdmStore.getService(ITermService.class).load( - languageUuid); - } - - public static void setGlobalLanguage(Language language) { - if(language != null) { - setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString()); - CdmStore.setDefaultLanguage(language); - } - - } - - /** - * @return - */ - public static Map getEditMarkerTypePreferences() { - List markerTypes = CdmStore.getTermManager() - .getPreferredTerms(MarkerType.class); - - Map result = new HashMap(); - - for (MarkerType markerType : markerTypes) { - String name = getMarkerTypeEditingPreferenceKey(markerType); - Boolean value = getBooleanValue(name); - - result.put(markerType, value); - } - - return result; - } - - /** - * @param markerTypeEditingMap - */ - public static void setEditMarkerTypePreferences( - Map markerTypeEditingMap) { - for (MarkerType markerType : markerTypeEditingMap.keySet()) { - String name = getMarkerTypeEditingPreferenceKey(markerType); - setBooleanValue(name, - markerTypeEditingMap.get(markerType)); - } - - } - - private static String getMarkerTypeEditingPreferenceKey( - MarkerType markerType) { - markerType = HibernateProxyHelper.deproxy(markerType); - return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX; - } - - /** - *

- * setEditMarkerTypePreference - *

- * - * @param input - * a {@link org.eclipse.ui.IEditorInput} object. - * @param markerType - * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object. - * @param edit - * a boolean. - */ - public static void setEditMarkerTypePreference(MarkerType markerType, - boolean edit) { - setBooleanValue( - getMarkerTypeEditingPreferenceKey(markerType), edit); - } - - /** - * @return - */ - public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() { - DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator - .NewInstance(); - configurator.setMoveDerivedUnitMediaToGallery(true); - configurator.setMoveFieldObjectMediaToGallery(true); - return configurator; - } - - /** - * This method will write language properties to the config.ini located in the configuration folder - * of the Taxonomic Ediitor. This method is only used to set the default language for Taxonomic Editor. - * - * @param setLanguage 0 is for german and 1 for english. - * @throws IOException - */ + if (CdmUtils.isBlank(languageUuidString)) { + return Language.getDefaultLanguage(); + } + + UUID languageUuid = UUID.fromString(languageUuidString); + return (Language) CdmStore.getService(ITermService.class).load( + languageUuid); + } + + public static void setGlobalLanguage(Language language) { + if(language != null) { + setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString()); + CdmStore.setDefaultLanguage(language); + } + + } + + public static Map getEditMarkerTypePreferences() { + List markerTypes = CdmStore.getTermManager() + .getPreferredTerms(MarkerType.class); + + Map result = new HashMap(); + + for (MarkerType markerType : markerTypes) { + String name = getMarkerTypeEditingPreferenceKey(markerType); + Boolean value = getBooleanValue(name); + + result.put(markerType, value); + } + + return result; + } + + public static void setEditMarkerTypePreferences( + Map markerTypeEditingMap) { + for (MarkerType markerType : markerTypeEditingMap.keySet()) { + String name = getMarkerTypeEditingPreferenceKey(markerType); + setBooleanValue(name, + markerTypeEditingMap.get(markerType)); + } + + } + + private static String getMarkerTypeEditingPreferenceKey( + MarkerType markerType) { + markerType = HibernateProxyHelper.deproxy(markerType); + return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX; + } + + public static void setEditMarkerTypePreference(MarkerType markerType, + boolean edit) { + setBooleanValue( + getMarkerTypeEditingPreferenceKey(markerType), edit); + } + + public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() { + DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator + .NewInstance(); + configurator.setMoveDerivedUnitMediaToGallery(true); + configurator.setMoveFieldObjectMediaToGallery(true); + return configurator; + } + + /** + * This method will write language properties to the config.ini located in the configuration folder + * of the Taxonomic Ediitor. This method is only used to set the default language for Taxonomic Editor. + * + * @param setLanguage 0 is for german and 1 for english. + * @throws IOException + */ public void writePropertyToConfigFile(int setLanguage) throws IOException { File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile(); //give warning to user if the directory has no write access @@ -1306,80 +1220,48 @@ public class PreferencesUtil implements IPreferenceKeys { } } - - - - /** - * @param orderActivated - */ public static void setSortNodes(NavigatorOrderEnum nodesOrder) { - setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key); + if (nodesOrder == null){ + setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), null); + }else{ + setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key); + } } - /** - * @param orderActivated - */ public static NavigatorOrderEnum getSortNodes() { return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey())); } - - /** - * @param orderActivated - */ + public static boolean isNodesSortedNaturally() { NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey())); return value.equals(NavigatorOrderEnum.NaturalOrder); } - /** - * @param orderActivated - */ public static boolean isNodesSortedByName() { NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey())); return value.equals(NavigatorOrderEnum.AlphabeticalOrder); } - /** - * @param orderActivated - */ public static boolean isNodesSortedByNameAndRank() { NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey())); return value.equals(NavigatorOrderEnum.RankAndNameOrder); } - /** - *

- * setStoreNavigatorState - *

- * - * @param selection - * a boolean. - */ - public static boolean isStoreNavigatorState() { - return getBooleanValue(RESTORE_NAVIGATOR_STATE); - - } - - /** - *

- * setStoreNavigatorState - *

- * - * @param selection - * a boolean. - */ - public static void setStoreNavigatorState(boolean selection) { - setBooleanValue(RESTORE_NAVIGATOR_STATE, selection); - - } - /** - * @return - */ + public static boolean isStoreNavigatorState() { + return getBooleanValue(RESTORE_NAVIGATOR_STATE); + + } + + public static void setStoreNavigatorState(boolean selection) { + setBooleanValue(RESTORE_NAVIGATOR_STATE, selection); + + } + public static boolean isShowUpWidgetIsDisposedMessages() { return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED); } @@ -1387,9 +1269,6 @@ public class PreferencesUtil implements IPreferenceKeys { setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection); } - /** - * @return - */ public static boolean isShowIdInVocabularyInChecklistEditor() { String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()); if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) { @@ -1426,24 +1305,22 @@ public class PreferencesUtil implements IPreferenceKeys { return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()); } - /** - * @return - */ - public static String displayAreaInChecklistEditor() { - String result = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()); - if (StringUtils.isBlank(result)){ - return ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()).getKey(); + public static TermDisplayEnum displayAreaInChecklistEditor() { + TermDisplayEnum result; + try{ + result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey())); + }catch (IllegalArgumentException e){ + result = ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()); } return result; } - /** - * @return - */ - public static String displayStatusInChecklistEditor() { - String result = getStringValue(PreferencePredicate.DisplayOfStatus.getKey()); - if (StringUtils.isBlank(result)){ - return((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey(); + public static TermDisplayEnum displayStatusInChecklistEditor() { + TermDisplayEnum result; + try{ + result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfStatus.getKey())); + }catch (IllegalArgumentException e){ + result = ((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()); } return result; } @@ -1452,9 +1329,6 @@ public class PreferencesUtil implements IPreferenceKeys { } - /** - * @return - */ public static boolean isShowRankInChecklistEditor() { return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey()); } @@ -1462,11 +1336,6 @@ public class PreferencesUtil implements IPreferenceKeys { setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection); } - /** - * @param object - * @param b - * @return - */ public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) { NameDetailsConfigurator config = new NameDetailsConfigurator(true); CdmPreferenceCache cache = CdmPreferenceCache.instance(); @@ -1474,7 +1343,7 @@ public class PreferencesUtil implements IPreferenceKeys { String value; if (!local) { PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView); - preference = cache.findBestMatching(key); + preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView); if (preference == null){ return null; } @@ -1487,45 +1356,36 @@ public class PreferencesUtil implements IPreferenceKeys { }else{ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local); } - String [] sections = value.split(";"); - Map sectionMap = new HashMap(); - String[] sectionValues; - for (String sectionValue: sections){ - sectionValues = sectionValue.split(":"); - sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1])); - } - - config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated")); - - config.setTaxonSectionActivated(getValue(sectionMap, "taxon")); - - config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails")); - config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled")); - - config.setLSIDActivated(getValue(sectionMap, "lsid")); - - config.setNomenclaturalCodeActived(getValue(sectionMap, "nc")); - - config.setAppendedPhraseActivated(getValue(sectionMap, "ap")); - - config.setRankActivated(getValue(sectionMap, "rank")); - - config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets")); - - config.setAuthorshipSectionActivated(getValue(sectionMap,"author")); - - config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef")); - - config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat")); - - config.setProtologueActivated(getValue(sectionMap,"protologue")); - - config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes")); - - config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation")); - + if (value!= null){ + String [] sections = value.split(";"); + Map sectionMap = new HashMap(); + String[] sectionValues; + for (String sectionValue: sections){ + sectionValues = sectionValue.split(":"); + sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1])); + } + config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated")); + config.setTaxonSectionActivated(getValue(sectionMap, "taxon")); + config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails")); + config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled")); + config.setLSIDActivated(getValue(sectionMap, "lsid")); + config.setNomenclaturalCodeActived(getValue(sectionMap, "nc")); + config.setAppendedPhraseActivated(getValue(sectionMap, "ap")); + config.setRankActivated(getValue(sectionMap, "rank")); + config.setNameCacheActivated(getValue(sectionMap, "nameCache")); + config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets")); + config.setAuthorshipSectionActivated(getValue(sectionMap,"author")); + config.setAuthorCacheActivated(getValue(sectionMap, "authorCache")); + config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef")); + config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat")); + config.setProtologueActivated(getValue(sectionMap,"protologue")); + config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes")); + config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation")); config.setHybridActivated(getValue(sectionMap,"hybrid")); - + config.setNameApprobiationActivated(getValue(sectionMap, "nameApproviation")); + }else { + return null; + } return config; } @@ -1578,12 +1438,6 @@ public class PreferencesUtil implements IPreferenceKeys { return config; } - - /** - * @param object - * @param b - * @return - */ public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) { CdmPreference preference = null; @@ -1600,25 +1454,14 @@ public class PreferencesUtil implements IPreferenceKeys { } private static Boolean getValue(Map sectionMap, String string) { - if (sectionMap.containsKey(string)){ - return sectionMap.get(string); - }else{ - return true; - } - - } - + if (sectionMap.containsKey(string)){ + return sectionMap.get(string); + }else{ + return true; + } + } - /** - *

- * setAbcdConfigurator - *

- * - * @param preferredConfiguration - * a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator} - * object. - */ public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() { Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null); @@ -1634,6 +1477,14 @@ public class PreferencesUtil implements IPreferenceKeys { return config; } else{ String configString = preference.getValue(); + extractAbcdConfiguratorFromPreferenceString(config, configString); + } + return config; + } + + public static void extractAbcdConfiguratorFromPreferenceString(Abcd206ImportConfigurator config, + String configString) { + if(configString!=null){ String[] configArray = configString.split(";"); for (String configItem: configArray){ @@ -1641,7 +1492,13 @@ public class PreferencesUtil implements IPreferenceKeys { String keyString = keyValue[0]; String valueString = null; if (keyValue.length>1){ - valueString = keyValue[1]; + valueString = keyValue[1]; + if (keyValue.length>2){ + + for (int index = 2; index< keyValue.length; index++){ + valueString += ":"+ keyValue[index]; + } + } } if (keyString.equals("ignoreImportOfExistingSpecimen")){ config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString)); @@ -1674,45 +1531,34 @@ public class PreferencesUtil implements IPreferenceKeys { }else if (keyString.equals("overwriteExistingSpecimens")){ config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString)); }else if (keyString.equals("nomenclaturalCode")){ - config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString)); + config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString)); + }else if (keyString.equals("removeCountryFromLocalityText")){ + config.setRemoveCountryFromLocalityText(Boolean.valueOf(valueString)); + }else if (keyString.equals("getSiblings")){ + config.setGetSiblings(Boolean.valueOf(valueString)); + }else if (keyString.equals("dnaSource")){ + try{ + config.setDnaSoure(URI.create(valueString)); + }catch(Exception e){ + config.setDnaSoure(null); + } }else{ logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString); } + } - } - return config; + } } public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){ Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null); - - config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS)); - - config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN)); - - config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS)); - config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS)); - config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES)); - config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT)); - config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS)); - config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP)); - config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN)); - config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER)); - config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE)); - config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER)); - config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION)); - config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN)); - config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS)); - config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA)); - config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE)); - config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE))); - - return config; + String configString = getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), true); + extractAbcdConfiguratorFromPreferenceString(config, configString); + return config; } - public static void updateAbcdImportConfigurationPreference() { CdmPreferenceCache cache = CdmPreferenceCache.instance(); @@ -1726,79 +1572,37 @@ public class PreferencesUtil implements IPreferenceKeys { public static void resetToDBPreferenceAbcdCOnfigurator(){ Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference(); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen()); - - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences()); + setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), config.toString()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData()); - setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible()); - if (config.getNomenclaturalCode() != null){ - setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey()); - } } + public static boolean isSortTaxaByRankAndName() { + return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME); + } + public static TermOrder getSortNamedAreasInDistributionEditor() { + TermOrder result; + try{ + result = TermOrder.valueOf(getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey())); + }catch (IllegalArgumentException e){ + result = (TermOrder)PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue(); + } + return result; + } + public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) { + setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder); + } - -/** - * @return - */ -public static boolean isSortTaxaByRankAndName() { - - return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME); -} - -/** - * @return - */ -public static String getSortNamedAreasInDistributionEditor() { - - return getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey()); -} - -public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) { - setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder); - -} - -/** - *

- * setPreferredNamedAreasForDistributionEditor - *

- * - * @param saveCheckedElements - * @param saveGrayedElements - */ -public static void setLastSelectedReference( - List lastSelectedReferences) { + public static void setLastSelectedReference( + List lastSelectedReferences) { setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString()); } -/** - *

- * setPreferredNamedAreasForDistributionEditor - *

- * - * @param saveCheckedElements - * @param saveGrayedElements - */ -public static List getLastSelectedReferences() { + public static List getLastSelectedReferences() { //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore(); String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES); @@ -1809,179 +1613,261 @@ public static List getLastSelectedReferences() { return result; } + public static void setPreferredNamedAreasForDistributionEditor( + String saveCheckedElements, String saveGrayedElements, boolean local) { + if (local){ + setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements); -/** - *

- * setPreferredNamedAreasForDistributionEditor - *

- * - * @param saveCheckedElements - * @param saveGrayedElements - */ -public static void setPreferredNamedAreasForDistributionEditor( - String saveCheckedElements, String saveGrayedElements, boolean local) { - if (local){ - setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements); + } + else{ + CdmPreference preference = null; - } - else{ - CdmPreference preference = null; + if (saveCheckedElements == null){ + preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms); - if (saveCheckedElements == null){ - preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms); + if (preference == null){ + return ; + } else{ + setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), + saveCheckedElements); + preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements); + setPreferenceToDB(preference); - if (preference == null){ - return ; + } } else{ - setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), - saveCheckedElements); preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements); setPreferenceToDB(preference); + setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), + saveCheckedElements); } - } else{ - preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements); - setPreferenceToDB(preference); - setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), - saveCheckedElements); - } - } - -} -/** - * @param saveCheckedElements - * @param saveCheckedElements2 - * @param b - */ -public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements, - boolean local, boolean isOverride) { - if (local){ - setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements); - setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride); } - else{ - ICdmRepository controller; - CdmPreference preference = null; - if (saveCheckedElements == null){ - preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies); - - if (preference == null){ - return ; + public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements, + boolean local, boolean isOverride) { + if (local){ + setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements); + setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride); + } + else{ + ICdmRepository controller; + CdmPreference preference = null; + + if (saveCheckedElements == null){ + preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies); + + if (preference == null){ + return ; + } else{ + setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), + saveCheckedElements); + preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements); + preference.setAllowOverride(isOverride); + setPreferenceToDB(preference); + } } else{ - setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), - saveCheckedElements); preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements); preference.setAllowOverride(isOverride); setPreferenceToDB(preference); - } - } else{ - preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements); - preference.setAllowOverride(isOverride); - setPreferenceToDB(preference); - setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), - saveCheckedElements); + setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), + saveCheckedElements); + } } } -} + public static String getPreferredVocabulariesForDistributionEditor(boolean local) { + if (local){ -/** - * @param saveCheckedElements - * @param saveCheckedElements2 - * @param b - */ -public static String getPreferredVocabulariesForDistributionEditor(boolean local) { - if (local){ + String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local); + return pref; + } + else{ + CdmPreference preference = null; + preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies); + if (preference == null){ + return null; + } else{ + return preference.getValue(); + } - String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local); - return pref; + } } - else{ - CdmPreference preference = null; - preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies); - if (preference == null){ + + public static List createUUIDListFromStringPref(String prefKey) { + if (prefKey == null){ return null; - } else{ - return preference.getValue(); } - + String prefValue = PreferencesUtil.getStringValue(prefKey); + if (prefValue == null){ + return null; + } + String[] stringArray = prefValue.split(";"); + List uuidList = new ArrayList(); + for (String uuid: stringArray){ + if (!StringUtils.isBlank(uuid)){ + uuidList.add(UUID.fromString(uuid)); + } + } + return uuidList; } -} -public static List createUUIDListFromStringPref(String prefKey) { - String prefValue = PreferencesUtil.getStringValue(prefKey); - String[] stringArray = prefValue.split(";"); - List uuidList = new ArrayList(); - for (String uuid: stringArray){ - if (!StringUtils.isBlank(uuid)){ - uuidList.add(UUID.fromString(uuid)); + public static boolean getFilterCommonNameReferences(){ + Boolean result = getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES); + if (result == null){ + return false; } + return result; } - return uuidList; -} -public static boolean getFilterCommonNameReferences(){ - return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES); -} + public static void updateDBPreferences() { -/** - * - */ -public static void updateDBPreferences() { - CdmPreference preference = null; - CdmPreferenceCache cache = CdmPreferenceCache.instance(); - cache.getAllTaxEditorDBPreferences(); - //ABCD Configurator + CdmPreferenceCache cache = CdmPreferenceCache.instance(); + cache.getAllTaxEditorDBPreferences(); - updateAbcdImportConfigurationPreference(); + //ABCD Configurator - //Name Details - NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false); -// if (config != null ){ -// if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){ -// setPreferredNameDetailsConfiguration(config, false); -// } -// } + //updateAbcdImportConfigurationPreference(); + //Name Details + NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false); + // if (config != null ){ + // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){ + // setPreferredNameDetailsConfiguration(config, false); + // } + // } + } + public static void setPreferencesToDB(List preferences) { + ICdmRepository controller; + //try{ + if(CdmStore.isActive()){ + controller = CdmStore.getCurrentApplicationConfiguration(); + for (CdmPreference preference: preferences){ + if (preference.getValue() == null && preference.isAllowOverride()){ + controller.getPreferenceService().remove(preference.getKey()); + }else{ + controller.getPreferenceService().set(preference); + } + } + CdmPreferenceCache.instance().getAllTaxEditorDBPreferences(); -} + } + /*}catch(Exception e){ + e.printStackTrace(); + }*/ + } -/** - * @param string - * @param saveCheckedElements - */ -public static void setPreferencesToDB(List preferences) { + /** + * Returns whether the named preference is known. + * @param prefKey the key of the preference + * @return true if the preference is known, false otherwise + */ + public static boolean contains(String prefKey){ + return getPreferenceStore().contains(prefKey(prefKey)); + } - ICdmRepository controller; - try{ - if(CdmStore.isActive()){ - controller = CdmStore.getCurrentApplicationConfiguration(); - for (CdmPreference preference: preferences){ + /** + * + */ + public static TermTree getPreferredFeatureTreeForNameDescription(boolean createNew) { + if(preferredNameFeatureTree != null && !createNew){ + return preferredNameFeatureTree; + } + createPreferredFeatureTreeForNameDescription(); + return preferredNameFeatureTree; - controller.getPreferenceService().set(preference); + } - CdmPreferenceCache.instance().put(preference); + public static void createPreferredFeatureTreeForNameDescription() { + + CdmPreferenceCache cache = CdmPreferenceCache.instance(); + CdmPreference pref = cache.get(PreferencePredicate.NameFeatures.getKey()); + List terms = new ArrayList(); + boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NameFeatures.getKey())); + + List uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey()); + if (uuids != null && !uuids.isEmpty()){ + terms = CdmStore.getTermManager().getTerms(uuids, Feature.class); + } + + + + + if (terms.isEmpty()){ + terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null)); + + } + terms.remove(Feature.PROTOLOGUE()); + if (terms.isEmpty()){ + preferredNameFeatureTree = TermEditorInput.getDefaultNameFeatureTree(); + }else{ + preferredNameFeatureTree = TermTree.NewInstance(terms); + } + + + } + + /** + * @param prefsToDelete + */ + public static void removeFromDB(List prefsToDelete) { + ICdmRepository controller; + //try{ + if(CdmStore.isActive()){ + controller = CdmStore.getCurrentApplicationConfiguration(); + for (CdmPreference preference: prefsToDelete){ + controller.getPreferenceService().remove(preference.getKey()); + } + CdmPreferenceCache.instance().getAllTaxEditorDBPreferences(); } + + } + + /** + * @return + */ + public static TermTree getPreferredFeatureTreeForTaxonDescription(boolean createNew) { + if(preferredTaxonFeatureTree != null && !createNew){ + return preferredTaxonFeatureTree; } - }catch(Exception e){ - e.printStackTrace(); + createPreferredFeatureTreeForTaxonDescription(); + return preferredTaxonFeatureTree; + } -} + public static void createPreferredFeatureTreeForTaxonDescription() { + + CdmPreferenceCache cache = CdmPreferenceCache.instance(); + CdmPreference pref = cache.get(PreferencePredicate.TaxonFeatures.getKey()); + List terms; + boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonFeatures.getKey())); + List 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 nameFeature = nameVocabulary.getTerms(); + terms.removeAll(nameFeature); + + } + if (terms.isEmpty()){ + preferredTaxonFeatureTree = TermEditorInput.getDefaultFeatureTree(); + }else{ + preferredTaxonFeatureTree = TermTree.NewInstance(terms); + } + }