
package com.ppm.integration.agilesdk.connector.agilecentral.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import com.ppm.integration.agilesdk.pm.ExternalTask;

public class Release extends Entity {

    private final List<ExternalTask> iterationAndUSs = new ArrayList<ExternalTask>();

    public Release(JSONObject jsonObject) {
        super(jsonObject);
    }

    public void addHierarchicalRequirement(HierarchicalRequirement hierarchicalRequirement) {
        if (hierarchicalRequirement.getReleaseUUID() != null
                && this.getUUID().equals(hierarchicalRequirement.getReleaseUUID())) {
            hierarchicalRequirement.setRelease(this);
            this.iterationAndUSs.add(hierarchicalRequirement);
        }
    }

    public void addIteration(Iteration iteration) {
        iteration.setRelease(this);
        this.iterationAndUSs.add(iteration);
    }

    public Date getScheduleStart() {
        return convertToDate(check("ReleaseStartDate") ? jsonObject.getString("ReleaseStartDate") : null);
    }

    public Date getScheduleFinish() {
        return convertToDate(check("ReleaseDate") ? jsonObject.getString("ReleaseDate") : null);
    }

    @Override
    public List<ExternalTask> getChildren() {
        return iterationAndUSs;
    }

    @Override
    public TaskStatus getStatus() {
        String state = (check("State") ? jsonObject.getString("State") : null);
        ExternalTask.TaskStatus result = ExternalTask.TaskStatus.UNKNOWN;
        // Defined,In-Progress,Completed,Accepted
        switch (state) {
            case "Defined":
                result = ExternalTask.TaskStatus.READY;
                break;
            case "In-Progress":
                result = ExternalTask.TaskStatus.IN_PROGRESS;
                break;
            case "Completed":
            case "Accepted":
                result = ExternalTask.TaskStatus.COMPLETED;
                break;
        }
        return result;
    }
}

@@ -221,16 +221,76 @@
 nalTask;
+%0Aimport com.ppm.integration.agilesdk.pm.ExternalTaskActuals;
 %0A%0Apublic
@@ -994,32 +994,46 @@
 ration);%0A    %7D%0A%0A
+    @Override%0A
     public Date 
@@ -1043,16 +1043,17 @@
 Schedule
+d
 Start() 
@@ -1160,32 +1160,46 @@
 : null);%0A    %7D%0A%0A
+    @Override%0A
     public Date 
@@ -1209,16 +1209,17 @@
 Schedule
+d
 Finish()
@@ -2075,24 +2075,24 @@
 ;%0A        %7D%0A
-
         retu
@@ -2107,11 +2107,1803 @@
 t;%0A    %7D
+%0A%0A    @Override%0A    public List%3CExternalTaskActuals%3E getActuals() %7B%0A        List%3CExternalTaskActuals%3E actuals = new ArrayList%3C%3E();%0A%0A        actuals.add(new ExternalTaskActuals() %7B%0A%0A            @Override%0A            public double getScheduledEffort() %7B%0A                if (jsonObject.getString(%22TaskEstimateTotal%22).equals(%22null%22)) %7B%0A                    return 0.0D;%0A                %7D%0A                return Double.parseDouble(jsonObject.getString(%22TaskEstimateTotal%22));%0A            %7D%0A%0A            @Override%0A            public Date getActualStart() %7B%0A                return null;%0A            %7D%0A%0A            @Override%0A            public Date getActualFinish() %7B%0A                return null;%0A            %7D%0A%0A            @Override%0A            public double getActualEffort() %7B%0A                System.out.println(%221# %22 + jsonObject.getString(%22TaskActualTotal%22).equals(%22null%22));%0A                if (jsonObject.getString(%22TaskActualTotal%22).equals(%22null%22)) %7B%0A                    return 0.0D;%0A                %7D%0A                return Double.parseDouble(jsonObject.getString(%22TaskActualTotal%22));%0A            %7D%0A%0A            @Override%0A            public double getPercentComplete() %7B%0A                return 0.0D;%0A            %7D%0A%0A            @Override%0A            public long getResourceId() %7B%0A                return -1L;%0A            %7D%0A%0A            @Override%0A            public Double getEstimatedRemainingEffort() %7B%0A                if (jsonObject.getString(%22TaskRemainingTotal%22).equals(%22null%22)) %7B%0A                    return 0.0D;%0A                %7D%0A                return Double.parseDouble(jsonObject.getString(%22TaskRemainingTotal%22));%0A            %7D%0A%0A            @Override%0A            public Date getEstimatedFinishDate() %7B%0A                return null;%0A            %7D%0A        %7D);%0A        return actuals;%0A    %7D
 %0A%7D%0A

fix release