package ca.ualberta.CMPUT301W15T06;

import android.util.Log;

public class ApproverClaimListController {

	private Claim claim;
	
	public ApproverClaimListController(Claim claim) {
		// TODO Auto-generated constructor stub
		this.claim=claim;
	}

	public void addComment(String string) throws NetWorkException {
		// TODO Auto-generated method stub
		Comment comment=new Comment(string);
		
	
		claim.getComments().getCommentList().add(comment);
		try {
			claim.notifyListeners();
		} catch (NetWorkException e) {
			// TODO Auto-generated catch block
			claim.getComments().getCommentList().remove(comment);
			throw new NetWorkException();
		}
		
	}

	public void returnClaim() throws NetWorkException, WrongApproverException {
		// TODO Auto-generated method stub

		if(claim.getComments().isFinish()){
			addComment("The Approver didn't give comments.");
		}else if(!claim.getComments().getUnFinishedComment().getApproverName().equals(AppSingleton.getInstance().getUserName())){
			throw new WrongApproverException();
		}
		User user =AppSingleton.getInstance().getTempUser();

		user.getClaimList().remove(claim);
		ModifiableClaim modifiableClaim=new ModifiableClaim(claim,"Returned");
		user.getClaimList().add(modifiableClaim);
		modifiableClaim.getComments().getUnFinishedComment().setFinish(true);
		try {			
			claim.notifyListeners();
			AppSingleton.getInstance().getNeedApproveList().remove(claim);
			claim=modifiableClaim;
			AppSingleton.getInstance().setCurrentClaim(modifiableClaim);

		} catch (NetWorkException e) {
			// TODO Auto-generated catch block
			user.getClaimList().add(claim);
			user.getClaimList().remove(modifiableClaim);
			throw new NetWorkException();
		}
		
	
	}

	public void approveClaim() throws NetWorkException, WrongApproverException {
		// TODO Auto-generated method stub

		if(claim.getComments().isFinish()){
			addComment("The Approver didn't give comments.");
		}else if(!claim.getComments().getUnFinishedComment().getApproverName().equals(AppSingleton.getInstance().getUserName())){
			throw new WrongApproverException();
		}
		
	
		
		try {
			claim.getComments().getUnFinishedComment().setFinish(true);
			claim.setStatus("Approved");
			AppSingleton.getInstance().getNeedApproveList().remove(claim);
		} catch (NetWorkException e) {
			// TODO Auto-generated catch block
			claim.getComments().getUnFinishedComment().setFinish(false);
			claim.setStatusSimple("Submitted");
			throw new NetWorkException();
		}
		
	}

}

@@ -59,193 +59,1154 @@
 og;%0A
-%0Apublic class ApproverClaimListController %7B%0A%0A%09private Claim claim;%0A%09%0A%09public ApproverClaimListController(Claim claim) %7B%0A%09%09// TODO Auto-generated constructor stub%0A%09%09this.claim=claim;%0A%09%7D%0A
+/**%0A * %3Cp%3E%0A * This %3Ccode%3EApproverClaimListController%3C/code%3E class controls the action of %0A * approver for claimant. This controller class will displays a %0A * list of %3Ccode%3EClaim%3C/code%3E, add new comment to the %3Ccode%3EClaim%3C/code%3E, %0A * approve or return the %3Ccode%3EClaim%3C/code%3E. It will be used when the %0A * approver asks to view and change status to the %3Ccode%3EClaim%3C/code%3E.%0A * %3Cp%3E%0A * %0A * @author CMPUT301W15T06%0A * @version 04/07/2015%0A * @see android.util.Log%0A */%0Apublic class ApproverClaimListController %7B%0A%0A%09/**%0A%09 * Set a %3Ccode%3EClaim%3C/code%3E object claim which contains all the detail of a claim.%0A%09 */%0A%09private Claim claim;%0A%09%0A%09/**%0A%09 * Set a %3Ccode%3EClaim%3C/code%3E to the claim list for approver.%0A%09 * %0A%09 * @param claim  a claim in the claim list waiting for approver to view%0A%09 */%0A%09public ApproverClaimListController(Claim claim) %7B%0A%09%09// TODO Auto-generated constructor stub%0A%09%09this.claim=claim;%0A%09%7D%0A%0A%09/**%0A%09 * Add a new String variable string as comment. Check network error and throws exceptions when necessary.%0A%09 * %0A%09 * @param string  a String variable that approver entered as comment (like %22Incomplete Claim Information%22)%0A%09 * @throws NetWorkException%0A%09 */
 %0A%09pu
@@ -1605,24 +1605,241 @@
 %0A%09%09%7D%0A%09%09%0A%09%7D%0A%0A
+%09/**%0A%09 * This method will allow approver to reutrn a claim after finish reviewing. %0A%09 * Check for errors and throw exceptions when necessary. %0A%09 * %0A%09 * @throws NetWorkException%0A%09 * @throws WrongApproverException%0A%09 */%0A
 %09public void
@@ -2877,16 +2877,234 @@
 %09%0A%09%0A%09%7D%0A%0A
+%09/**%0A%09 * This method will allow approver to approve a claim after finish reviewing. %0A%09 * Check for errors and throw exceptions when necessary. %0A%09 * %0A%09 * @throws NetWorkException%0A%09 * @throws WrongApproverException%0A%09 */%0A
 %09public 

Update ApproverClaimListController.java