package com.k_int.aggr2.mimsy.data;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


import com.k_int.mimsy.ref.MimsyDataTypeEnum;
import com.k_int.mimsy.ref.ObjectConformanceEnum;
import com.k_int.mimsy.ref.RecordTypeEnum;


public class MimsyObjectDataDTO extends MimsyDataDTO implements Serializable
{
    private static final long 			serialVersionUID    = 1L;
    private Set<TextTypePairDTO>      		other_numbers       = new HashSet<TextTypePairDTO>();    
    private RecordTypeEnum              record_type;  
    //private String 						name;
    private Integer                     item_count;			  
    private String                      section;  
    private Set<NameDTO>      				names         		= new HashSet<NameDTO>();  
    private Set<String>      			boroughs         	= new HashSet<String>();  
    private Set<NameDTO>      				functional_classification         		= new HashSet<NameDTO>();  
    private String                      title;
    private Set<TitleDTO>                 	other_titles        = new HashSet<TitleDTO>();
    private String                      publisher;
    private String                      pagination;
    private String                      site;
    private Set<String>                 materials 			= new HashSet<String>();
    private String						primary_material;
    private String                      measurements;
    private Set<DescriptionDTO>            descriptions        = new HashSet<DescriptionDTO>();
    private String                      acquisition;
    private String                      credit_line;
    private String                      owner_status;
    private String                      permanent_location;
    private String                      current_location;   
    private String                      current_location_description;   
    private Boolean                     loan_allowed;
    private String                      project_notes;  
    private String                      intended_use;    
    private String                      conservation_action;    
    private Set<String>                 project_codes		= new HashSet<String>();    
    private Set<ControlledReferenceDTO>    linked_objects 		= new HashSet<ControlledReferenceDTO>();
    private Set<ControlledReferenceDTO>    linked_places       = new HashSet<ControlledReferenceDTO>();
    private Set<ControlledReferenceDTO>    linked_agents       = new HashSet<ControlledReferenceDTO>();
    private Set<ControlledReferenceDTO>    linked_events       = new HashSet<ControlledReferenceDTO>();
    private Map<Integer,MimsyMediaDataDTO>         linked_media        = new HashMap<Integer,MimsyMediaDataDTO>();
    private Set<ControlledReferenceDTO>  	linked_publications = new HashSet<ControlledReferenceDTO>();
    private Set<ControlledReferenceDTO>    linked_subjects     = new HashSet<ControlledReferenceDTO>(); 
    private Set<ControlledReferenceDTO>    linked_sites     	= new HashSet<ControlledReferenceDTO>();   
    private Set<ControlledReferenceDTO>    makers     			= new HashSet<ControlledReferenceDTO>();    
    private Set<ControlledReferenceDTO>    collectors    		= new HashSet<ControlledReferenceDTO>();   
    private Set<MimsyDateDTO>			    made 				= new HashSet<MimsyDateDTO>();
    private Set<MimsyDateDTO>			    collected 			= new HashSet<MimsyDateDTO>();   
    private String                      additional_information;
    private RightsDTO                 	rights; 
    private String 						note;
    //private Set<String> 				maker 				= new HashSet<String>();
    //private Set<String> 				collector 			= new HashSet<String>();    
    private String 						place_made;
    private String 						place_collected;
    private String 						summary;
    private String						object_id;
    private String 						summary_title;
    private String						display_date;
    private boolean 					linked_data_changed;
    
    public MimsyObjectDataDTO(String mimsy_id, String object_id, ObjectConformanceEnum conformance, Date last_updated)
    {
        super(mimsy_id,MimsyDataTypeEnum.OBJECT,last_updated,conformance);
    	this.object_id=object_id;
        if(mimsy_id==null || object_id==null || conformance==null || last_updated==null)
        	throw new NullPointerException("No null values allowed in constructor");       
    }
    
    protected MimsyObjectDataDTO()
    {;}
    
    public void setObjectId(String object_id)
    {
    	this.object_id=object_id;
    }
    
    public String getObjectId()
    {
    	return object_id;
    }
  	
    
    public Set<TextTypePairDTO> getOtherNumbers()
    {
        return other_numbers;
    }

    public void setOtherNumbers(Set<TextTypePairDTO> other_numbers)
    {
        this.other_numbers = other_numbers;
    }

    public RecordTypeEnum getRecordType()
    {
        return record_type;
    }

    public void setRecordType(RecordTypeEnum record_type)
    {
        this.record_type = record_type;
    }

    public Integer getItemCount()
    {
        return item_count;
    }

    public void setItemCount(Integer item_count)
    {
        this.item_count = item_count;
    }

    public String getSection()
    {
        return section;
    }


    public void setSection(String section)
    {
        this.section = section;
    }
    
    /*public void setName(String name)
    {
    	this.name=name;
    }
    
    public String getName()
    {
    	return name;
    }*/

    public Set<NameDTO> getNames()
    {
        return names;
    }

    public void setNames(Set<NameDTO> other_names)
    {
        this.names = other_names;
    }
    
    public Set<String> getBoroughs()
    {
        return boroughs;
    }

    public void setBoroughs(Set<String> boroughs)
    {
        this.boroughs = boroughs;
    }
    
    public Set<NameDTO> getFunctionalClassification()
    {
        return functional_classification;
    }

    public void setFunctionalClassification(Set<NameDTO> functional_classification)
    {
        this.functional_classification = functional_classification;
    }

    public String getTitle()
    {
        return title;
    }

    //TITLE
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public Set<TitleDTO> getOtherTitles()
    {
        return other_titles;
    }

    public void setOtherTitles(Set<TitleDTO> other_titles)
    {
        this.other_titles = other_titles;
    }

    public String getPublisher()
    {
        return publisher;
    }

    //OPTION5
    public void setPublisher(String publisher)
    {
        this.publisher = publisher;
    }

    public String getPagination()
    {
        return pagination;
    }

    //OPTION6
    public void setPagination(String pagination)
    {
        this.pagination = pagination;
    }
    

    public String getSite()
    {
        return site;
    }

    public void setSite(String site)
    {
        this.site = site;
    }


    public Set<String> getMaterials()
    {
        return materials;
    }
   
    public void setMaterials(Set<String> materials)
    {
        this.materials = materials;
    }
    
    public void setPrimaryMaterial(String primary_material)
    {
    	this.primary_material=primary_material;
    }
    
    public String getPrimaryMaterial()
    {
    	return primary_material;
    }
        
    public String getMeasurements()
    {
        return measurements;
    }
   
    public void setMeasurements(String measurements)
    {
        this.measurements = measurements;
    }
        
    public String getNote()
    {
        return note;
    }
 
    public void setNote(String note)
    {
        this.note=note ;
    }


    public String getAcquisition()
    {
        return acquisition;
    }

    // OPTION 7
    public void setAcquisition(String acquisition)
    {
        this.acquisition = acquisition;
    }

    public String getCreditLine()
    {
        return credit_line;
    }

    public void setCreditLine(String credit_line)
    {
        this.credit_line = credit_line;
    }

    public String getOwnerStatus()
    {
        return owner_status;
    }

    //LEGAL_STATUS
    public void setOwnerStatus(String owner_status)
    {
        this.owner_status = owner_status;
    }

    public String getPermanentLocation()
    {
        return permanent_location;
    }

    //HOME_LOCATION
    public void setPermanentLocation(String permanent_location)
    {
        this.permanent_location = permanent_location;
    }

    public String getCurrentLocation()
    {
        return current_location;
    }

    //LOCATION
    public void setCurrentLocation(String current_location)
    {
        this.current_location = current_location;
    }
    
    public void setCurrentLocationDescription(String current_location_description)
    {
        this.current_location_description = current_location_description;
    }
    
    public String getCurrentLocationDescription()
    {
    	return current_location_description;
    }

    public Boolean isLoanAllowed() {
        return loan_allowed;
    }

    public void setLoanAllowed(Boolean loan_allowed)
    {
        this.loan_allowed = loan_allowed;
    }

    public String getProjectNotes()
    {
        return project_notes;
    }

    //OPTION1
    public void setProjectNotes(String project_notes)
    {
        this.project_notes = project_notes;
    }

    public String getIntendedUse()
    {
        return intended_use;
    }

    //OPTION2
    public void setIntendedUse(String intended_use)
    {
        this.intended_use = intended_use;
    }
    
    public String getConservationAction()
    {
        return conservation_action;
    }

    //OPTION 3
    public void setConservationAction(String conservation_action)
    {
        this.conservation_action = conservation_action;
    }

    public Set<String> getProjectCodes()
    {
        return project_codes;
    }

    //OPTION4
    public void setProjectCodes(Set<String> project_codes)
    {
        this.project_codes = project_codes;
    }

    //ITEMS_PLACES.*   
    public Set<ControlledReferenceDTO> getLinkedPlaces()
    {
        return linked_places;
    }

    public void setLinkedPlaces(Set<ControlledReferenceDTO> linked_places)
    {
        this.linked_places = linked_places;
    }
    
    //ITEMS_SITES.*    
    public Set<ControlledReferenceDTO> getLinkedSites()
    {
        return linked_sites;
    }

    public void setLinkedSites(Set<ControlledReferenceDTO> linked_sites)
    {
        this.linked_sites = linked_sites;
    }

    public Set<ControlledReferenceDTO> getLinkedAgents()
    {
        return linked_agents;
    }

    //ITEMS_PEOPLE.*
    public void setLinkedAgents(Set<ControlledReferenceDTO> linked_people)
    {
        this.linked_agents = linked_people;
    }

    public Set<ControlledReferenceDTO> getLinkedEvents()
    {
        return linked_events;
    }

    //ITEMS_EVENTS.*
    public void setLinkedEvents(Set<ControlledReferenceDTO> linked_events)
    {
        this.linked_events = linked_events;
    }

    public Set<ControlledReferenceDTO> getLinkedPublications()
    {
        return linked_publications;
    }

    //ITEMS_PUBLICATIONS.*
    public void setLinkedPublications(
            Set<ControlledReferenceDTO> linked_publications)
    {
        this.linked_publications = linked_publications;
    }

    public Set<ControlledReferenceDTO> getLinkedSubjects()
    {
        return linked_subjects;
    }

    //ITEMS_SUBJECTS
    public void setLinkedSubjects(Set<ControlledReferenceDTO> linked_subjects)
    {
        this.linked_subjects = linked_subjects;
    }

    public String getAdditionalInformation()
    {
        return additional_information;
    }

    //OFFSITE
    public void setAdditionalInformation(String additional_information)
    {
        this.additional_information = additional_information;
    }

    public Set<DescriptionDTO> getDescriptions()
    {
        return descriptions;
    }
    
    // DESCRIPTION
    public void setSummary(String summary)
    {
    	this.summary=summary;
    }
    
    public String getSummary()
    {
    	return summary;
    }


    //ITEM_DESCRIPTIONS
    public void setDescriptions(Set<DescriptionDTO> descriptions)
    {
        this.descriptions = descriptions;
    }

    public Map<Integer,MimsyMediaDataDTO> getLinkedMedia()
    {
        return linked_media;
    }


    //ITEMS_MEDIA.MEDIA - maybe needs more!
    public void setLinkedMedia(Map<Integer,MimsyMediaDataDTO> linked_media)
    {
        this.linked_media = linked_media;
    }

    public Set<ControlledReferenceDTO> getLinkedObjects()
    {
        return linked_objects;
    }

    //RELATED_ITEMS.*
    public void setLinkedObjects(Set<ControlledReferenceDTO> linked_objects)
    {
        this.linked_objects = linked_objects;
    }

    /*public Set<String> getMakerNames()
    {
        return maker;
    }

    //MAKER
    public void setMakerNames(Set<String> maker)
    {
        this.maker = maker;
    }*/
    
    
    public String getPlaceMade()
    {
        return place_made;
    }

    //PLACE_MADE
    public void setPlaceMade(String place_made)
    {
        this.place_made=place_made;;
    }
    
    public Set<ControlledReferenceDTO> getLinkedMakers()
    {
        return makers;
    }

    //ITEMS_MAKERS.*
    public void setLinkedMakers(
            Set<ControlledReferenceDTO> makers)
    {
        this.makers = makers;
    }
     

    //COLLECTOR
    
    /*public void setCollectorNames(Set<String> collector)
    {
        this.collector = collector;
    }
    
    public Set<String> getCollectorNames()
    {
    	return collector;
    }*/
    
    public String getPlaceCollected()
    {
        return place_collected;
    }

    //PLACE_COLLECTED
    public void setPlaceCollected(String place_collected)
    {
        this.place_collected=place_collected;
    }
    
    public Set<ControlledReferenceDTO> getLinkedCollectors()
    {
        return collectors;
    }

    //ITEMS_COLLECTORS.*
    public void setLinkedCollectors(
            Set<ControlledReferenceDTO> collectors)
    {
        this.collectors = collectors;
    }

    public Set<MimsyDateDTO> getMadeDates()
    {
        return made;
    }

    //DATE_MADE.*
    public void setMadeDates(Set<MimsyDateDTO> date_made)
    {
        this.made = date_made;
    }
        
    public Set<MimsyDateDTO> getCollectedDates()
    {
        return collected;
    }

    //DATE_COLLECTED.*
    public void setCollectedDates(Set<MimsyDateDTO> collected)
    {
        this.collected = collected;
    }
    
    public RightsDTO getRights()
    {
        return rights;
    }

    //RIGHTS.*
    public void setRights(RightsDTO rights)
    {
        this.rights = rights;
    }
 
 
    public void setSummaryTitle(String summary_title)
    {
    	this.summary_title=summary_title;
    }
    
    public String getSummaryTitle()
    {   
    	return summary_title;
    }
    
    public void setDisplayDate(String display_date)
    {
    	this.display_date=display_date;
    }
    
    public String getDisplayDate()
    {
    	return display_date;
    }
    
    
    public boolean getLinkedDataChanged()
    {
    	return linked_data_changed;
    }
    
    public void setLinkedDataChanged(boolean linked_data_changed)
    {
    	this.linked_data_changed=linked_data_changed;
    }
    
    public String generateSummaryTitle()
    { 
    	String object_name		= null;
    	String full_name		= null;
    	String display_title 	= null;
    	String curated_title	= null;
    	String popular_title	= null;
    	
    	Iterator<NameDTO> names = this.getNames().iterator();
    	while(names.hasNext())
    	{
    		NameDTO name = names.next();
    		if(name.getType()!=null)
    		{
    			if(name.getType().equalsIgnoreCase("object name") && object_name==null)   			
    				object_name=name.getName();
    			else if (name.getType().equalsIgnoreCase("full name") && full_name==null)
    				full_name=name.getName();
    		}
    	}
    	
    	
    	
    	Iterator<TitleDTO> titles = this.getOtherTitles().iterator();
    	while(titles.hasNext())
    	{
    		TitleDTO title = titles.next();
    		if(title.getType()!=null)
    		{
    			if(title.getType().equalsIgnoreCase("display title") && display_title==null)
    				display_title=title.getTitle();
    			else if (title.getType().equalsIgnoreCase("assigned by curator") && curated_title==null)
    				curated_title=title.getTitle();
    			else if (title.getType().equalsIgnoreCase("popular title") && popular_title==null)
    				popular_title=title.getTitle();
    		}
    	}
    	
    	if(display_title==null && this.getTitle()!=null)// use title from catalogue table as display title if present and non in linked table
    		display_title=this.getTitle();
    	
    	StringBuilder builder = new StringBuilder();
    	if(full_name!=null && display_title!=null)
    	{
    		builder.append(full_name);
    		builder.append(" - ");
    		builder.append(display_title); 		
    	}
    	else if(full_name==null && object_name!=null && display_title!=null) // display title not null
    	{
    		builder.append(object_name);
    		builder.append(" - ");
    		builder.append(display_title); 		
    	}
    	else if (display_title==null)
    	{
    		if(full_name!=null)
    			builder.append(full_name);
    		else if (object_name!=null)
    			builder.append(object_name);
    		   		
    		if(curated_title!=null)
    		{
        		if(builder.length()>0)
        			builder.append(" - ");
    			
        		builder.append(curated_title);
    		}
    		else if (popular_title!=null)
    		{
    			if(builder.length()>0)
        			builder.append(" - ");
    			
    			builder.append(popular_title);
    		}
    	}
    
    	return builder.toString();    	
    	
    }
}
