/*
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.monitor.impl;

import com.eclipsesource.json.JsonObject;
import com.hazelcast.monitor.WanSyncState;
import com.hazelcast.util.Clock;
import com.hazelcast.wan.WanSyncStatus;

public class WanSyncStateImpl implements WanSyncState {

    private long creationTime;
    private WanSyncStatus status = WanSyncStatus.READY;
    private int syncedPartitionCount;
    private String activeWanConfigName = "";
    private String activePublisherName = "";

    public WanSyncStateImpl() { }

    public WanSyncStateImpl(WanSyncStatus status, int syncedPartitionCount,
                            String activeWanConfigName, String activePublisherName) {
        creationTime = Clock.currentTimeMillis();
        this.status = status;
        this.syncedPartitionCount = syncedPartitionCount;
        this.activeWanConfigName = activeWanConfigName;
        this.activePublisherName = activePublisherName;
    }

    @Override
    public long getCreationTime() {
        return creationTime;
    }

    @Override
    public WanSyncStatus getStatus() {
        return status;
    }

    @Override
    public int getSyncedPartitionCount() {
        return syncedPartitionCount;
    }

    @Override
    public String getActiveWanConfigName() {
        return activeWanConfigName;
    }

    @Override
    public String getActivePublisherName() {
        return activePublisherName;
    }

    @Override
    public JsonObject toJson() {
        JsonObject root = new JsonObject();
        root.add("creationTime", creationTime);
        root.add("status", status.getStatus());
        root.add("syncedPartitionCount", syncedPartitionCount);
        root.add("activeWanConfigName", activeWanConfigName);
        root.add("activePublisherName", activePublisherName);
        return root;
    }

    @Override
    public void fromJson(JsonObject json) {
        this.creationTime = json.getLong("creationTime", -1L);
        int status = json.getInt("status", WanSyncStatus.READY.getStatus());
        this.status = WanSyncStatus.getByStatus(status);
        this.syncedPartitionCount = json.getInt("syncedPartitionCount", 0);
        this.activeWanConfigName = json.getString("activeWanConfigName", "");
        this.activePublisherName = json.getString("activePublisherName", "");
    }

    @Override
    public String toString() {
        return "WanSyncStateImpl{wanSyncStatus=" + status
                + ", syncedPartitionCount=" + syncedPartitionCount
                + ", activeWanConfigName=" + activeWanConfigName
                + ", activePublisherName=" + activePublisherName
                + '}';
    }
}

@@ -1036,21 +1036,16 @@
 nfigName
- = %22%22
 ;%0A    pr
@@ -1080,13 +1080,8 @@
 Name
- = %22%22
 ;%0A%0A 
@@ -2258,16 +2258,63 @@
 Count);%0A
+        if (activeWanConfigName != null) %7B%0A    
         
@@ -2363,24 +2363,81 @@
 onfigName);%0A
+        %7D%0A        if (activePublisherName != null) %7B%0A    
         root
@@ -2482,24 +2482,34 @@
 isherName);%0A
+        %7D%0A
         retu
@@ -2924,26 +2924,28 @@
 onfigName%22, 
-%22%22
+null
 );%0A        t
@@ -3012,10 +3012,12 @@
 e%22, 
-%22%22
+null
 );%0A 

Change defaults for proper json parsing