001package org.biopax.paxtools.impl.level3;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.model.level3.PublicationXref;
005import org.biopax.paxtools.util.BPCollections;
006import org.biopax.paxtools.util.SetStringBridge;
007import org.hibernate.annotations.Cache;
008import org.hibernate.annotations.*;
009import org.hibernate.search.annotations.*;
010
011import javax.persistence.*;
012import javax.persistence.Entity;
013import java.util.Set;
014
015@Entity
016@Proxy(proxyClass= PublicationXref.class)
017@Indexed
018@DynamicUpdate @DynamicInsert
019@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
020public class PublicationXrefImpl extends XrefImpl implements PublicationXref
021{
022        private String title;
023        private Set<String> url;
024        private Set<String> source;
025        private Set<String> author;
026        private int year = UNKNOWN_INT;
027
028        /**
029         * Constructor.
030         */
031        public PublicationXrefImpl()
032        {
033                this.url = BPCollections.I.createSet();
034                this.source = BPCollections.I.createSet();
035                this.author = BPCollections.I.createSet();
036        }
037
038        @Transient
039    public Class<? extends PublicationXref> getModelInterface()
040        {
041                return PublicationXref.class;
042        }
043
044        //
045        // PublicationXref interface implementation
046        //
047        ////////////////////////////////////////////////////////////////////////////
048
049    // Property author
050    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
051    @ElementCollection
052    @JoinTable(name="author")
053    @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
054    @Boost(1.1f)
055    @FieldBridge(impl=SetStringBridge.class)
056        public Set<String> getAuthor()
057        {
058                return author;
059        }
060
061        public void setAuthor(Set<String> author)
062        {
063                this.author = author;
064        }
065
066        public void addAuthor(String author)
067        {
068                if(author != null && author.length() > 0)
069                        this.author.add(author);
070        }
071
072        public void removeAuthor(String author)
073        {
074                if(author != null)
075                        this.author.remove(author);
076        }
077
078    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
079    @ElementCollection
080    @JoinTable(name="source")
081    @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
082    @Boost(1.1f)
083    @FieldBridge(impl=SetStringBridge.class)
084        public Set<String> getSource()
085        {
086                return source;
087        }
088
089        public void setSource(Set<String> source)
090        {
091                this.source = source;
092        }
093
094        public void addSource(String source)
095        {
096                if(source != null && source.length() > 0)
097                        this.source.add(source);
098        }
099
100        public void removeSource(String source)
101        {
102                if(source != null)
103                        this.source.remove(source);
104        }
105
106    
107    @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
108    @Boost(1.1f)
109        @Column(columnDefinition="LONGTEXT")
110        public String getTitle()
111        {
112                return title;
113        }
114
115        public void setTitle(String title)
116        {
117                this.title = title;
118        }
119
120        // Property url
121    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
122    @ElementCollection
123    @JoinTable(name="url")
124    @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
125    @Boost(1.1f)
126    @FieldBridge(impl=SetStringBridge.class)
127        public Set<String> getUrl()
128        {
129                return url;
130        }
131
132        public void setUrl(Set<String> url)
133        {
134                this.url = url;
135        }
136
137        public void addUrl(String url)
138        {
139                if(url != null && url.length() > 0)
140                        this.url.add(url);
141        }
142
143        public void removeUrl(String url)
144        {
145                if(url != null)
146                        this.url.remove(url);
147        }
148
149    // Property year
150    
151    @Column(name="published") //default one caused MySQLIntegrityConstraintViolationException: Column 'year' in field list is ambiguous
152    @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
153    @Boost(1.1f)
154        public int getYear()
155        {
156                return year;
157        }
158
159        public void setYear(int year)
160        {
161                this.year = year;
162        }
163        
164        @Override
165        protected boolean semanticallyEquivalent(BioPAXElement other) {
166                if(!(other instanceof PublicationXref)) return false;
167                
168                PublicationXref that = (PublicationXref) other;
169                boolean eqv = (year == that.getYear()) &&
170                        (title != null ? 
171                                title.equals(that.getTitle()) 
172                                : that.getTitle() == null)
173                        && author.containsAll(that.getAuthor())
174                        && source.containsAll(that.getSource())
175                        && url.containsAll(that.getUrl());
176                
177                return eqv      && super.semanticallyEquivalent(other);
178        }
179}