package fi.nls.oskari.domain.map;

import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;

import java.io.IOException;

/**
 * Common model for layers consisting of user created data.
 */
public class UserDataLayer {
    private static final ObjectMapper OM;
    static {
        OM = new ObjectMapper();
        OM.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }
    private String uuid;
    private String publisher_name;
    private UserDataStyle style;

    public UserDataLayer () {
        style = new UserDataStyle();
    }

    public String getUuid() {
        return uuid;
    }
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getPublisher_name() {
        return publisher_name;
    }

    public void setPublisher_name(String publisher_name) {
        this.publisher_name = publisher_name;
    }

    public boolean isPublished() {
        return publisher_name != null && !publisher_name.isEmpty();
    }

    public boolean isOwnedBy(final String uuid) {
        if(uuid == null || getUuid() == null) {
            return false;
        }
        return getUuid().equals(uuid);
    }
    public void setStyle (UserDataStyle style) {
        this.style = style;
    }

    public UserDataStyle getStyle () {
        return style;
    }
    public void mapPropertiesToStyle (String properties) throws JSONException {
        try {
            style = OM.readValue(properties, UserDataStyle.class);
        } catch (IOException e) {
            throw new JSONException(e.getMessage());
        }
    }
    public void mapPropertiesToStyle (JSONObject properties) throws JSONException {
        mapPropertiesToStyle(properties.toString());
    }
}

@@ -39,30 +39,52 @@
 ort 
-org.json.JSONExce
+fi.nls.oskari.domain.map.wfs.WFSLayerO
 ption
+s
 ;%0Aim
@@ -113,422 +113,105 @@
 ct;%0A
-import com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.DeserializationFeature;%0A%0Aimport java.io.IOException;%0A%0A/**%0A * Common model for layers consisting of user created data.%0A */%0Apublic class UserDataLayer %7B%0A    private static final ObjectMapper OM;%0A    static %7B%0A        OM = new ObjectMapper();%0A        OM.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);%0A    %7D
+%0A/**%0A * Common model for layers consisting of user created data.%0A */%0Apublic class UserDataLayer %7B
 %0A   
@@ -304,81 +304,44 @@
 le;%0A
-%0A
     p
-ublic UserDataLayer () %7B%0A        style = new UserDataStyle();%0A    %7D
+rivate WFSLayerOptions options;
 %0A%0A  
@@ -1021,33 +1021,32 @@
  = style;%0A    %7D%0A
-%0A
     public UserD
@@ -1088,32 +1088,33 @@
 rn style;%0A    %7D%0A
+%0A
     public void 
@@ -1117,69 +1117,136 @@
 oid 
-mapPropertiesToStyle (String properties) throws JSONExce
+setOptions (JSONObject options) %7B%0A        this.options = new WFSLayerOptions(options);%0A    %7D%0A    public JSONObject getO
 ption
+s ()
  %7B%0A 
@@ -1256,177 +1256,203 @@
     
-try %7B%0A            style = OM.readValue(properties, UserDataStyle.class);%0A        %7D catch (IOException e) %7B%0A            throw new JSONException(e.getMessage());%0A        %7D
+return options.getOptions();%0A    %7D%0A    public WFSLayerOptions getWFSLayerOptions () %7B%0A        if (options == null) %7B%0A            options = new WFSLayerOptions();%0A        %7D%0A        return options;
 %0A   
@@ -1490,17 +1490,16 @@
 sToStyle
- 
 (JSONObj
@@ -1518,88 +1518,37 @@
 es) 
-throws JSONException %7B%0A        mapPropertiesToStyle(properties.toString());
+%7B%0A        //TODO remove
 %0A    %7D%0A
+%0A
 %7D%0A

add WFSLayerOptions for UserDataLayer