package fi.nls.oskari.control.statistics.db;

import fi.nls.oskari.util.JSONHelper;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * This is the value object for the layer url and other metadata in the database.
 * MyBatis Type for the SQL table oskari_maplayers
 */
public class RegionSet {
    /**
     *  The layer id in Oskari, for example: 9.
     */
    private long oskariLayerId;
    
    /**
     *  The layer name in Oskari, for example: "oskari:kunnat2013".
     */
    private String oskariLayerName;
    
    /**
     * The base url to the data source, for example: .
     */
    private String url;

    private String srs;

    private String attributes;
    
    public JSONObject asJSON() {
        JSONObject tags = new JSONObject();
        try {
            // only regionset id and regionIdTag is used in frontend, and regionIdTag should propably come from datasource...
            //tags.put("nameIdTag", getNameProperty());
            tags.put("regionIdTag", getIdProperty());
            //tags.put("url", getUrl());
            //tags.put("featuresUrl", getFeaturesUrl());
        } catch (JSONException e) {
            throw new RuntimeException("Something went wrong serializing the region set", e);
        }
        return tags;
    }
    public String getNameProperty() {
        return getStatsJSON().optString("nameIdTag");
    }
    public String getIdProperty() {
        return getStatsJSON().optString("regionIdTag");
    }
    public String getFeaturesUrl() {
        return getStatsJSON().optString("featuresUrl");
    }
    private JSONObject getStatsJSON() {
        JSONObject json = JSONHelper.createJSONObject(attributes);
        if(json == null) {
            return new JSONObject();
        }
        JSONObject stats = json.optJSONObject("statistics");

        if(stats == null) {
            return new JSONObject();
        }
        return stats;
    }

// -----------------

    public long getOskariLayerId() {
        return oskariLayerId;
    }

    public void setOskariLayerId(long oskariLayerId) {
        this.oskariLayerId = oskariLayerId;
    }

    public String getOskariLayerName() {
        return oskariLayerName;
    }

    public void setOskariLayerName(String oskariLayerName) {
        this.oskariLayerName = oskariLayerName;
    }

    public String getAttributes() {
        return attributes;
    }

    public void setAttributes(String attributes) {
        this.attributes = attributes;
    }
    
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSrs() {
        return srs;
    }

    public void setSrs(String srs) {
        this.srs = srs;
    }
}

@@ -307,1645 +307,282 @@
 t %7B%0A
-    /**%0A     *  The layer id in Oskari, for example: 9.%0A     */%0A    private long oskariLayerId;%0A    %0A    /**%0A     *  The layer name in Oskari, for example: %22oskari:kunnat2013%22.%0A     */%0A    private String oskariLayerName;%0A    %0A    /**%0A     * The base url to the data source, for example: .%0A     */%0A    private String url;%0A%0A    private String srs;%0A%0A    private String attributes;%0A    %0A    public JSONObject asJSON() %7B%0A        JSONObject tags = new JSONObject();%0A        try %7B%0A            // only regionset id and regionIdTag is used in frontend, and regionIdTag should propably come from datasource...%0A            //tags.put(%22nameIdTag%22, getNameProperty());%0A            tags.put(%22regionIdTag%22, getIdProperty());%0A            //tags.put(%22url%22, getUrl());%0A            //tags.put(%22featuresUrl%22, getFeaturesUrl());%0A        %7D catch (JSONException e) %7B%0A            throw new RuntimeException(%22Something went wrong serializing the region set%22, e);%0A        %7D%0A        return tags;%0A    %7D%0A    public String getNameProperty() %7B%0A        return getStatsJSON().optString(%22nameIdTag%22);%0A    %7D%0A    public String getIdProperty() %7B%0A        return getStatsJSON().optString(%22regionIdTag%22);%0A    %7D%0A    public String getFeaturesUrl() %7B%0A        return getStatsJSON().optString(%22featuresUrl%22);%0A    %7D%0A    private JSONObject getStatsJSON() %7B%0A        JSONObject json = JSONHelper.createJSONObject(attributes);%0A        if(json == null) %7B%0A            return new JSONObject();%0A        %7D%0A        JSONObject stats = json.optJSONObject(%22statistics%22);%0A%0A        if(stats == null) %7B%0A            return new JSONObject();%0A        %7D%0A        return stats;%0A    %7D%0A%0A// -----------------
+%0A    private long oskariLayerId; // oskari_maplayer.id%0A    private String oskariLayerName; // oskari_maplayer.name%0A    private String url; // oskari_maplayer.url%0A    private String srs; // oskari_maplayer.srs_name%0A    private String attributes; // oskari_maplayer.attributes
 %0A%0A  
@@ -1120,20 +1120,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1368,10 +1368,1249 @@
 ;%0A    %7D%0A
+%0A    public JSONObject asJSON() %7B%0A        JSONObject tags = new JSONObject();%0A        try %7B%0A            // only regionset id and regionIdTag is used in frontend, and regionIdTag should propably come from datasource...%0A            //tags.put(%22nameIdTag%22, getNameProperty());%0A            tags.put(%22regionIdTag%22, getIdProperty());%0A            //tags.put(%22url%22, getUrl());%0A            //tags.put(%22featuresUrl%22, getFeaturesUrl());%0A        %7D catch (JSONException e) %7B%0A            throw new RuntimeException(%22Something went wrong serializing the region set%22, e);%0A        %7D%0A        return tags;%0A    %7D%0A%0A    public String getNameProperty() %7B%0A        return getStatsJSON().optString(%22nameIdTag%22);%0A    %7D%0A%0A    public String getIdProperty() %7B%0A        return getStatsJSON().optString(%22regionIdTag%22);%0A    %7D%0A%0A    public String getFeaturesUrl() %7B%0A        return getStatsJSON().optString(%22featuresUrl%22);%0A    %7D%0A%0A    private JSONObject getStatsJSON() %7B%0A        JSONObject json = JSONHelper.createJSONObject(attributes);%0A        if(json == null) %7B%0A            return new JSONObject();%0A        %7D%0A        JSONObject stats = json.optJSONObject(%22statistics%22);%0A%0A        if(stats == null) %7B%0A            return new JSONObject();%0A        %7D%0A        return stats;%0A    %7D%0A%0A
 %7D%0A

Remove weird comments, add empty lines between functions, remove empty lines between fields