package org.synyx.urlaubsverwaltung.core.department;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import org.joda.time.DateTime;

import org.springframework.data.jpa.domain.AbstractPersistable;

import org.springframework.util.Assert;

import org.synyx.urlaubsverwaltung.core.person.Person;

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

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Temporal;


/**
 * Department represents an organisation unit of a company.
 *
 * @author  Daniel Hammann - <hammann@synyx.de>
 */

@Entity
public class Department extends AbstractPersistable<Integer> {

    @Column(nullable = false)
    private String name;

    private String description;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date lastModification;

    @ElementCollection
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Person> members = new ArrayList<>();

    public String getName() {

        return name;
    }


    public void setName(String name) {

        this.name = name;
    }


    public String getDescription() {

        return description;
    }


    public void setDescription(String description) {

        this.description = description;
    }


    public DateTime getLastModification() {

        if (lastModification == null) {
            return null; // because dateTime creates an DateTime.now() wenn new DateTime(null) is called.
        } else {
            return new DateTime(lastModification);
        }
    }


    public void setLastModification(DateTime lastModification) {

        Assert.notNull(lastModification);
        this.lastModification = lastModification.toDate();
    }


    @Override
    public void setId(Integer id) {

        super.setId(id);
    }


    public List<Person> getMembers() {

        return members;
    }


    public void setMembers(List<Person> members) {

        this.members = members;
    }
}

@@ -1472,21 +1472,8 @@
     
- return null;
  // 
@@ -1480,17 +1480,17 @@
 because 
-d
+D
 ateTime 
@@ -1497,19 +1497,16 @@
 creates 
-an 
 DateTime
@@ -1516,12 +1516,10 @@
 w() 
-wenn
+if
  new
@@ -1543,17 +1543,41 @@
 s called
-.
+%0A            return null;
 %0A       

remove trailing comment