package org.openur.module.domain;

import java.time.LocalDateTime;

import org.apache.commons.lang3.Validate;
import org.openur.module.domain.util.DefaultsUtil;

@SuppressWarnings("unchecked")
public abstract class IdentifiableEntityBuilder<T extends IdentifiableEntityBuilder<T>>
{
	// properties:
	private String identifier = DefaultsUtil.getRandomIdentifierByDefaultMechanism();
	private LocalDateTime creationDate = null;
	private LocalDateTime lastModifiedDate = null;
	
	// constructor:
	protected IdentifiableEntityBuilder()
	{
		super();
	}
	
	// builder-methods:
	public T identifier(String identifier)
	{
		Validate.notEmpty(identifier, "identifier must not be empty!");
		
		this.identifier = identifier;	
		
		return (T) this;
	}
	
	public T creationDate(LocalDateTime creationDate)
	{
		this.creationDate = creationDate;	
		
		return (T) this;
	}

	public T lastModifiedDate(LocalDateTime changeDate)
	{
		this.lastModifiedDate = changeDate;			
		
		return (T) this;
	}
	
	// accessors:
	protected String getIdentifier()
	{
		return identifier;
	}
	
	protected LocalDateTime getCreationDate()
	{
		return creationDate;
	}	
	
	protected LocalDateTime getLastModifiedDate()
	{
		return lastModifiedDate;
	}
}

@@ -333,63 +333,8 @@
 fier
- = DefaultsUtil.getRandomIdentifierByDefaultMechanism()
 ;%0D%0A%09
@@ -503,16 +503,90 @@
 per();%0D%0A
+%09%09%0D%0A%09%09identifier = DefaultsUtil.getRandomIdentifierByDefaultMechanism();%0D%0A
 %09%7D%0D%0A%09%0D%0A%09

create identifier in constructor, not in field-definition.