RecommendationAlgorithmConfigurationImpl.java 3.03 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.cq.targetrecommendations.impl.model;

import com.adobe.cq.targetrecommendations.api.model.DayCountInterval;
import com.adobe.cq.targetrecommendations.api.model.RecommendationAlgorithmConfiguration;
import com.adobe.cq.targetrecommendations.api.model.RecommendationAlgorithmInclusionRule;
import java.util.List;
import java.util.Map;

public class RecommendationAlgorithmConfigurationImpl
implements RecommendationAlgorithmConfiguration {
    private Map<Object, Object> properties;

    public RecommendationAlgorithmConfigurationImpl(Map<Object, Object> properties) {
        this.properties = properties;
    }

    @Override
    public String getConfigurationKey() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.KEY, String.class);
    }

    @Override
    public String getConfigurationType() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.TYPE, String.class);
    }

    @Override
    public String getConfigurationDataSource() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.DATASOURCE, String.class);
    }

    @Override
    public String getConfigurationAttribute() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.ATTRIBUTE, String.class);
    }

    @Override
    public DayCountInterval getDayCount() {
        String dayCountStr = this.getProperty((Object)AlgorightmConfigurationProperty.DAY_COUNT, String.class);
        return DayCountInterval.fromString(dayCountStr);
    }

    @Override
    public double getPriceRangeMin() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.PRICE_MIN, Double.class);
    }

    @Override
    public double getPriceRangeMax() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.PRICE_MAX, Double.class);
    }

    @Override
    public String getProductConfidence() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.PRODUCT_CONFIDENCE, String.class);
    }

    @Override
    public int getMinInventory() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.PRODUCT_MIN_INVENTORY, Integer.class);
    }

    @Override
    public List<RecommendationAlgorithmInclusionRule> getInclusionRules() {
        return this.getProperty((Object)AlgorightmConfigurationProperty.INCLUSION_RULES, List.class);
    }

    private <T> T getProperty(Object key, Class<T> convertTo) {
        Object propValue = this.properties.get(key);
        T convertedPropValue = null;
        if (propValue != null && convertTo.isAssignableFrom(propValue.getClass())) {
            convertedPropValue = convertTo.cast(propValue);
        }
        return convertedPropValue;
    }

    public static enum AlgorightmConfigurationProperty {
        KEY,
        TYPE,
        DATASOURCE,
        ATTRIBUTE,
        DAY_COUNT,
        PRICE_MIN,
        PRICE_MAX,
        PRODUCT_CONFIDENCE,
        PRODUCT_MIN_INVENTORY,
        INCLUSION_RULES;
        

        private AlgorightmConfigurationProperty() {
        }
    }

}