package com.globant.labs.mood.model.persistent;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.globant.labs.mood.jackson.TemplateFileDeserializer;
import com.google.appengine.api.datastore.Blob;
import com.google.common.base.Charsets;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.io.Serializable;
import java.util.Date;

/**
 * @author mauro.monti (monti.mauro@gmail.com)
 */
@Entity
public class Template extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 7841829072159026119L;

    @Basic
    private String name;

    @Basic
    private String description;

    @Basic
    private Blob file;

    public Template() {
        super();
    }

    public Template(final String name) {
        this();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @JsonIgnore
    public Blob getFile() {
        return file;
    }

    public String getTemplate() {
        if (file != null) {
            return new String(file.getBytes(), Charsets.UTF_8);
        }
        return null;
    }

    @JsonDeserialize(using = TemplateFileDeserializer.class)
    public void setFile(Blob file) {
        this.file = file;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Template template = (Template) o;

        if (!getId().equals(template.getId())) return false;
        if (!created.equals(template.created)) return false;
        if (!name.equals(template.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = this.getId().hashCode();
        result = 31 * result + created.hashCode();
        return result;
    }

}

@@ -2098,21 +2098,69 @@
 esult = 
-this.
+0;%0A%0A        if(getId() != null) %7B%0A          result = 
 getId().
@@ -2161,32 +2161,37 @@
 tId().hashCode()
+ * 31
 ;%0A        result
@@ -2188,38 +2188,72 @@
     
-result = 31 * result + created
+%7D%0A%0A        if(getName() != null) %7B%0A          result += getName()
 .has
@@ -2259,18 +2259,34 @@
 shCode()
+ * 64
 ;%0A
+        %7D%0A%0A
         
@@ -2298,16 +2298,37 @@
 n result
+ + created.hashCode()
 ;%0A    %7D%0A

Fix hash compute