package ligueBaseball.models;

import java.text.SimpleDateFormat;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import ligueBaseball.entities.DatabaseEntity;
import ligueBaseball.entities.Player;
import ligueBaseball.entities.Team;
import ligueBaseball.exceptions.FailedToRetrievePlayersOfTeamException;
import ligueBaseball.exceptions.NotInstanceOfClassException;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;

@XmlRootElement(name = "joueur")
@JsonRootName("player")
@JsonSerialize(include = Inclusion.NON_NULL)
public class PlayerModel extends AbstractModel
{
    private int id;
    private String lastName;
    private String firstName;

    private int number;
    private String dateBegin;
    private String dateEnd;

    private TeamModel team;

    public PlayerModel() {

    }

    public PlayerModel(Player player) throws FailedToRetrievePlayersOfTeamException {
        this.createFromEntity(player);
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    @XmlAttribute(name = "nom")
    @JsonProperty("lastName")
    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    @XmlAttribute(name = "prenom")
    @JsonProperty("firstName")
    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    @XmlAttribute(name = "numero")
    @JsonProperty("number")
    public int getNumber()
    {
        return number;
    }

    public void setNumber(int number)
    {
        this.number = number;
    }

    @XmlAttribute(name = "datedebut")
    @JsonProperty("dateBegin")
    public String getDateBegin()
    {
        if (dateBegin != null) {
            return new SimpleDateFormat("dd-MMM-yyyy").format(dateBegin);
        }
        return "";
    }

    public void setDateBegin(String dateBegin)
    {
        this.dateBegin = dateBegin;
    }

    @XmlTransient
    @JsonProperty("dateEnd")
    public String getDateEnd()
    {
        return dateEnd;
    }

    public void setDateEnd(String dateEnd)
    {
        this.dateEnd = dateEnd;
    }

    @JsonProperty("team")
    public TeamModel getTeam()
    {
        return team;
    }

    public void removeTeam()
    {
        this.team = null;
    }

    @Override
    public void createFromEntity(DatabaseEntity entity) throws FailedToRetrievePlayersOfTeamException
    {
        if (!(entity instanceof Player)) {
            throw new NotInstanceOfClassException(this.getClass());
        }

        Player player = (Player) entity;
        this.setId(player.getId());
        this.setFirstName(player.getFirstName());
        this.setLastName(player.getLastName());
        this.setId(player.getId());
        if (player.getBeginningDate() != null) {
            this.setDateBegin(player.getBeginningDate().toString());
        }
        if (player.getEndDate() != null) {
            this.setDateEnd(player.getEndDate().toString());
        }
        this.setNumber(player.getNumber());

        Team team = player.getTeam();
        if (team != null) {
            this.team = new TeamModel(player.getTeam(), false);
        }
    }
}

@@ -28,44 +28,8 @@
 s;%0A%0A
-import java.text.SimpleDateFormat;%0A%0A
 impo
@@ -2094,24 +2094,57 @@
 %0A           
+ return dateBegin;%0A            //
  return new 
@@ -3135,32 +3135,50 @@
 layer.getId());%0A
+        try %7B%0A    
         if (play
@@ -3202,32 +3202,36 @@
 te() != null) %7B%0A
+    
             this
@@ -3275,32 +3275,119 @@
 ().toString());%0A
+            %7D%0A        %7D catch (IllegalArgumentException e) %7B%0A            // do nothing%0A
         %7D%0A      

Fix création match