<commit_before>package fi.nls.oskari.control.view.modifier.bundle;

import fi.mml.map.mapwindow.util.OskariLayerWorker;
import fi.mml.portti.domain.permissions.Permissions;
import fi.mml.portti.service.db.permissions.PermissionsService;
import fi.mml.portti.service.db.permissions.PermissionsServiceIbatisImpl;
import fi.nls.oskari.analysis.AnalysisHelper;
import fi.nls.oskari.annotation.OskariViewModifier;
import fi.nls.oskari.domain.User;
import fi.nls.oskari.domain.map.MyPlaceCategory;
import fi.nls.oskari.domain.map.OskariLayer;
import fi.nls.oskari.domain.map.analysis.Analysis;
import fi.nls.oskari.domain.map.userlayer.UserLayer;
import fi.nls.oskari.domain.map.view.ViewTypes;
import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.map.analysis.domain.AnalysisLayer;
import fi.nls.oskari.map.analysis.service.AnalysisDbService;
import fi.nls.oskari.map.analysis.service.AnalysisDbServiceIbatisImpl;
import fi.nls.oskari.map.userlayer.service.UserLayerDataService;
import fi.nls.oskari.map.userlayer.service.UserLayerDbService;
import fi.nls.oskari.map.userlayer.service.UserLayerDbServiceIbatisImpl;
import fi.nls.oskari.myplaces.MyPlacesService;
import fi.nls.oskari.service.OskariComponentManager;
import fi.nls.oskari.util.ConversionHelper;
import fi.nls.oskari.util.JSONHelper;
import fi.nls.oskari.view.modifier.ModifierException;
import fi.nls.oskari.view.modifier.ModifierParams;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

@OskariViewModifier("mapfull")
public class MapfullHandler extends BundleHandler {

    private static final Logger LOGGER = LogFactory.getLogger(MapfullHandler.class);
    private static PermissionsService permissionsService = new PermissionsServiceIbatisImpl();

    // FIXME: default srs is hardcoded into frontend if srs is not defined in mapOptions!!
    public static final String DEFAULT_MAP_SRS = "EPSG:3067";

    private static final String KEY_LAYERS = "layers";
    private static final String KEY_SEL_LAYERS = "selectedLayers";
    private static final String KEY_ID = "id";

    private static final String KEY_USER = "user";


    private static final String KEY_MAP_OPTIONS = "mapOptions";
    private static final String KEY_PROJ_DEFS = "projectionDefs";
    private static final String KEY_SRS = "srsName";


    private static final String KEY_PLUGINS = "plugins";
    public static final String KEY_CONFIG = "config";
    private static final String KEY_BASELAYERS = "baseLayers";

    private static final String PREFIX_MYPLACES = "myplaces_";
    private static final String PREFIX_ANALYSIS = "analysis_";
    private static final String PREFIX_USERLAYERS = "userlayer_";

    private static final String PLUGIN_LAYERSELECTION = "Oskari.mapframework.bundle.mapmodule.plugin.LayerSelectionPlugin";
    private static final String PLUGIN_GEOLOCATION = "Oskari.mapframework.bundle.mapmodule.plugin.GeoLocationPlugin";
    public static final String PLUGIN_SEARCH = "Oskari.mapframework.bundle.mapmodule.plugin.SearchPlugin";
    public static final String EPSG_PROJ4_FORMATS = "epsg_proj4_formats.json";


    private static MyPlacesService myPlaceService = null;
    private static final AnalysisDbService analysisService = new AnalysisDbServiceIbatisImpl();
    private static final UserLayerDbService userLayerService = new UserLayerDbServiceIbatisImpl();
    private static final UserLayerDataService userLayerDataService = new UserLayerDataService();

    private static final LogoPluginHandler LOGO_PLUGIN_HANDLER = new LogoPluginHandler();
    private static final WfsLayerPluginHandler WFSLAYER_PLUGIN_HANDLER = new WfsLayerPluginHandler();

    private static JSONObject epsgMap = null;
    private static JSONArray svgMarkers = null;


    public void init() {
        myPlaceService = OskariComponentManager.getComponentOfType(MyPlacesService.class);
        epsgInit();
        svgInit();
    }

    public boolean modifyBundle(final ModifierParams params) throws ModifierException {
        final JSONObject mapfullConfig = getBundleConfig(params.getConfig());
        final JSONObject mapfullState = getBundleState(params.getConfig());

        if (mapfullConfig == null) {
            return false;
        }
        // setup correct ajax url
        final String ajaxUrl = mapfullConfig.optString("globalMapAjaxUrl");
        try {
            // fix ajaxurl to current community if possible
            // (required to show correct help articles)
            mapfullConfig.put("globalMapAjaxUrl", params.getBaseAjaxUrl());
            LOGGER.debug("Replaced ajax url: ", ajaxUrl, "->", params.getBaseAjaxUrl());
        } catch (Exception e) {
            LOGGER.error(e, "Replacing ajax url failed: ", ajaxUrl, "- Parsed:",<commit_msg>Removed unused variable<commit_after>package fi.nls.oskari.control.view.modifier.bundle;

import fi.mml.map.mapwindow.util.OskariLayerWorker;
import fi.mml.portti.domain.permissions.Permissions;
import fi.mml.portti.service.db.permissions.PermissionsService;
import fi.mml.portti.service.db.permissions.PermissionsServiceIbatisImpl;
import fi.nls.oskari.analysis.AnalysisHelper;
import fi.nls.oskari.annotation.OskariViewModifier;
import fi.nls.oskari.domain.User;
import fi.nls.oskari.domain.map.MyPlaceCategory;
import fi.nls.oskari.domain.map.OskariLayer;
import fi.nls.oskari.domain.map.analysis.Analysis;
import fi.nls.oskari.domain.map.userlayer.UserLayer;
import fi.nls.oskari.domain.map.view.ViewTypes;
import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.map.analysis.domain.AnalysisLayer;
import fi.nls.oskari.map.analysis.service.AnalysisDbService;
import fi.nls.oskari.map.analysis.service.AnalysisDbServiceIbatisImpl;
import fi.nls.oskari.map.userlayer.service.UserLayerDataService;
import fi.nls.oskari.map.userlayer.service.UserLayerDbService;
import fi.nls.oskari.map.userlayer.service.UserLayerDbServiceIbatisImpl;
import fi.nls.oskari.myplaces.MyPlacesService;
import fi.nls.oskari.service.OskariComponentManager;
import fi.nls.oskari.util.ConversionHelper;
import fi.nls.oskari.util.JSONHelper;
import fi.nls.oskari.view.modifier.ModifierException;
import fi.nls.oskari.view.modifier.ModifierParams;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

@OskariViewModifier("mapfull")
public class MapfullHandler extends BundleHandler {

    private static final Logger LOGGER = LogFactory.getLogger(MapfullHandler.class);
    private static PermissionsService permissionsService = new PermissionsServiceIbatisImpl();

    // FIXME: default srs is hardcoded into frontend if srs is not defined in mapOptions!!
    public static final String DEFAULT_MAP_SRS = "EPSG:3067";

    private static final String KEY_LAYERS = "layers";
    private static final String KEY_SEL_LAYERS = "selectedLayers";
    private static final String KEY_ID = "id";

    private static final String KEY_USER = "user";


    private static final String KEY_MAP_OPTIONS = "mapOptions";
    private static final String KEY_PROJ_DEFS = "projectionDefs";
    private static final String KEY_SRS = "srsName";


    private static final String KEY_PLUGINS = "plugins";
    public static final String KEY_CONFIG = "config";
    private static final String KEY_BASELAYERS = "baseLayers";

    private static final String PREFIX_MYPLACES = "myplaces_";
    private static final String PREFIX_ANALYSIS = "analysis_";
    private static final String PREFIX_USERLAYERS = "userlayer_";

    private static final String PLUGIN_LAYERSELECTION = "Oskari.mapframework.bundle.mapmodule.plugin.LayerSelectionPlugin";
    private static final String PLUGIN_GEOLOCATION = "Oskari.mapframework.bundle.mapmodule.plugin.GeoLocationPlugin";
    public static final String PLUGIN_SEARCH = "Oskari.mapframework.bundle.mapmodule.plugin.SearchPlugin";
    public static final String EPSG_PROJ4_FORMATS = "epsg_proj4_formats.json";


    private static MyPlacesService myPlaceService = null;
    private static final AnalysisDbService analysisService = new AnalysisDbServiceIbatisImpl();
    private static final UserLayerDbService userLayerService = new UserLayerDbServiceIbatisImpl();
    private static final UserLayerDataService userLayerDataService = new UserLayerDataService();

    private static final LogoPluginHandler LOGO_PLUGIN_HANDLER = new LogoPluginHandler();
    private static final WfsLayerPluginHandler WFSLAYER_PLUGIN_HANDLER = new WfsLayerPluginHandler();

    private static JSONObject epsgMap = null;


    public void init() {
        myPlaceService = OskariComponentManager.getComponentOfType(MyPlacesService.class);
        epsgInit();
        svgInit();
    }

    public boolean modifyBundle(final ModifierParams params) throws ModifierException {
        final JSONObject mapfullConfig = getBundleConfig(params.getConfig());
        final JSONObject mapfullState = getBundleState(params.getConfig());

        if (mapfullConfig == null) {
            return false;
        }
        // setup correct ajax url
        final String ajaxUrl = mapfullConfig.optString("globalMapAjaxUrl");
        try {
            // fix ajaxurl to current community if possible
            // (required to show correct help articles)
            mapfullConfig.put("globalMapAjaxUrl", params.getBaseAjaxUrl());
            LOGGER.debug("Replaced ajax url: ", ajaxUrl, "->", params.getBaseAjaxUrl());
        } catch (Exception e) {
            LOGGER.error(e, "Replacing ajax url failed: ", ajaxUrl, "- Parsed:",
{'fraction_non_alphanumeric': 0.08730964467005076, 'fraction_numerical': 0.001218274111675127, 'mean_word_length': 4.632361349342482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2566285', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2958, 'n_words': 648}