All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.protege.editor.owl.model.user.OrcidPreferencesManager Maven / Gradle / Ivy

package org.protege.editor.owl.model.user;


import org.protege.editor.core.prefs.Preferences;

import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Matthew Horridge
 * Stanford Center for Biomedical Informatics Research
 * 23/11/15
 */
public class OrcidPreferencesManager implements OrcidProvider {

    private static final String PREFERENCES_KEY = "user.orcid";

    private final Preferences preferences;

    /**
     * Create a manager to get and set the orcid preferences in the specified preferences object.
     * @param preferences The preferences object.  Not {@code null}.
     */
    public OrcidPreferencesManager(Preferences preferences) {
        this.preferences = checkNotNull(preferences);
    }

    /**
     * Gets the ORCID.
     * @return An optional ORCID.
     */
    public Optional getOrcid() {
        String orcid = preferences.getString(PREFERENCES_KEY, null);
        if(orcid == null) {
            return Optional.empty();
        }
        if("".equals(orcid)) {
            return Optional.empty();
        }
        return Optional.ofNullable(new Orcid(orcid));
    }

    /**
     * Sets the ORCID.
     * @param orcid The ORCID.  Not {@code null}.
     */
    public void setOrcid(Orcid orcid) {
        preferences.putString(PREFERENCES_KEY, orcid.getValue());
    }

    /**
     * Clears the ORCID.
     */
    public void clearOrcid() {
        preferences.putString(PREFERENCES_KEY, null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy