001package de.deepamehta.core.service;
002
003import de.deepamehta.core.DeepaMehtaType;
004import de.deepamehta.core.service.ModelFactory;
005
006
007
008public abstract class Migration {
009
010    // ---------------------------------------------------------------------------------------------- Instance Variables
011
012    protected CoreService dm4;
013    protected ModelFactory mf;
014
015    // -------------------------------------------------------------------------------------------------- Public Methods
016
017    // ### TODO: make this internal. Define a public Migration interface?
018    public void setCoreService(CoreService dm4) {
019        this.dm4 = dm4;
020        this.mf = dm4.getModelFactory();
021    }
022
023    public abstract void run();
024
025    // ----------------------------------------------------------------------------------------------- Protected Methods
026
027    // Note: exceptionally here the Core has some knowledge about the Webclient.
028    // ### TODO: move these methods to the Webclient service.
029
030    /**
031     * Convenience method for plugin authors to set a Webclient view config value for a certain topic type.
032     *
033     * @param   topicTypeUri    The URI of the topic type whose view configuration value to set.
034     * @param   setting         Last component of the child type URI whose value to set, e.g. "icon".
035     * @param   value           The config value (String, Integer, Long, Double, or Boolean).
036     */
037    protected final void setTopicTypeViewConfigValue(String topicTypeUri, String setting, Object value) {
038        setViewConfigValue(dm4.getTopicType(topicTypeUri), setting, value);
039    }
040
041    /**
042     * Convenience method for plugin authors to set a Webclient view config value for a certain assoc type.
043     *
044     * @param   assocTypeUri    The URI of the assoc type whose view configuration value to set.
045     * @param   setting         Last component of the child type URI whose value to set, e.g. "color".
046     * @param   value           The config value (String, Integer, Long, Double, or Boolean).
047     */
048    protected final void setAssocTypeViewConfigValue(String assocTypeUri, String setting, Object value) {
049        setViewConfigValue(dm4.getAssociationType(assocTypeUri), setting, value);
050    }
051
052    // ------------------------------------------------------------------------------------------------- Private Methods
053
054    private void setViewConfigValue(DeepaMehtaType type, String setting, Object value) {
055        type.getViewConfig().setConfigValue("dm4.webclient.view_config", "dm4.webclient." + setting, value);
056    }
057}