* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.taxeditor.preference;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.URI;
+import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
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.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.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;
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.CdmApplicationState;
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.api.service.config.SecundumForSubtreeConfigurator;
import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.URI;
+import eu.etaxonomy.cdm.facade.DerivedUnitFacadeConfigurator;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
-import eu.etaxonomy.cdm.model.common.IDefinedTerm;
-import eu.etaxonomy.cdm.model.common.ISimpleTerm;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.MarkerType;
-import eu.etaxonomy.cdm.model.common.TermBase;
-import eu.etaxonomy.cdm.model.common.TermType;
-import eu.etaxonomy.cdm.model.description.FeatureTree;
+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.DistributionDescription;
+import eu.etaxonomy.cdm.model.metadata.EnabledComputedDescription;
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.SecReferenceHandlingEnum;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingSwapEnum;
+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.IDefinedTerm;
+import eu.etaxonomy.cdm.model.term.ISimpleTerm;
+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.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoNaturalComparator;
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.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
-import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
+import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
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;
/**
- * <p>
- * PreferencesUtil class.
- * </p>
- *
* @author p.ciardelli
* @author n.hoffmann
* @created 05.12.2008
*/
public class PreferencesUtil implements IPreferenceKeys {
- /**
- *
- */
- public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
+ private final static Logger logger = LogManager.getLogger(PreferencesUtil.class);
- public static final String P2_REPOSITORIES_DELIM = ",";
- public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+ private final static String EDITOR_PREFERENCES_NODE = "eu.etaxonomy.taxeditor";
- private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
+ public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
+ public static final String UPDATE_NAVIGATOR = "update_navigator";
+ public static final String P2_REPOSITORIES_DELIM = ",";
+ public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+ public static final String SUBJECT_DELIM = "/";
+ private static TermTree<Feature> preferredNameFeatureTree;
+ private static TermTree<Feature> preferredTaxonFeatureTree;
- /**
- * <p>
- * getPreferenceStore
- * </p>
- *
- * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
- */
- public static IPreferenceStore getPreferenceStore() {
- return TaxeditorStorePlugin.getDefault().getPreferenceStore();
- }
- private static String prefKey(String name) {
- return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
- }
+ 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 {
+ //check if there exist a node for the predicate
+ if(getEditorPreferences().nodeExists(prefKey.getPredicate())){
+ Preferences predicateNode = getEditorPreferences().node(prefKey.getPredicate());
+ String[] splittedSubject = extractSubjectParts(prefKey.getSubject());
+ //check if the predicate node contains a node for the subject, this should be the last part
+ 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<CdmPreference> getPreference(PreferencePredicate prefPredicate){
+ try {
+ List<CdmPreference> 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;
+ }
+
+ 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;
+
+ }
+
+ private static String prefKey(String name) {
+ return name + "_"+ ((ICdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
+ }
+
+ public static String prefOverrideKey(String name) {
+ return name + "_OVERRIDE_";
+ }
- /**
- * <p>
- * setStringValue
- * </p>
- *
- *
- **/
public static void setStringValue(String name, String value) {
- getPreferenceStore().setValue(prefKey(name), value);
+ if (value != null){
+ getPreferenceStore().setValue(prefKey(name), value);
+ }else{
+ getPreferenceStore().setToDefault(prefKey(name));
+ }
}
- /**
- * <p>
- * setIntValue
- * </p>
- *
- *
- **/
public static void setIntValue(String name, int value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
public static void setBooleanValue(String name, boolean value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
public static void setDoubleValue(String name, double value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setFloatValue
- * </p>
- *
- *
- **/
public static void setFloatValue(String name, float value) {
- getPreferenceStore().setValue(name + ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(), value);
+ getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setFloatValue
- * </p>
- *
- *
- **/
public static void setLongValue(String name, long value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setStringValue
- * </p>
- *
- *
- **/
- public static String getStringValue(String name) {
+ public static String getStringValue(String name, boolean local) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getString(dbSpecific);
- }else{
- return getPreferenceStore().
- getString(name);
+ CdmPreference pref = getDBPreferenceValue(name);
+
+ boolean override = getOverrideForPreference(name);
+
+ if (local || (pref == null && override)|| (pref != null && pref.isAllowOverride() && override)){
+ //local preference
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ return getPreferenceStore().getString(dbSpecific);
+ }
+ }else if (pref != null){
+ //db preference
+ if (pref.getValue() == null){
+ Object result = PreferencePredicate.getByKey(pref.getPredicate()).getDefaultValue();
+ if (result instanceof String){
+ return (String)result;
+ }else{
+ return result != null?result.toString(): null;
+ }
+ }
+ return pref.getValue();
+ }
+ //no override but default value
+ IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof String){
+ return (String)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return pred.getDefaultValue().toString();
+ }
}
+ return null;
+ }
+ public static String getStringValue(String name){
+ return getStringValue(name, false);
}
- /**
- * <p>
- * setIntValue
- * </p>
- *
- *
- **/
- public static int getIntValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getInt(dbSpecific);
- }else{
- return getPreferenceStore().
- getInt(name);
- }
+ private static CdmPreference getDBPreferenceValue(String name) {
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ CdmPreference pref = null;
+ pref = cache.get(name);
+ return pref;
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
- public static boolean getBooleanValue(String name) {
- if (CdmStore.isActive()){
+ public static int getIntValue(String name, boolean local) {
+ CdmPreference pref= getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
+ }
+ Integer result = null;
+ try{
+ result = Integer.parseInt(prefValue);
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not an integer");
+ }
+
+ boolean override = getOverrideForPreference(name);
+ if (local || (pref == null && override) || (pref != null && pref.isAllowOverride() && override)){
String dbSpecific = prefKey(name);
if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getBoolean(dbSpecific);
- }else{
- return getPreferenceStore().
- getBoolean(name);
+ result = getPreferenceStore().getInt(dbSpecific);
+ }
+ }
+ if (result == null){
+ IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Integer){
+ result = (Integer)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ try{
+ result = Integer.valueOf(pred.getDefaultValue().toString());
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a number");
+ result = 0;
+ }
+ }
+ }
+ //if no default value available
+ if (result == null){
+ result = 0;
}
+ }
+ return result;
+ }
+ public static boolean getBooleanValue(String name) {
+ Boolean result = getBooleanValue(name, false);
+ if (result == null){
+ return false;
}else{
-
- return getPreferenceStore().getBoolean(name);
+ return result;
}
-
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
- public static double getDoubleValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getDouble(dbSpecific);
+ public static Boolean getBooleanValue(String name, boolean local) {
+ if (CdmStore.isActive()){
+ CdmPreference pref = getDBPreferenceValue(name);
+ String overrideKey = createPreferenceString(createOverridePreferenceString(name));
+ boolean override = getPreferenceStore().getBoolean(overrideKey);
+ if (local || (pref == null && override)|| (pref != null && pref.isAllowOverride() && override)){
+ //local preference
+ String dbSpecific = prefKey(name);
+ return getPreferenceStore().getBoolean(dbSpecific);
+
+ }else if (pref != null){
+ //db preference is available and override == false
+ if (pref.getValue() == null){
+ Object result = PreferencePredicate.getByKey(pref.getPredicate()).getDefaultValue();
+ if (result instanceof Boolean){
+ return (Boolean)result;
+ }else{
+ return Boolean.valueOf(result.toString());
+ }
+ }
+ return Boolean.valueOf(pref.getValue());
+ }
+ //no override but default value
+ IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Boolean){
+ return (Boolean)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return Boolean.valueOf(pred.getDefaultValue().toString());
+ }
+ }
+ return false;
}else{
- return getPreferenceStore().
- getDouble(name);
+ // no connection to db, use local preference
+ return getPreferenceStore().getBoolean(name);
}
-
}
- /**
- * <p>
- * getFloatValue
- * </p>
- *
- *
- **/
- public static float getFloatValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getFloat(dbSpecific);
- }else{
- return getPreferenceStore().
- getFloat(name);
+ public static float getFloatValue(String name, boolean local) {
+ CdmPreference pref = getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
+ }
+ Float result = null;
+ try{
+ if (prefValue != null){
+ result = Float.parseFloat(prefValue);
+ }
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a float");
}
+ boolean override = getOverrideForPreference(name);
+
+ if (local || pref == null || (pref.isAllowOverride() && override)){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ result = getPreferenceStore().getFloat(dbSpecific);
+ }else{
+ IPreferencePredicate<?> pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Float){
+ return (float)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return Float.valueOf(pred.getDefaultValue().toString());
+ }
+ }
+ return 0;
+ }
+ }
+ return result;
}
- /**
- * <p>
- * getLongValue
- * </p>
- *
- *
- **/
- public static long getLongValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getLong(dbSpecific);
- }else{
- return getPreferenceStore().
- getLong(name);
- }
- }
-
-
- /**
- * <p>
- * setPreferredNomenclaturalCode
- * </p>
- *
- * @param preferredCode
- * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
- * object.
- */
- public static CdmPreference setPreferredNomenclaturalCode(
- String preferenceKey, boolean local) {
- if (local){
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preferenceKey);
- }
- else{
- ICdmRepository controller;
- controller = CdmStore.getCurrentApplicationConfiguration();
- if (controller == null){
+ public static CdmPreference setPreferredNomenclaturalCode(
+ String preferenceValue, boolean local) {
+ if (local){
+ setStringValue(PreferencePredicate.NomenclaturalCode.getKey(),
+ 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 (preferenceKey == null){
- preference = controller.getPreferenceService().find(key);
- if (preference == null){
- return null;
- } else{
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preference.getValue());
- setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
- return preference;
- }
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceKey);
- controller.getPreferenceService().set(preference);
-
- }
- }
- 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(PreferencePredicate.NomenclaturalCode.getKey(),
+ preference.getValue());
- }
+ return preference;
+ }
+ } else{
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
+ controller.getPreferenceService().set(preference);
- public static NomenclaturalCode getPreferredNomenclaturalCode(){
- if (getBooleanValue(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
- return getPreferredNomenclaturalCode(true);
- } else{
- return getPreferredNomenclaturalCode(false);
+ }
}
- }
+ return null;
+ }
- /**
- * <p>
- * getPreferredNomenclaturalCode
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
- */
- public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
-
- CdmPreference pref = null;
- if (!useLocal){
- pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
- }
+ public static void setPreferredNomenclaturalCode(
+ CdmPreference preference) {
- String preferredCode;
- if(pref == null){
- preferredCode = getStringValue(
- PREFERRED_NOMENCLATURAL_CODE_KEY);
+ ICdmRepository controller;
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ if (controller == null){
+ return;
+ }
- }else{
- preferredCode = pref.getValue();
- }
+ 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);
+ }
+ }
- return getPreferredNomenclaturalCode(preferredCode);
+ public static NomenclaturalCode getPreferredNomenclaturalCode() {
- }
+ String nomString = getStringValue(PreferencePredicate.NomenclaturalCode.getKey());
+ return getPreferredNomenclaturalCode(nomString);
+ }
- /**
- * <p>
- * getPreferredNomenclaturalCode
- * </p>
- *
- * @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(){
- if (getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) && getBooleanValue(SHOW_TAXON_ASSOCIATIONS_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_TAXON_ASSOCIATIONS);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
+ public static boolean isShowTaxonAssociations(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
+ return result;
+ }
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
- }
+ public static boolean isShowLifeForm(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
+ return result;
}
- public static boolean isShowLifeForm(){
- if (getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) && getBooleanValue(SHOW_LIFE_FORM_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_LIFE_FORM);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
+ public static boolean isDeterminationOnlyForFieldUnits(){
+ boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
+ return result;
+ }
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
- }
+ public static boolean isCollectingAreaInGeneralSection(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
+ return result;
}
- public static boolean isDeterminationOnlyForFieldUnits(){
- if (getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) && getBooleanValue(DETERMINATIONS_ONLY_FOR_FIELDUNITS_ALLOW_OVERRIDE)) {
- return getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
+ public static CdmPreference getPreferenceFromDB(IPreferencePredicate<?> predicate){
+ ICdmRepository controller;
+ CdmPreference pref = null;
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
+ try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
+ pref = controller.getPreferenceService().find(key);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
}
+
+ return pref;
}
- public static boolean isCollectingAreaInGeneralSection(){
- if (getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) && getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
+ public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate<?> predicate){
+ ICdmRepository controller;
+ List<CdmPreference> prefs = null;
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
+ try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
+ prefs = controller.getPreferenceService().list(predicate);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
}
- }
- public static boolean isShowSimpleDetailsView(){
- if (getBooleanValue(OVERRIDE_NAME_DETAILS) && getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)) {
- return getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION);
- } else{
- CdmPreference pref = getPreferenceFromDB(EditorPreferencePredicate.NameDetailsView);
+ return prefs;
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
- }
}
+ 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(IPreferencePredicate predicate){
+ public static CdmPreference getPreferenceFromDB(PrefKey key){
ICdmRepository controller;
CdmPreference pref = null;
try{
if(CdmStore.isActive()){
controller = CdmStore.getCurrentApplicationConfiguration();
- PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
pref = controller.getPreferenceService().find(key);
}
}catch(Exception e){
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){
e.printStackTrace();
}
-
}
+ public static String getPreferredDefaultLangugae(){
+ String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR, true);
+ 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(){
- boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
+ public static Language getPreferredDefaultLanguage(){
+
+ String prop = System.getProperty("osgi.nl");
+ if (prop.startsWith("de")) {
+ return Language.GERMAN();
+ }else {
+ return Language.ENGLISH();
+ }
+// String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR, true);
+// if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
+// if (preferredLanguage.equals(Language.uuidEnglish.toString())) {
+// return Language.ENGLISH();
+// }else if (preferredLanguage.equals(Language.uuidGerman.toString())) {
+// return Language.GERMAN();
+// }else {
+// return Language.ENGLISH();
+// }
+// }
+// return Language.getDefaultLanguage();
+ }
+
+ public static boolean isShowMediaPreview(){
+ boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW, true);
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<FieldMatcher> 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;
- }
+ /**
+ * 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, true)) {
+ 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), true);
+ MatchMode matchMode = MatchMode.valueOf(matchModeName);
+ try {
+ matchStrategy.setMatchMode(fieldName, matchMode);
+ } catch (MatchException e) {
+ MessagingUtils.error(PreferencesUtil.class, e);
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * 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);
- }
+ return matchStrategy;
+ }
+ return getDefaultMatchStrategy(clazz);
+ }
- /**
- * <p>
- * getDateFormatPattern
- * </p>
- *
- * @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;
- }
+ /**
+ * 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);
- /**
- * <p>
- * addTermToPreferredTerms
- * </p>
- *
- * @param term
- * a T object.
- * @param <T>
- * a T object.
- */
- public static <T extends TermBase> void addTermToPreferredTerms(T term) {
-
- // VocabularyEnum vocabulary =
- // VocabularyEnum.getVocabularyEnum(term.getClass());
- //
- // getPreferenceStore().setValue(getPreferenceKey(term),
- // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
- //
- // firePreferencesChanged(term.getClass());
- }
+ List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
- /**
- * 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;
- }
+ for (FieldMatcher fieldMatcher : fieldMatchers) {
+ String fieldName = fieldMatcher.getPropertyName();
+ setStringValue(
+ getMatchStrategyFieldName(className, fieldName),
+ fieldMatcher.getMatchMode().name());
+ }
+ }
- /**
- * 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;
- }
+ /**
+ * 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;
+ }
- /**
- * 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;
- }
+ /**
+ * Construct a unique key using the CdmBase object's uuid
+ */
+ public static String getPreferenceKey(ISimpleTerm<?> simpleTerm) {
+ simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
+ String key = simpleTerm.getClass().getName().concat(".")
+ .concat(simpleTerm.getUuid().toString());
+ if (key.contains("javassist")) { //Note by AM (2022-06): javassist is not used anymore, instead hibernate uses bytebuddy which is not contained in class names so this logging will not work anymore
+ 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;
- }
+ /**
+ * Construct a unique key using the CdmBase object's uuid
+ */
+ public static String getPreferenceKey(IDefinedTerm definedTerm) {
+ definedTerm = HibernateProxyHelper.deproxy(definedTerm);
+ String key = definedTerm.getClass().getName().concat(".")
+ .concat(definedTerm.getUuid().toString());
+ if (key.contains("javassist")) { //Note by AM (2022-06): javassist is not used anymore, instead hibernate uses bytebuddy which is not contained in class names so this logging will not work anymore
+ MessagingUtils.warn(PreferencesUtil.class,
+ "Trying to persist a preference based on a proxy class.");
+ }
+ return key;
+ }
- /**
- * 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;
- }
+ /**
+ * 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(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA): true);
+ configurator.setDoSynonyms(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS): true);
+ configurator.setDoNamesWithoutTaxa(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES): true);
+ configurator.setDoTaxaByCommonNames(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES): true);
+ configurator.setDoIncludeAuthors(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS): false);
+ configurator.setIncludeUnpublished(PreferencesUtil.getPreferenceStore().contains(IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED)? PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED): true);
+ //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
+
+ 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());
- }
+ /**
+ * 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.setIncludeUnpublished(true);
+ configurator.setDoIncludeAuthors(false);
+ 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;
+ }
- /**
- * <p>
- * firePreferencesChanged
- * </p>
- *
- * @param clazz
- * a {@link java.lang.Class} object.
- */
- public static void firePreferencesChanged(Class clazz) {
- getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
- null, clazz);
- }
+ /**
+ * 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());
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS,
+ configurator.isDoIncludeAuthors());
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_UNPUBLISHED,
+ configurator.isIncludeUnpublished());
+ }
- public static String createPreferenceString(String property){
- return prefKey(property);
+ public static void firePreferencesChanged(Class clazz) {
+ getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
+ null, clazz);
+ }
- }
+ public static void firePreferencesChangedForNavigator() {
+ getPreferenceStore().firePropertyChangeEvent(UPDATE_NAVIGATOR,
+ null, null);
+ }
- /**
- * 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(EditorPreferencePredicate.DistributionEditorActivated.getKey()), true);
- getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
- getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfStatus.getKey()), EditorPreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
-
-
- //Name Details
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_HYBRID), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_LSID), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAMECACHE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_RANK), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION), true);
- //Navigator preferences
- getPreferenceStore().setDefault(createPreferenceString(SORT_NODES), NavigatorOrderEnum.RankAndNameOrder.getKey());
-
- getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
- //override db preferences
- getPreferenceStore().setDefault(createPreferenceString(ABCD_IMPORT_OVERRIDE), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN_OVERRIDE), false);
- getPreferenceStore().setDefault(createPreferenceString(OVERRIDE_NAME_DETAILS), false);
- getPreferenceStore().setDefault(createPreferenceString(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE), false);
-
- getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_TAXONNODE_WIZARD), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAMESPACE_IN_SOURCE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_ID_IN_SOURCE), true);
- getPreferenceStore().setDefault(createPreferenceString(DISABLE_MULTI_CLASSIFICATION), false);
- getPreferenceStore().setDefault(createPreferenceString(DISABLE_SEC), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SEC_DETAILS), true);
- }
- /**
- * <p>
- * checkNomenclaturalCode
- * </p>
- */
- public static void checkNomenclaturalCode() {
- // First time Editor is opened, no nomenclatural code has been set
- if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
- PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
- }
+ public static String createPreferenceString(String property){
+ return prefKey(property);
+ }
+ public static String createOverridePreferenceString(String property){
+ return prefOverrideKey(property);
+ }
+ public static boolean getOverrideForPreference(String preferenceString){
+ return PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(preferenceString), true);
+ }
+ /**
+ * Set default values for preferences
+ */
+ public static void setDefaults() {
+
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.EditMapServiceAccessPoint.getKey()),
+ "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);
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_WITH_AUTHORS, false);
+
+ //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.NameDetailsView.getKey())), false);
+ 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()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.SearchForIdentifierAndTitleCache.getKey()), Boolean.valueOf(PreferencePredicate.SearchForIdentifierAndTitleCache.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.SearchForIdentifierAndTitleCache.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.SearchForIdentifierAsDefault.getKey()), Boolean.valueOf(PreferencePredicate.SearchForIdentifierAsDefault.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.SearchForIdentifierAsDefault.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifier.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), false);
+ }
+
+ 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;
+ public static void setNomenclaturalCodePreferences(){
+ ICdmRepository controller;
controller = CdmStore.getCurrentApplicationConfiguration();
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
CdmPreference preference = null;
if (preference == null){
return;
}
- setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
+// setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
int index = StringUtils.lastIndexOf(preference.getValue(), ".");
UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+ setStringValue(PreferencePredicate.NomenclaturalCode.getKey(),
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
+// }
+// }
- 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(PreferencePredicate.EditMapServiceAccessPoint.getKey());
+ }
- /**
- * <p>
- * getMapServiceAccessPoint
- * </p>
- *
- * @return a {@link java.lang.String} object.
- */
- 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;
+ }
- /**
- * <p>
- * shouldConnectAtStartUp
- * </p>
- *
- * @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;
- }
+ public static TermTree<?> getDefaultFeatureTreeForTextualDescription() {
+ String uuidString = getStringValue(
+ FEATURE_TREE_DEFAULT_TEXT, true);
+ if (StringUtils.isBlank(uuidString)) {
+ return null;
+ }
+ TermTree<?> tree = CdmStore.getService(
+ ITermTreeService.class).load(UUID.fromString(uuidString));
- /**
- * <p>
- * getDefaultFeatureTreeForTextualDescription
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
- */
- public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
- String uuidString = getStringValue(
- FEATURE_TREE_DEFAULT_TEXT);
- return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
- IFeatureTreeService.class).load(UUID.fromString(uuidString));
- }
+ if (tree == null || tree.getId() == 0) {
+ return null;
+ }
+ return tree;
+ }
- /**
- * <p>
- * getDefaultFeatureTreeForStructuredDescription
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.description.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));
- }
+ public static TermTree<?> getDefaultFeatureTreeForStructuredDescription() {
+ String uuidString = getStringValue(
+ FEATURE_TREE_DEFAULT_STRUCTURE, true);
+ return StringUtils.isBlank(uuidString) ? null : CdmStore.getService(
+ ITermTreeService.class).load(UUID.fromString(uuidString));
+ }
- /**
- * <p>
- * setSortRanksHierarchichally
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static void setSortRanksHierarchichally(boolean selection) {
- setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
- }
+ public static void setSortRanksHierarchichally(boolean selection) {
+ setBooleanValue(PreferencePredicate.SortRanksHierarchichally.getKey(), selection);
+ }
- /**
- * <p>
- * getSortRanksHierarchichally
- * </p>
- *
- * @return a boolean.
- */
- public static boolean getSortRanksHierarchichally() {
- return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
- }
+ public static boolean getSortRanksHierarchichally() {
+ return getBooleanValue(PreferencePredicate.SortRanksHierarchichally.getKey());
+ }
- public static boolean isMultilanguageTextEditingCapability() {
- return getBooleanValue(
- MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
- }
+ public static boolean isMultilanguageTextEditingCapability() {
+ return getBooleanValue(
+ PreferencePredicate.MultiLanguageTextEditing.getKey());
+ }
- public static Language getGlobalLanguage() {
+ public static Language getGlobalLanguage() {
+ String languageUuidString = getStringValue(
+ PreferencePredicate.TermLanguage.getKey(), true);
- String languageUuidString = getStringValue(
- GLOBAL_LANGUAGE_UUID);
+ CdmPreference dbPref = getDBPreferenceValue(PreferencePredicate.TermLanguage.getKey());
- if(!CdmStore.isActive()) {
+ if (dbPref == null || (dbPref != null && dbPref.isAllowOverride() && getOverrideForPreference(PreferencePredicate.TermLanguage.getKey()))) {
+ if (CdmUtils.isBlank(languageUuidString)) {
+ return Language.getDefaultLanguage();
+ }else {
+ return Language.getLanguageFromUuid(UUID.fromString(languageUuidString));
+ }
+ }else {
+ languageUuidString = dbPref.getValue();
+ }
+ UUID languageUuid = UUID.fromString(languageUuidString);
+ Language language = (Language)CdmApplicationState.getTermProxy().load(languageUuid);
+ if (language != null){
+ return language;
+ }else{
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<MarkerType, Boolean> getEditMarkerTypePreferences() {
- List<MarkerType> markerTypes = CdmStore.getTermManager()
- .getPreferredTerms(MarkerType.class);
-
- Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
+ public static void setGlobalLanguage(Language language) {
+ if(language != null) {
+ setStringValue(PreferencePredicate.TermLanguage.getKey(),language.getUuid().toString());
+ CdmStore.setDefaultLanguage(language);
+ }else {
+ CdmStore.setDefaultLanguage(Language.getDefaultLanguage());
+ }
+ }
- for (MarkerType markerType : markerTypes) {
- String name = getMarkerTypeEditingPreferenceKey(markerType);
- Boolean value = getBooleanValue(name);
+ public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
+ List<MarkerType> markerTypes = CdmStore.getTermManager()
+ .getPreferredTerms(MarkerType.class);
- result.put(markerType, value);
- }
+ Map<MarkerType, Boolean> result = new HashMap<>();
- return result;
- }
+ for (MarkerType markerType : markerTypes) {
+ String name = getMarkerTypeEditingPreferenceKey(markerType);
+ Boolean value = getBooleanValue(name);
+ result.put(markerType, value);
+ }
- /**
- * @param markerTypeEditingMap
- */
- public static void setEditMarkerTypePreferences(
- Map<MarkerType, Boolean> markerTypeEditingMap) {
- for (MarkerType markerType : markerTypeEditingMap.keySet()) {
- String name = getMarkerTypeEditingPreferenceKey(markerType);
- setBooleanValue(name,
- markerTypeEditingMap.get(markerType));
- }
+ return result;
+ }
- }
+ public static void setEditMarkerTypePreferences(
+ Map<MarkerType, Boolean> 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;
- }
+ private static String getMarkerTypeEditingPreferenceKey(
+ MarkerType markerType) {
+ markerType = HibernateProxyHelper.deproxy(markerType);
+ return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
+ }
- /**
- * <p>
- * setEditMarkerTypePreference
- * </p>
- *
- * @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);
- }
+ 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;
- }
+ 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. <b>This method is only used to set the default language for Taxonomic Editor.</b>
- *
- * @param setLanguage 0 is for german and 1 for english.
- * @throws IOException
- */
- public void writePropertyToConfigFile(int setLanguage) throws IOException {
+ /**
+ * This method will write language properties to the config.ini located in the configuration folder
+ * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
+ *
+ * @param setLanguage 0 is for german and 1 for english.
+ * @throws IOException
+ */
+ public static 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
if(file == null){
throw new IOException();
}
- Properties properties = load(file.getAbsolutePath()+"/config.ini");
+ Properties properties;
+ properties = load(file.getAbsolutePath()+"/config.ini");
switch(setLanguage){
case 0:
properties.setProperty("osgi.nl", "de");
- setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
+ setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, Language.uuidGerman.toString());
break;
case 1:
properties.setProperty("osgi.nl", "en");
- setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
+ setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, Language.uuidEnglish.toString());
break;
default:
break;
}
save(file+"/config.ini", properties);
+
+
}
/**
* @return
* @throws IOException
*/
- private Properties load(String filename) throws IOException {
+ private static Properties load(String filename) throws IOException {
FileInputStream in = new FileInputStream(filename);
Properties prop = new Properties();
prop.load(in);
* @param properties
* @throws IOException
*/
- private void save(String filename, Properties properties) throws IOException{
+ private static void save(String filename, Properties properties) throws IOException{
FileOutputStream fos = new FileOutputStream(filename);
properties.store(fos, "");
fos.close();
/**
* Retrieves a list of previously saved P2 repositories
- *
- * @return
*/
public static List<MetadataRepositoryElement> getP2Repositories() {
List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
- String p2ReposPref = getStringValue(P2_REPOSITORY_LIST);
+ String p2ReposPref = getStringValue(P2_REPOSITORY_LIST, true);
if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
continue;
}
boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
- MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
+ MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri.getJavaUri(), true);
mre.setNickname(nickname);
mre.setEnabled(enabled);
p2Repos.add(mre);
}
}
-
-
-
- /**
- * @param orderActivated
- */
public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
- setStringValue(SORT_NODES, 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(SORT_NODES));
-
+ return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedNaturally() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.NaturalOrder);
-
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedByName() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
-
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedByNameAndRank() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.RankAndNameOrder);
-
}
- /**
- * <p>
- * setStoreNavigatorState
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static boolean isStoreNavigatorState() {
- return getBooleanValue(RESTORE_NAVIGATOR_STATE);
- }
+ public static Comparator<TaxonNodeDto> getNodeComparator() {
+ Comparator<TaxonNodeDto> comparator;
+ NavigatorOrderEnum orderValue = NavigatorOrderEnum.RankAndNameOrder;
+ try{
+ orderValue = PreferencesUtil.getSortNodes();
+ }catch(IllegalArgumentException e){
- /**
- * <p>
- * setStoreNavigatorState
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static void setStoreNavigatorState(boolean selection) {
- setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
+ }
+ if (orderValue.equals(NavigatorOrderEnum.NaturalOrder)){
+ comparator = new TaxonNodeDtoNaturalComparator();
+ } else if (orderValue.equals(NavigatorOrderEnum.AlphabeticalOrder)){
+ comparator = new TaxonNodeDtoByNameComparator();
+ }else {
+ comparator = new TaxonNodeDtoByRankAndNameComparator();
+ }
+ return comparator;
}
- /**
- * @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);
}
+
public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
}
- /**
- * @return
- */
public static boolean isShowIdInVocabularyInChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
return true;
}else{
}
}
public static boolean isShowSymbol1InChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
return true;
}else{
return false;
}
- }
+ }
public static boolean isShowSymbol2InChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
return true;
}else{
return false;
}
- }
+ }
+
public static void setAreaDisplayInChecklistEditor(String selection) {
- setStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
+ setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
}
- public static void setOwnDescriptionForChecklistEditor(boolean selection) {
- setBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
+ public static void setDescriptionForChecklistEditor(DistributionDescription selection) {
+ setStringValue(PreferencePredicate.DescriptionForDistributionEditor.getKey(), selection.getKey());
}
- public static boolean isOwnDescriptionForChecklistEditor() {
- return getBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
+ public static DistributionDescription getDescriptionForChecklistEditor() {
+ String str = getStringValue(PreferencePredicate.DescriptionForDistributionEditor.getKey());
+ DistributionDescription result = null;
+ try {
+ result = DistributionDescription.byKey(str);
+ }catch(IllegalArgumentException e) {
+ result = (DistributionDescription)PreferencePredicate.DescriptionForDistributionEditor.getDefaultValue();
+ }
+ return result;
}
- /**
- * @return
- */
- public static String displayStatusInChecklistEditor() {
- return getStringValue(EditorPreferencePredicate.DisplayOfStatus.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;
+ }
+
+ public static TermDisplayEnum displayStatusInChecklistEditor() {
+ TermDisplayEnum result;
+ try{
+ result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfStatus.getKey()));
+ }catch (IllegalArgumentException e){
+ result = ((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue());
+ }
+ return result;
}
+
public static void setDisplayStatusInChecklistEditor(String selection) {
- setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), selection);
+ setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
}
- /**
- * @return
- */
public static boolean isShowRankInChecklistEditor() {
- return getBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey());
+ return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
}
+
public static void setShowRankInChecklistEditor(boolean selection) {
- setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
+ setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
}
- /**
- * @param object
- * @param b
- * @return
- */
public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
- NameDetailsConfigurator config = new NameDetailsConfigurator(true);
-
+ NameDetailsConfigurator config = new NameDetailsConfigurator();
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
CdmPreference preference = null;
-
+ String value;
if (!local) {
- preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
+ preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
if (preference == null){
return null;
}
- setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
-
+ // setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
+ value = preference.getValue();
+ config.setAllowOverride(preference.isAllowOverride());
//the preference value is build like this:
//<section1>:true;<section2>:false....
+ }else{
+ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
+ }
+ if (value!= null){
+ fillNameDetailsConfigurator(config, value);
+
+
+ }else {
+ return null;
+ }
+ return config;
+ }
- String value = preference.getValue();
- String [] sections = value.split(";");
- Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
- String[] sectionValues;
- for (String sectionValue: sections){
+ public static void fillNameDetailsConfigurator(NameDetailsConfigurator config, String value) {
+ String [] sections = value.split(";");
+ Map<String, Boolean> sectionMap = new HashMap<>();
+ String[] sectionValues;
+ for (String sectionValue: sections){
+ if (sectionValue.contains(":")){
sectionValues = sectionValue.split(":");
sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
}
- config.setAllowOverride(preference.isAllowOverride());
- config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
-
- // getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
- // (getValue(sectionMap, "taxon")));
- config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
-
- config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecEnabled"));
- config.setSecEnabled(getValue(sectionMap, "taxon.SecDetails"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
- // (getValue(sectionMap, "lsid")));
- config.setLSIDActivated(getValue(sectionMap, "lsid"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
- // (getValue(sectionMap, "nc")));
- config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
- // (getValue(sectionMap, "ap")));
- config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
- // (getValue(sectionMap, "rank")));
- config.setRankActivated(getValue(sectionMap, "rank"));
-
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
- // (getValue(sectionMap, "atomisedEpithets")));
- config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
- // (getValue(sectionMap,"author")));
- config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
- // (getValue(sectionMap, "nomRef")));
- config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
- // (getValue(sectionMap, "nomStat")));
- config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
-
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
- // (getValue(sectionMap,"protologue")));
- config.setProtologueActivated(getValue(sectionMap,"protologue"));
+ }
+ for (Field field: config.getClass().getDeclaredFields()){
+ try {
+ config.getClass().getDeclaredField(field.getName()).set(config, getValue(sectionMap, field.getName()));
+ } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
+ | SecurityException e) {
+ logger.debug(e.getMessage());
+ }
+ }
+ }
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
- // (getValue(sectionMap,"typeDes")));
- config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
+ public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
+ NameDetailsConfigurator config = new NameDetailsConfigurator();
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
- // (getValue(sectionMap,"nameRelation")));
- config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
+ String value;
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
- // (getValue(sectionMap, "hybrid")));
- config.setHybridActivated(getValue(sectionMap,"hybrid"));
- }else{
- config.setSimpleDetailsViewActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION));
- config.setTaxonSectionActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON));
- config.setSecDetailsActivated(getBooleanValue(SHOW_SEC_DETAILS));
- config.setSecEnabled(getBooleanValue(DISABLE_SEC));
- config.setLSIDActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID));
- config.setNomenclaturalCodeActived(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
- config.setAppendedPhraseActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
- config.setRankActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK));
- config.setAtomisedEpithetsActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
- config.setAuthorshipSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
- config.setNomenclaturalReferenceSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
- config.setNomenclaturalStatusSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
- config.setProtologueActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
- config.setTypeDesignationSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
- config.setNameRelationsSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
- config.setHybridActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID));
+ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
+ if (value != null){
+ fillNameDetailsConfigurator(config, value);
+ }else {
+ return null;
}
return config;
}
- /**
- * @param object
- * @param b
- * @return
- */
public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
CdmPreference preference = null;
if (!local) {
- preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NameDetailsView, config.toString());
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView, config.toString());
setPreferenceToDB(preference);
}
- //also add to local preferences
- setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION, config.isSimpleDetailsViewActivated());
- setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
- setBooleanValue(SHOW_SEC_DETAILS, config.isSecDetailsActivated());
- setBooleanValue(DISABLE_SEC, config.isSecEnabled());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, config.isNomenclaturalCodeActived());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, config.isAppendedPhraseActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, config.isAtomisedEpithetsActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, config.isAuthorshipSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, config.isNomenclaturalReferenceSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, config.isNomenclaturalStatusSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, config.isProtologueActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, config.isTypeDesignationSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, config.isNameRelationsSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID, config.isHybridActivated());
-
+ else{
+ setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
+ }
}
private static Boolean getValue(Map<String, Boolean> 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;
+ }
+ }
- }
+ public static void extractSecundumForSubtreeConfiguratorFromPreferenceString(SecundumForSubtreeConfigurator config,
+ String configString) {
+ if(configString != null){
+ String[] configArray = configString.split(";");
+ for (String configItem: configArray){
+ String[] keyValue = configItem.split(":");
+ String keyString = keyValue[0];
+ String valueString = null;
+ if (keyValue.length>1){
+ valueString = keyValue[1];
+ if (keyValue.length>2){
+ for (int index = 2; index< keyValue.length; index++){
+ valueString += ":"+ keyValue[index];
+ }
+ }
+ }
+ if (keyString.equals("includeAcceptedTaxa")){
+ config.setIncludeAcceptedTaxa(Boolean.valueOf(valueString));
+ }else if (keyString.equals("includeSynonyms")){
+ config.setIncludeSynonyms(Boolean.valueOf(valueString));
+ }else if (keyString.equals("includeSharedTaxa")){
+ config.setIncludeSharedTaxa(Boolean.valueOf(valueString));
+ }else if (keyString.equals("includeProParteSynonyms")){
+ config.setIncludeProParteSynonyms(Boolean.valueOf(valueString));
+ }else if (keyString.equals("includeMisapplications")){
+ config.setIncludeMisapplications(Boolean.valueOf(valueString));
+ }else if (keyString.equals("overwriteExisting")){
+ config.setOverwriteExisting(Boolean.valueOf(valueString));
+ }else if (keyString.equals("emptySecundumDetail")){
+ config.setEmptySecundumDetail(Boolean.valueOf(valueString));
+ }else{
+ logger.debug("This key of the set secundum configurator needs to be added to the transformer: " + keyString);
+ }
+ }
+ }
+ }
- /**
- * <p>
- * setAbcdConfigurator
- * </p>
- *
- * @param preferredConfiguration
- * a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
- * object.
- */
public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
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){
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));
- }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
- config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
+ }else if (keyString.equals("addIndividualsAssociations")){
+ config.setAddIndividualsAssociations(Boolean.valueOf(valueString));
+ }else if (keyString.equals("addDeterminations")){
+ config.setAddDeterminations(Boolean.valueOf(valueString));
}else if (keyString.equals("reuseExistingTaxaWhenPossible")){
config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
}else if (keyString.equals("ignoreAuthorship")){
}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("classificationUUID")){
+ if (valueString != null){
+ config.setClassificationUuid(UUID.fromString(valueString));
+ }
+ }else if (keyString.equals("classificationName")){
+ config.setClassificationName(valueString);
+ }else if (keyString.equals("dnaSource")){
+ try{
+ if (StringUtils.isNotBlank(valueString)){
+ 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);
+ return getLocalAbcdImportConfigurator(true);
+ }
- 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)));
+ public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(boolean skipCheckOverride){
+ Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
+ CdmPreference pref = CdmPreferenceCache.instance().get(PreferencePredicate.AbcdImportConfig.getKey());
+ if (pref == null || pref.isAllowOverride()){
+ String configString = PreferencesUtil.getStringValue(PreferencePredicate.AbcdImportConfig.getKey());
+ if (StringUtils.isBlank(configString)){
+ configString = getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), skipCheckOverride);
+ extractAbcdConfiguratorFromPreferenceString(config, configString);
+ if (config.getNomenclaturalCode() == null){
+ config.setNomenclaturalCode(getPreferredNomenclaturalCode());
+ }
+ }else{
+ config = Abcd206ImportConfigurator.NewInstance(null, null);
+ PreferencesUtil.extractAbcdConfiguratorFromPreferenceString(config, configString);
+ }
+ }else{
+ extractAbcdConfiguratorFromPreferenceString(config, pref.getValue());
+ }
- return config;
+ return config;
}
+ public static Abcd206ImportConfigurator getLastUsedAbcdImportConfigurator(){
+ Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
+
+ String configString = PreferencesUtil.getStringValue(IPreferenceKeys.LAST_USED_ABCD_CONFIG, true);
+ if (configString != null){
+ extractAbcdConfiguratorFromPreferenceString(config, configString);
+ if (config != null){
+ if (config.getNomenclaturalCode() == null){
+ config.setNomenclaturalCode(getPreferredNomenclaturalCode());
+ }
+ }
+ }else{
+ config = PreferencesUtil.getLocalAbcdImportConfigurator(false);
+ }
+
+ return config;
+ }
public static void updateAbcdImportConfigurationPreference() {
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
- Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
- ICdmRepository controller;
- controller = CdmStore.getCurrentApplicationConfiguration();
- PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
- CdmPreference preference = null;
- if (controller == null){
- return ;
- }
- preference = controller.getPreferenceService().find(key);
- boolean allowOverride = true;
- if (preference != null && !preference.isAllowOverride()){
- allowOverride = false;
- }
- if (!getBooleanValue(IPreferenceKeys.ABCD_IMPORT_OVERRIDE) || !allowOverride){
- resetToDBPreferenceAbcdCOnfigurator();
+ CdmPreference pref = cache.findBestMatching(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig));
+ if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
+ resetToDBPreferenceAbcdCOnfigurator();
}
}
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());
+ setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), config.toString());
+ }
- 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());
+ public static boolean isSortTaxaByRankAndName() {
+ return getBooleanValue(PreferencePredicate.SortTaxaByRankAndName.getKey());
+ }
- 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 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);
+ }
- /**
- *
- */
- public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
- NameDetailsConfigurator config = new NameDetailsConfigurator(true);
- if (local){
- config.setSimpleDetailsViewActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
- config.setAppendedPhraseActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
- config.setAtomisedEpithetsActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
- config.setAuthorshipSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
- config.setLSIDActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
- config.setNameApprobiationActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
- config.setNameCacheActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
- config.setNameRelationsSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
- config.setNomenclaturalCodeActived(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
- config.setNomenclaturalStatusSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
- config.setNomenclaturalReferenceSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
- config.setProtologueActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
- config.setRankActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
- config.setTaxonSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
- config.setTypeDesignationSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
- config.setHybridActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
- }else{
-
- }
-
- return config;
- }
-
-
- public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
- setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
- config.isSimpleDetailsViewActivated());
- setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
- config.isNomenclaturalCodeActived());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
- config.isNameCacheActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
- config.isAppendedPhraseActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
- config.isAtomisedEpithetsActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
- config.isAuthorCacheActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
- config.isAuthorshipSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
- config.isNomenclaturalReferenceSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
- config.isNomenclaturalStatusSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
- config.isProtologueActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
- config.isTypeDesignationSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
- config.isNameRelationsSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
- config.isHybridActivated());
-
- }
-
-/**
- * @return
- */
-public static boolean isSortTaxaByRankAndName() {
-
- return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
-}
-
-/**
- * @return
- */
-public static boolean isSortNamedAreaByOrderInVocabulary() {
-
- return getBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey());
-}
-
-public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
- setBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey(), isSortByVocabularyOrder);
-
-}
-
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @param saveCheckedElements
- * @param saveGrayedElements
- */
-public static void setLastSelectedReference(
- List<String> lastSelectedReferences) {
+ public static void setLastSelectedReference(
+ List<String> lastSelectedReferences) {
- setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
+ setStringValue(IPreferenceKeys.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
}
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @param saveCheckedElements
- * @param saveGrayedElements
- */
-public static List<String> getLastSelectedReferences() {
+ public static List<String> getLastSelectedReferences() {
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
- String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
+ String lastSelected = getStringValue(IPreferenceKeys.LAST_SELECTED_REFERENCES, true);
List<String> result = new ArrayList<>();
if (!StringUtils.isBlank(lastSelected)){
Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
return result;
}
-
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @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;
-
- if (saveCheckedElements == null){
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
-
- if (preference == null){
- return ;
+ public static void setPreferredNamedAreasForDistributionEditor(
+ String saveCheckedElements, String saveGrayedElements, boolean local) {
+ if (local){
+ setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
+ }
+ else{
+ CdmPreference preference = null;
+
+ 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);
+ }
} 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) {
- if (local){
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
- }
- 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{
+ 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);
+ setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
+ saveCheckedElements);
}
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
- setPreferenceToDB(preference);
- 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());
- return pref;
+ 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();
+ }
+ }
}
- else{
- CdmPreference preference = null;
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
- if (preference == null){
+
+ public static List<UUID> createUUIDListFromStringPref(String prefKey, boolean local) {
+ if (prefKey == null){
return null;
- } else{
- return preference.getValue();
}
-
+ String prefValue = PreferencesUtil.getStringValue(prefKey, local);
+ if (prefValue == null){
+ return null;
+ }
+ List<UUID> uuidList = createUuidList(prefValue);
+ return uuidList;
}
+ public static List<UUID> createUuidList(String prefValue) {
+ String[] stringArray = prefValue.split(";");
+ List<UUID> uuidList = new ArrayList<>();
+ for (String uuid: stringArray){
+ if (!StringUtils.isBlank(uuid)){
+ uuidList.add(UUID.fromString(uuid));
+ }
+ }
+ return uuidList;
+ }
+ public static boolean getFilterCommonNameReferences(){
+ return getBooleanValue(PreferencePredicate.CommonNameReferencesWithMarker.getKey());
+ }
-}
-
-public static boolean getFilterCommonNameReferences(){
- return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
-}
-
-/**
- *
- */
-public static void updateDBPreferences() {
- CdmPreference preference = null;
- IPreferenceStore prefStore = getPreferenceStore();
-
- //ABCD Configurator
+ public static void updateDBPreferences() {
- updateAbcdImportConfigurationPreference();
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ cache.getAllTaxEditorDBPreferences();
- preference = getPreferenceFromDB(PreferencePredicate.ShowImportExportMenu);
- if (preference != null){
- if(!getBooleanValue(SHOW_IO_MENU) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_IO_MENU, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_IO_MENU, true);
+ //Name Details
+ NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
}
- preference = getPreferenceFromDB(PreferencePredicate.ShowMediaView);
- if (preference != null){
- if(!getBooleanValue(SHOW_MEDIA) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_MEDIA, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_MEDIA, true);
- }
+ public static void setPreferencesToDB(List<CdmPreference> preferences) {
- preference = getPreferenceFromDB(PreferencePredicate.ShowChecklistPerspective);
- if (preference != null){
- if(!getBooleanValue(SHOW_CHECKLIST_PERSPECTIVE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, Boolean.valueOf(preference.getValue()));
+ ICdmRepository controller;
+ 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();
}
- }else{
- setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, false);
}
- //Specimen Details
- preference = getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
- if (preference != null){
- if(!getBooleanValue(SHOW_SPECIMEN) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_SPECIMEN, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_SPECIMEN, true);
+ /**
+ * Returns whether the named preference is known.
+ * @param prefKey the key of the preference
+ * @return <code>true</code> if the preference is known, <code>false</code> otherwise
+ */
+ public static boolean contains(String prefKey){
+ return getPreferenceStore().contains(prefKey(prefKey));
}
- preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
- if (preference != null){
- if(!getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_TAXON_ASSOCIATIONS, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
- if (preference != null){
- if(!getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
- if (preference != null){
- if(!getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_LIFE_FORM, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
- if (preference != null){
- if(!getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS, Boolean.valueOf(preference.getValue()));
+ public static TermTree<Feature> getPreferredFeatureTreeForNameDescription(boolean createNew) {
+ if(preferredNameFeatureTree != null && !createNew){
+ return preferredNameFeatureTree;
}
+ createPreferredFeatureTreeForNameDescription();
+ return preferredNameFeatureTree;
}
+ public static void createPreferredFeatureTreeForNameDescription() {
- //Name Details
- NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
- if (config != null ){
- if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
- setPreferredNameDetailsConfiguration(config, false);
- }
- }
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ CdmPreference pref = cache.get(PreferencePredicate.NameFeatures.getKey());
+ List<Feature> terms = new ArrayList<>();
+ boolean override = PreferencesUtil.getOverrideForPreference(PreferencePredicate.NameFeatures.getKey());
- //Distribution Editor
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_VOCABULARIES_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), preference.getValue());
- setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey(), false);
+ if (uuids != null && !uuids.isEmpty()){
+ terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
}
- }else{
- setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE,true);
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), "");
- }
- preference = getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
- if (preference != null){
- boolean test = getBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE);
- if (!getBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey(), Boolean.valueOf(preference.getValue()));
+ 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{
- test = getBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey());
- System.err.println(test);
+ preferredNameFeatureTree = TermTree.NewFeatureInstance(terms);
}
}
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_STATUS_OVERRIDE) || !preference.isAllowOverride()){
- //get terms for the uuids... and add them to the termManager as preferred terms
- ITermService termService = CdmStore.getService(ITermService.class);
- String[] uuidArray = preference.getValue().split(";");
- List<UUID> uuidList = new ArrayList();
- for (String uuidString:uuidArray){
- try {
- uuidList.add(UUID.fromString(uuidString));
- } catch (Exception e) {
- logger.warn("Preference loading failed", e);
+ public static void removeFromDB(List<CdmPreference> prefsToDelete) {
+ ICdmRepository controller;
+ //try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ for (CdmPreference preference: prefsToDelete){
+ controller.getPreferenceService().remove(preference.getKey());
}
+ CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
}
-
- List<DefinedTermBase> definedTermBases = termService.load(uuidList, null);
- CdmStore.getTermManager().setPreferredTerms(definedTermBases, TermStore.getTerms(TermType.PresenceAbsenceTerm, null));
- }
}
- preference = getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DESCRIPTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey(), Boolean.valueOf(preference.getValue()));
- }
- }
+ public static void removeFromDB(CdmPreference prefToDelete) {
+ ICdmRepository controller;
- preference = getPreferenceFromDB(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DISPLAY_AREA_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), preference.getValue());
- }
- }
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ controller.getPreferenceService().remove(prefToDelete.getKey());
- preference = getPreferenceFromDB(EditorPreferencePredicate.DisplayOfStatus);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DISPLAY_STATUS_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), preference.getValue());
+ CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
}
}
- preference = getPreferenceFromDB(EditorPreferencePredicate.ShowRankInDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_SHOW_RANK_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), Boolean.valueOf(preference.getValue()));
+ public static TermTree<?> getPreferredFeatureTreeForTaxonDescription(boolean createNew) {
+ if(preferredTaxonFeatureTree != null && !createNew){
+ return preferredTaxonFeatureTree;
}
+ createPreferredFeatureTreeForTaxonDescription();
+ return preferredTaxonFeatureTree;
}
- preference = getPreferenceFromDB(EditorPreferencePredicate.AreasSortedByIdInVocabulary);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_AREAS_SORTED_BY_IDINVOC_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey(), Boolean.valueOf(preference.getValue()));
+ public static void createPreferredFeatureTreeForTaxonDescription() {
+
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ CdmPreference pref = cache.get(PreferencePredicate.TaxonFeatures.getKey());
+ List<Feature> terms = null;
+ boolean override = PreferencesUtil.getOverrideForPreference(PreferencePredicate.TaxonFeatures.getKey());
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.TaxonFeatures.getKey(), false);
+ if (uuids != null && !uuids.isEmpty()){
+ 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();
+ terms.removeAll(nameFeature);
- preference = getPreferenceFromDB(EditorPreferencePredicate.OwnDescriptionForDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(OWN_DESCRIPTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), Boolean.valueOf(preference.getValue()));
}
- }
- //common names
- preference = getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
- if (preference != null){
- if (!getBooleanValue(COMMON_NAME_AREA_VOCABULARIES) || !preference.isAllowOverride()){
- setStringValue(COMMON_NAME_AREA_VOCABULARIES, preference.getValue());
- setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
+ if (terms.isEmpty()){
+ preferredTaxonFeatureTree = TermEditorInput.getDefaultFeatureTree();
+ }else{
+ preferredTaxonFeatureTree = TermTree.NewFeatureInstance(terms);
}
- }else{
- setStringValue(COMMON_NAME_AREA_VOCABULARIES, "");
- setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, true);
}
- preference = getPreferenceFromDB(PreferencePredicate.CommonNameReferencesWithMarker);
- if (preference != null){
- if (!getBooleanValue(FILTER_COMMON_NAME_REFERENCES) || !preference.isAllowOverride()){
- setBooleanValue(FILTER_COMMON_NAME_REFERENCES, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(FILTER_COMMON_NAME_REFERENCES, false);
+ public static void setLastSelectedBiocaseProvider(String lastAccessPoint) {
+ setStringValue(LAST_USED_BIOCASE_PROVIDER, lastAccessPoint);
}
+ /**
+ * @return
+ */
+ public static boolean getLocalActive() {
+ // TODO: this needs to be adapted!!!
+ return true;
+ }
+ /**
+ * @return
+ */
+ public static boolean showGfbioMetaData() {
+ //TODO: needs to be adapted!!!
+ return false;
+ }
+ public static SecReferenceHandlingEnum getSecReferenceHandlingPreference(){
- //sources
- preference = getPreferenceFromDB(PreferencePredicate.ShowIdInSource);
- if (preference != null){
- if (!getBooleanValue(SHOW_ID_IN_SOURCE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_ID_IN_SOURCE, Boolean.valueOf(preference.getValue()));
+ String defaultBehaviour = getStringValue(PreferencePredicate.DefaultBehaviourForSecundum.getKey());
+ SecReferenceHandlingEnum handling = null;
+ try{
+ handling = SecReferenceHandlingEnum.valueOf(defaultBehaviour);
+ }catch(IllegalArgumentException e){
+ handling = (SecReferenceHandlingEnum)PreferencePredicate.DefaultBehaviourForSecundum.getDefaultValue();
}
- }else{
- setBooleanValue(SHOW_ID_IN_SOURCE, true);
- }
+ return handling;
- preference = getPreferenceFromDB(PreferencePredicate.ShowNamespaceInSource);
- if (preference != null){
- if (!getBooleanValue(SHOW_NAMESPACE_IN_SOURCE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, true);
- }
- //multiple classifications / taxon navigator
- preference = getPreferenceFromDB(PreferencePredicate.DisableMultiClassification);
- if (preference != null){
- if (!getBooleanValue(DISABLE_MULTI_CLASSIFICATION) || !preference.isAllowOverride()){
- setBooleanValue(DISABLE_MULTI_CLASSIFICATION, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(DISABLE_MULTI_CLASSIFICATION, false);
}
- preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonNodeWizard);
- if (preference != null){
- if (!getBooleanValue(SHOW_TAXONNODE_WIZARD) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_TAXONNODE_WIZARD, Boolean.valueOf(preference.getValue()));
+ public static SecReferenceHandlingSwapEnum getSecReferenceHandlingSwapPreference(){
+ String defaultBehaviour = getStringValue(PreferencePredicate.DefaultBehaviourForSecundumWhenSwap.getKey());
+ SecReferenceHandlingSwapEnum handling = null;
+ try{
+ handling = SecReferenceHandlingSwapEnum.valueOf(defaultBehaviour);
+ }catch (IllegalArgumentException e){
+ handling = (SecReferenceHandlingSwapEnum)PreferencePredicate.DefaultBehaviourForSecundumWhenSwap.getDefaultValue();
}
- }else{
- setBooleanValue(SHOW_TAXONNODE_WIZARD, true);
- }
-
-}
-
-
+ return handling;
+ }
+ public static EnabledComputedDescription getComputedDesciptionHandlingPreference(){
+ String defaultBehaviour= getStringValue(PreferencePredicate.EnableComputedDescription.getKey());
+ EnabledComputedDescription computedDescriptionsEnabled = (EnabledComputedDescription)PreferencePredicate.EnableComputedDescription.getDefaultValue();
+ if (StringUtils.isNotBlank(defaultBehaviour)){
+ try{
+ computedDescriptionsEnabled = EnabledComputedDescription.byKey(defaultBehaviour);
+ }catch(IllegalArgumentException e){
+ //do nothing, keep default value;
+ }
+ }
+ return computedDescriptionsEnabled;
+ }
+ public static boolean isComputedDesciptionHandlingDisabled(){
+ String defaultBehaviour= getStringValue(PreferencePredicate.EnableComputedDescription.getKey());
+ EnabledComputedDescription computedDescriptionsEnabled = null;
+ try{
+ computedDescriptionsEnabled = EnabledComputedDescription.byKey(defaultBehaviour);
+ }catch (IllegalArgumentException e){
+ computedDescriptionsEnabled = (EnabledComputedDescription)PreferencePredicate.EnableComputedDescription.getDefaultValue();
+ }
+ return computedDescriptionsEnabled.equals(EnabledComputedDescription.Disabled);
+ }
}