/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.rave.provider.opensocial.web.model;

import org.apache.rave.rest.model.RegionWidget;

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
public class OpenSocialRegionWidget extends RegionWidget {
    @XmlElement(name="securityToken")
    protected String securityToken;
    @XmlElement(name="metadata")
    protected String metadata;

    public OpenSocialRegionWidget() {  }

    public OpenSocialRegionWidget(RegionWidget base, String securityToken, String metadata) {
        this(base);
        this.securityToken = securityToken;
        this.metadata = metadata;
    }

    public OpenSocialRegionWidget(RegionWidget base) {
        this.id = base.getId();
        this.type = base.getType();
        this.widgetId = base.getWidgetId();
        this.widgetUrl = base.getWidgetUrl();
        this.regionId = base.getRegionId();
        this.collapsed = base.isCollapsed();
        this.locked = base.isLocked();
        this.hideChrome = base.isHideChrome();
        this.ownerId = base.getOwnerId();
        this.userPrefs = base.getUserPrefs();
    }

    public String getSecurityToken() {
        return securityToken;
    }

    public void setSecurityToken(String securityToken) {
        this.securityToken = securityToken;
    }

    public String getMetadata() {
        return metadata;
    }

    public void setMetadata(String metadata) {
        this.metadata = metadata;
    }
}

@@ -858,16 +858,68 @@
 model;%0A%0A
+import com.fasterxml.jackson.databind.ObjectMapper;%0A
 import o
@@ -994,16 +994,38 @@
 ation.*;
+%0Aimport java.util.Map;
 %0A%0A@XmlAc
@@ -1135,17 +1135,19 @@
 ent(name
-=
+ = 
 %22securit
@@ -1211,17 +1211,19 @@
 ent(name
-=
+ = 
 %22metadat
@@ -1240,22 +1240,35 @@
 otected 
+Map%3C
 String
+, Object%3E
  metadat
@@ -1271,16 +1271,78 @@
 adata;%0A%0A
+    private static ObjectMapper mapper = new ObjectMapper();%0A%0A
     publ
@@ -1370,16 +1370,19 @@
 dget() %7B
+%0A  
   %7D%0A%0A   
@@ -1548,32 +1548,28 @@
     
-this.m
+setM
 etadata
- = 
+(
 metadata
 ;%0A  
@@ -1556,32 +1556,33 @@
 etadata(metadata
+)
 ;%0A    %7D%0A%0A    pub
@@ -2248,30 +2248,44 @@
 %0A    public 
+ Map%3C
 String
+, Object%3E
  getMetadata
@@ -2360,32 +2360,272 @@
 ing metadata) %7B%0A
+        Map%3CString, Object%3E metadataObject = null;%0A        try %7B%0A            metadataObject = mapper.readValue(metadata, Map.class);%0A        %7D catch (Exception e) %7B%0A            //TODO: Do we need to handle this exception somehow?%0A        %7D%0A
         this.met
@@ -2632,26 +2632,32 @@
 adata = metadata
+Object
 ;%0A    %7D%0A%7D%0A

Properly serialize metadata string for pagesForRender endpoint