package org.ovirt.mobile.movirt.rest;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * Created by sphoorti on 5/2/15.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Disk implements RestEntityWrapper<org.ovirt.mobile.movirt.model.Disk> {
    public String id;
    public String name;
    public String size;
    public Status status;
    public Vm vm;
    public Snapshot snapshot;

    @JsonIgnoreProperties(ignoreUnknown = true)
    public class Status {
        public String state;
    }

    public org.ovirt.mobile.movirt.model.Disk toEntity() {
        org.ovirt.mobile.movirt.model.Disk disk = new org.ovirt.mobile.movirt.model.Disk();
        disk.setId(id);
        disk.setName(name);
        disk.setSize(size);
        disk.setStatus(status.state);

        if (vm != null) {
            disk.setVmId(vm.id);
        }
        if (snapshot != null) {
            disk.setSnapshotId(snapshot.id);
        }

        return disk;
    }
}

@@ -748,24 +748,82 @@
 Size(size);%0A
+        if (status != null && status.state != null) %7B%0A    
         disk
@@ -847,16 +847,26 @@
 .state);
+%0A        %7D
 %0A%0A      

fix NPE when the VM has a disk without status