View Javadoc

1   /*
2    * Copyright 2007 The International Moth Class Association (IMCA)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.imca.model.entities;
17  
18  import java.util.Collection;
19  import java.util.Locale;
20  
21  import javax.persistence.Entity;
22  import javax.persistence.GeneratedValue;
23  import javax.persistence.GenerationType;
24  import javax.persistence.Id;
25  import javax.persistence.NamedQuery;
26  import javax.persistence.NamedQueries;
27  import javax.persistence.OneToMany;
28  import javax.persistence.ManyToMany;
29  
30  /**
31   * An persistence entity description. There is no logic just getter and setters,
32   * for the properties. This Object represents a table in the database and the
33   * properties are fields.
34   *
35   * @author dougculnane
36   */
37  @Entity
38  @NamedQueries( {
39          @NamedQuery(name = "findAssociationByCountryCode",
40                  query = "SELECT a FROM AssociationEntity a WHERE " +
41                  		"a.isoCountryCode= :isoCountryCode"),
42          @NamedQuery(name = "findAssociationByCountryCodeAndArea", 
43                  query = "SELECT a FROM AssociationEntity a WHERE " +
44                  		"a.isoCountryCode= :isoCountryCode AND a.area = :area"),
45  		@NamedQuery(name = "findAllAssociations", 
46                  query = "SELECT a FROM AssociationEntity a " +
47                  		"ORDER BY a.isoCountryCode"),
48         @NamedQuery(name = "findAssociationsWithWebsites", 
49                  query = "SELECT a FROM AssociationEntity a " +
50                          "WHERE a.url != '' ORDER BY a.isoCountryCode"), 
51          @NamedQuery(name = "findAssociationByIsOfficial", 
52                  query = "SELECT a FROM AssociationEntity a " +
53                          "WHERE a.isOfficiallyImca = :isOfficial"),
54          @NamedQuery(name = "AssociationBasicSearch",
55                  query = "SELECT a FROM AssociationEntity a WHERE " +
56                  		"a.isoCountryCode LIKE :search OR a.area LIKE :search")
57  })
58  public class AssociationEntity {
59  
60      /**
61       * Object Identifier.
62       */
63      @Id
64      @GeneratedValue(strategy=GenerationType.TABLE)
65      private long id;
66  
67      /**
68       * Is the association recognized as an Official IMCA association.
69       */
70      private boolean isOfficiallyImca = false;
71  
72      /**
73       * Website of association.
74       */
75      private String url = "";
76  
77      /**
78       * Bank or other payment information so that members can pay fees to the 
79       * association.
80       */
81      private String paymentExplanation = "Contact Secretary for info.";
82  
83      /**
84       * Collection of members.
85       */
86      @ManyToMany
87      private Collection<MembershipEntity> members;
88  
89      /**
90       * Collection of committee members.
91       */
92      @OneToMany
93      private Collection<CommitteeMemberEntity> committee;
94  
95      /**
96       * Indication of area when the country is split into area association.
97       */
98      private String area = "";
99  
100     /**
101      * 2 digit ISO Country code for association.
102      */
103     private String isoCountryCode = "";
104 
105     public String getIsoCountryCode() {
106         return isoCountryCode;
107     }
108 
109     public void setIsoContryCode(String isoCountryCode) {
110         this.isoCountryCode = isoCountryCode;
111     }
112 
113     public boolean getIsOfficiallyImca() {
114         return isOfficiallyImca;
115     }
116 
117     public void setIsOfficiallyImca(boolean isOfficiallyImca) {
118         this.isOfficiallyImca = isOfficiallyImca;
119     }
120 
121     public String getPaymentExplanation() {
122         return paymentExplanation;
123     }
124 
125     public void setPaymentExplanation(String paymentExplanation) {
126         this.paymentExplanation = paymentExplanation;
127     }
128 
129     public Collection<CommitteeMemberEntity> getCommittee() {
130         return committee;
131     }
132 
133     public void setCommittee(Collection<CommitteeMemberEntity> committee) {
134         this.committee = committee;
135     }
136 
137     public void setIsoCountryCode(String isoCountryCode) {
138         this.isoCountryCode = isoCountryCode;
139     }
140 
141     public String getArea() {
142         return area;
143     }
144 
145     public void setArea(String area) {
146         this.area = area;
147     }
148 
149     public long getId() {
150         return id;
151     }
152 
153     public void setId(long id) {
154         this.id = id;
155     }
156 
157     public Collection<MembershipEntity> getMembers() {
158         return members;
159     }
160 
161     public void setMembers(Collection<MembershipEntity> members) {
162         this.members = members;
163     }
164 
165     public String getUrl() {
166         return url;
167     }
168 
169     public void setUrl(String url) {
170         this.url = url;
171     }
172 
173     /**
174      * Override the Object method to give a usable human readable 
175      * representation of the Object.
176      */
177     public String toString() {
178         StringBuffer buf = new StringBuffer();
179         buf.append("International Moth ");
180         
181         if (this.isOfficiallyImca) {
182             buf.append("Class Association");
183         } else  {
184             buf.append("Fleet");
185         }
186         if (!"".equals(isoCountryCode)){
187             buf.append(" ( ");
188             if (!"".equals(area)){
189                 buf.append(area);
190                 buf.append(", ");
191             }
192             Locale loc = new Locale("", isoCountryCode);
193             buf.append(loc.getISO3Country().toUpperCase(Locale.ENGLISH));
194             buf.append(" ).");
195         }
196         return buf.toString();
197     }
198 
199 }