View Javadoc

1   package org.kuali.mobility.tours.entity;
2   
3   import java.util.ArrayList;
4   import java.util.HashSet;
5   import java.util.List;
6   import java.util.Set;
7   
8   import javax.persistence.Basic;
9   import javax.persistence.CascadeType;
10  import javax.persistence.Column;
11  import javax.persistence.Entity;
12  import javax.persistence.FetchType;
13  import javax.persistence.GeneratedValue;
14  import javax.persistence.GenerationType;
15  import javax.persistence.Id;
16  import javax.persistence.JoinColumn;
17  import javax.persistence.OneToMany;
18  import javax.persistence.OneToOne;
19  import javax.persistence.SequenceGenerator;
20  import javax.persistence.Table;
21  import javax.persistence.Version;
22  import javax.xml.bind.annotation.XmlElement;
23  
24  import org.kuali.mobility.tours.service.ToursService;
25  
26  @Entity(name="POI")
27  @Table(name="TOUR_POI_T")
28  public class POI implements Comparable<POI> {
29  
30  	@Id
31      //@SequenceGenerator(name="poi_sequence", sequenceName="SEQ_TOUR_POI_T", initialValue=1000, allocationSize=1)
32      //@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="poi_sequence")
33  	@GeneratedValue(strategy = GenerationType.TABLE)
34      @Column(name="POI_ID")
35  	private Long poiId;
36  
37  	@Basic
38      @Column(name="TOUR_ID", insertable=false, updatable=false)
39  	private Long tourId;
40  
41      @OneToOne(fetch=FetchType.LAZY)
42      @JoinColumn(name="TOUR_ID", nullable=true)
43  	protected Tour tour;
44  
45      @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="poiId")
46  	private Set<POIPermission> permissions;
47  
48      @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="poi")
49  	private Set<POIPhoneNumber> phoneNumbers = new HashSet<POIPhoneNumber>();
50  
51      @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="poi")
52  	private Set<POIEmailAddress> emailAddresses = new HashSet<POIEmailAddress>();
53  
54  	@Column(name="NAME")
55  	private String name;
56  
57  	@Column(name="OFF_NAME")
58  	private String officialName;
59  
60  	@Column(name="POI_TYPE")
61  	private String type;
62  
63  	@Column(name="LOCATION_ID")
64  	private String locationId;
65  
66  	@Column(name="LAT")
67  	private float latitude;
68  
69  	@Column(name="LNG")
70  	private float longitude;
71  
72  	@Column(name="MEDIA")
73  	private String media;
74  
75  	@Column(name="DESCRIPTION")
76  	private String description;
77  
78  	@Column(name="ST_DESCRIPTION")
79  	private String shortDescription;
80  
81  	@Column(name="ORDR")
82  	private Integer order;
83  
84  	@Column(name="DIST_TO_NXT")
85  	private Long distanceToNextPoi;
86  
87  	@Column(name="URL")
88  	private String url;
89  
90  	@Column(name="IMG_URL")
91  	private String thumbnailUrl;
92  
93  	@Column(name="FB_LIKE_URL")
94  	private String fbLikeUrl;
95  
96  	@Column(name="FB_LIKE_EN")
97  	private String fbLikeButtonEnabled;
98  
99  	@Version
100     @Column(name="VER_NBR")
101     protected Long versionNumber;
102 
103 	public POI copy(boolean includeIds) {
104 		POI copy = new POI();
105 		if (includeIds) {
106 			copy.setPoiId(new Long(poiId));
107 			copy.setVersionNumber(new Long(versionNumber));
108 		}
109 		if (tourId != null) {
110 			copy.setTourId(new Long(tourId));
111 		}
112 		if (name != null) {
113 			copy.setName(new String(name));
114 		}
115 		if (officialName != null) {
116 			copy.setOfficialName(new String(officialName));
117 		}
118 		if (type != null) {
119 			copy.setType(new String(type));
120 		}
121 		if (locationId != null) {
122 			copy.setLocationId(new String(locationId));
123 		}
124 		copy.setLatitude(latitude);
125 		copy.setLongitude(longitude);
126 		if (media != null) {
127 			copy.setMedia(new String(media));
128 		}
129 		if (description != null) {
130 			copy.setDescription(new String(description));
131 		}
132 		if (shortDescription != null) {
133 			copy.setShortDescription(new String(shortDescription));
134 		}
135 		if (order != null) {
136 			copy.setOrder(new Integer(order));
137 		}
138 		if (distanceToNextPoi != null) {
139 			copy.setDistanceToNextPoi(new Long(distanceToNextPoi));
140 		}
141 		if (url != null) {
142 			copy.setUrl(new String(url));
143 		}
144 		if (thumbnailUrl != null) {
145 			copy.setThumbnailUrl(new String(thumbnailUrl));
146 		}
147 		if (fbLikeUrl != null) {
148 			copy.setFbLikeUrl(new String(fbLikeUrl));
149 		}
150 		if (fbLikeButtonEnabled != null) {
151 			copy.setFbLikeButtonEnabled(new String(fbLikeButtonEnabled));
152 		}
153 		if (permissions != null && !permissions.isEmpty()){
154 			Set<POIPermission> permissionListCopy = new HashSet<POIPermission>();
155 			for (POIPermission permission : permissions) {
156 				POIPermission permissionCopy = permission.copy(includeIds);
157 				permissionCopy.setPoi(copy);
158 				permissionListCopy.add(permissionCopy);
159 			}
160 			copy.setPermissions(permissionListCopy);
161 		} else {
162 			copy.setPermissions(new HashSet<POIPermission>());
163 		}
164 
165 		if (phoneNumbers != null && !phoneNumbers.isEmpty()){
166 			Set<POIPhoneNumber> phoneNumberListCopy = new HashSet<POIPhoneNumber>();
167 			for (POIPhoneNumber phoneNumber : phoneNumbers) {
168 				POIPhoneNumber phoneNumberCopy = phoneNumber.copy(includeIds);
169 				phoneNumberCopy.setPoi(copy);
170 				phoneNumberListCopy.add(phoneNumberCopy);
171 			}
172 			copy.setPhoneNumbers(phoneNumberListCopy);
173 		} else {
174 			copy.setPhoneNumbers(new HashSet<POIPhoneNumber>());
175 		}
176 		return copy;
177 	}
178 
179 	public List<String> getViewGroups() {
180 		List<String> groups = new ArrayList<String>();
181 		for (POIPermission tp : permissions) {
182 			if (ToursService.PERMISSION_TYPE_VIEW.equals(tp.getType())){
183 				groups.add(tp.getGroupName());
184 			}
185 		}
186 		return groups;
187 	}
188 
189 	public List<String> getEditGroups() {
190 		List<String> groups = new ArrayList<String>();
191 		for (POIPermission tp : permissions) {
192 			if (ToursService.PERMISSION_TYPE_EDIT.equals(tp.getType())){
193 				groups.add(tp.getGroupName());
194 			}
195 		}
196 		return groups;
197 	}
198 
199 	public Long getPoiId() {
200 		return poiId;
201 	}
202 
203 	public void setPoiId(Long poiId) {
204 		this.poiId = poiId;
205 	}
206 
207 	public Long getTourId() {
208 		return tourId;
209 	}
210 
211 	public void setTourId(Long tourId) {
212 		this.tourId = tourId;
213 	}
214 
215 	public String getType() {
216 		return type;
217 	}
218 
219 	public void setType(String type) {
220 		this.type = type;
221 	}
222 
223 	public String getLocationId() {
224 		return locationId;
225 	}
226 
227 	public void setLocationId(String locationId) {
228 		this.locationId = locationId;
229 	}
230 
231 	public float getLatitude() {
232 		return latitude;
233 	}
234 
235 	public void setLatitude(float latitude) {
236 		this.latitude = latitude;
237 	}
238 
239 	public float getLongitude() {
240 		return longitude;
241 	}
242 
243 	public void setLongitude(float longitude) {
244 		this.longitude = longitude;
245 	}
246 
247 	public Long getVersionNumber() {
248 		return versionNumber;
249 	}
250 
251 	public void setVersionNumber(Long versionNumber) {
252 		this.versionNumber = versionNumber;
253 	}
254 
255 	public String getName() {
256 		return name;
257 	}
258 
259 	public void setName(String name) {
260 		this.name = name;
261 	}
262 
263 	public Tour getTour() {
264 		return tour;
265 	}
266 
267 	public void setTour(Tour tour) {
268 		this.tour = tour;
269 	}
270 
271 	public String getMedia() {
272 		return media;
273 	}
274 
275 	public void setMedia(String media) {
276 		this.media = media;
277 	}
278 
279 	public String getDescription() {
280 		return description;
281 	}
282 
283 	public void setDescription(String description) {
284 		this.description = description;
285 	}
286 
287 	public String getUrl() {
288 		return url;
289 	}
290 
291 	public void setUrl(String url) {
292 		this.url = url;
293 	}
294 
295 	public Integer getOrder() {
296 		return order;
297 	}
298 
299 	public void setOrder(Integer order) {
300 		this.order = order;
301 	}
302 
303 	public Long getDistanceToNextPoi() {
304 		return distanceToNextPoi;
305 	}
306 
307 	public void setDistanceToNextPoi(Long distanceToNextPoi) {
308 		this.distanceToNextPoi = distanceToNextPoi;
309 	}
310 
311 	@Override
312 	public int compareTo(POI arg0) {
313 		if (order == null) return -1;
314 		if (arg0.order == null) return 1;
315 		return order - arg0.order;
316 	}
317 
318 	public String getShortDescription() {
319 		return shortDescription;
320 	}
321 
322 	public void setShortDescription(String shortDescription) {
323 		this.shortDescription = shortDescription;
324 	}
325 
326 	public String getThumbnailUrl() {
327 		return thumbnailUrl;
328 	}
329 
330 	public void setThumbnailUrl(String thumbnailUrl) {
331 		this.thumbnailUrl = thumbnailUrl;
332 	}
333 
334 	public String getFbLikeUrl() {
335 		return fbLikeUrl;
336 	}
337 
338 	public void setFbLikeUrl(String fbLikeUrl) {
339 		this.fbLikeUrl = fbLikeUrl;
340 	}
341 
342 	public String getFbLikeButtonEnabled() {
343 		return fbLikeButtonEnabled;
344 	}
345 
346 	public void setFbLikeButtonEnabled(String fbLikeButtonEnabled) {
347 		this.fbLikeButtonEnabled = fbLikeButtonEnabled;
348 	}
349 
350 	@XmlElement(name = "permissions")
351 	public Set<POIPermission> getPermissions() {
352 		return permissions;
353 	}
354 
355 	public void setPermissions(Set<POIPermission> permissions) {
356 		this.permissions = permissions;
357 	}
358 
359 	@XmlElement(name = "phoneNumbers")
360 	public Set<POIPhoneNumber> getPhoneNumbers() {
361 		return phoneNumbers;
362 	}
363 
364 	public void setPhoneNumbers(Set<POIPhoneNumber> phoneNumbers) {
365 		this.phoneNumbers = phoneNumbers;
366 	}
367 
368 	@XmlElement(name = "emailAddresses")
369 	public Set<POIEmailAddress> getEmailAddresses() {
370 		return emailAddresses;
371 	}
372 
373 	public void setEmailAddresses(Set<POIEmailAddress> emailAddresses) {
374 		this.emailAddresses = emailAddresses;
375 	}
376 
377 	public String getOfficialName() {
378 		return officialName;
379 	}
380 
381 	public void setOfficialName(String officialName) {
382 		this.officialName = officialName;
383 	}
384 }