package fr.inria.anhalytics.kb.entities;

import fr.inria.anhalytics.commons.utilities.Utilities;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author azhar
 */
public class Person {

    private Long personId;
    private String title = "";
    private String url = "";
    private String email = "";
    private String photo = "";
    private String phone = "";
    private List<Person_Identifier> person_identifiers = null;
    private List<Person_Name> person_names = null;

    public Person() {
    }

    public Person(Long personId, String title, String photo, String url, String email, String phone, List<Person_Identifier> person_identifiers, List<Person_Name> person_names) {
        this.personId = personId;
        this.person_names = person_names;
        this.photo = photo;
        this.title = title;
        this.url = url;
        this.email = email;
        this.person_identifiers = person_identifiers;
        this.phone = phone;
    }

    /**
     * @return the personId
     */
    public Long getPersonId() {
        return personId;
    }

    /**
     * @param personId the personId to set
     */
    public void setPersonId(Long personId) {
        this.personId = personId;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        if (title.length() > 45) {
            title = title.substring(0, 44);
        }
        this.title = title;
    }

    /**
     * @return the photo
     */
    public String getPhoto() {
        return photo;
    }

    /**
     * @param photo the photo to set
     */
    public void setPhoto(String photo) {
        if (photo.length() > 45) {
            photo = photo.substring(0, 44);
        }
        this.photo = photo;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        if (url.length() > 150) {
            url = url.substring(0, 149);
        }
        this.url = url;
    }

    /**
     * @return the person_identifiers
     */
    public List<Person_Identifier> getPerson_identifiers() {
        return person_identifiers;
    }

    /**
     * @param person_identifiers the person_identifiers to set
     */
    public void setPerson_identifiers(List<Person_Identifier> person_identifiers) {
        this.person_identifiers = person_identifiers;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        if (email.length() > 150) {
            email = email.substring(0, 149);
        }
        this.email = email;
    }

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        if (phone.length() > 45) {
            phone = phone.substring(0, 44);
        }
        this.phone = phone;
    }

    public Map<String, Object> getPersonDocument() {
        Map<String, Object> personDocument = new HashMap<String, Object>();
        Map<String, Object> personIdentifierDocument = new HashMap<String, Object>();
        personDocument.put("personId", this.getPersonId());
        personDocument.put("email", this.getEmail());
        personDocument.put("title", this.getTitle());
        personDocument.put("photo", this.getPhoto());
        personDocument.put("phone", this.getPhone());
        personDocument.put("url", this.getUrl());
        for (Person_Identifier pi : this.getPerson_identifiers()) {
            personIdentifierDocument.put("type", pi.getType());
            personIdentifierDocument.put("id", pi.getId());
        }
        personDocument.put("identifers", personIdentifierDocument);

        List<Map<String, Object>> names = new ArrayList<Map<String, Object>>();
        for (Person_Name pn : this.getPerson_names()) {
            Map<String, Object> name = new HashMap<String, Object>();
            name.put("fullname", pn.getFullname());
            name.put("date", Utilities.formatDate(pn.getPublication_date()));
            name.put("title", pn.getTitle());
            names.add(name);
        }
        personDocument.put("names", names);

        return personDocument;
    }

    /**
     * @return the person_names
     */
    public List<Person_Name> getPerson_names() {
        return person_names;
    }

    /**
     * @param person_names the person_names to set
     */
    public void setPerson_names(List<Person_Name> person_names) {
        this.person_names = person_names;
    }
}

@@ -3379,32 +3379,37 @@
 ect%3E();%0A        
+List%3C
 Map%3CString, Obje
@@ -3407,24 +3407,25 @@
 ing, Object%3E
+%3E
  personIdent
@@ -3421,32 +3421,33 @@
 personIdentifier
+s
 Document = new H
@@ -3437,36 +3437,42 @@
 sDocument = new 
-Hash
+ArrayList%3C
 Map%3CString, Obje
@@ -3466,32 +3466,33 @@
 %3CString, Object%3E
+%3E
 ();%0A        pers
@@ -3889,32 +3889,78 @@
     
-personIdentifierDocument
+Map%3CString, Object%3E id = new HashMap%3CString, Object%3E();%0A            id
 .put
@@ -3979,24 +3979,62 @@
 getType());%0A
+            id.put(%22id%22, pi.getId());%0A
             
@@ -4041,32 +4041,33 @@
 personIdentifier
+s
 Document.put(%22id
@@ -4059,36 +4059,22 @@
 ocument.
-put(%22id%22, pi.getId()
+add(id
 );%0A     
@@ -4135,16 +4135,17 @@
 entifier
+s
 Document

index the list of person identifiers.