1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.directdemocracyportal.democracy.service; |
6 | |
|
7 | |
import java.util.ArrayList; |
8 | |
import java.util.Date; |
9 | |
import java.util.List; |
10 | |
|
11 | |
import org.directdemocracyportal.democracy.model.application.Action; |
12 | |
import org.directdemocracyportal.democracy.model.application.Event; |
13 | |
import org.directdemocracyportal.democracy.model.application.GovernmentPortal; |
14 | |
import org.directdemocracyportal.democracy.model.application.OnlinePoliticalParty; |
15 | |
import org.directdemocracyportal.democracy.model.application.Portal; |
16 | |
import org.directdemocracyportal.democracy.model.application.User; |
17 | |
import org.directdemocracyportal.democracy.model.application.UserRole; |
18 | |
import org.directdemocracyportal.democracy.model.application.UserSession; |
19 | |
import org.directdemocracyportal.democracy.model.core.GroupAgent; |
20 | |
import org.directdemocracyportal.democracy.model.core.Role; |
21 | |
import org.directdemocracyportal.democracy.model.world.Country; |
22 | |
import org.directdemocracyportal.democracy.model.world.Election; |
23 | |
import org.directdemocracyportal.democracy.model.world.ElectionType; |
24 | |
import org.directdemocracyportal.democracy.model.world.Government; |
25 | |
import org.directdemocracyportal.democracy.model.world.GovernmentType; |
26 | |
import org.directdemocracyportal.democracy.model.world.Issue; |
27 | |
import org.directdemocracyportal.democracy.model.world.Organisation; |
28 | |
import org.directdemocracyportal.democracy.model.world.OrganisationType; |
29 | |
import org.directdemocracyportal.democracy.model.world.Person; |
30 | |
import org.directdemocracyportal.democracy.model.world.PoliticalParty; |
31 | |
import org.directdemocracyportal.democracy.model.world.Region; |
32 | |
import org.directdemocracyportal.democracy.model.world.RegionType; |
33 | |
import org.directdemocracyportal.democracy.model.world.Resolution; |
34 | |
import org.directdemocracyportal.democracy.model.world.VoteResult; |
35 | |
import org.directdemocracyportal.democracy.model.world.Organisation.OrganisationRoles; |
36 | |
import org.directdemocracyportal.democracy.model.world.Resolution.ResolutionState; |
37 | |
import org.directdemocracyportal.democracy.service.command.CreatePartyCommand; |
38 | |
import org.directdemocracyportal.democracy.service.dao.AgentDAO; |
39 | |
import org.directdemocracyportal.democracy.service.dao.CountryDAO; |
40 | |
import org.directdemocracyportal.democracy.service.dao.DocumentDAO; |
41 | |
import org.directdemocracyportal.democracy.service.dao.EventDAO; |
42 | |
import org.directdemocracyportal.democracy.service.dao.GovernmentDAO; |
43 | |
import org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO; |
44 | |
import org.directdemocracyportal.democracy.service.dao.PortalDAO; |
45 | |
import org.directdemocracyportal.democracy.service.dao.RegionDAO; |
46 | |
import org.directdemocracyportal.democracy.service.dao.RoleDAO; |
47 | |
import org.directdemocracyportal.democracy.service.dao.UserDAO; |
48 | |
import org.directdemocracyportal.democracy.service.dao.UserSessionDAO; |
49 | |
import org.springframework.dao.DataAccessException; |
50 | |
import org.springframework.transaction.annotation.Propagation; |
51 | |
import org.springframework.transaction.annotation.Transactional; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Transactional(propagation = Propagation.REQUIRED) |
57 | |
public class PortalServiceImpl implements PortalService |
58 | |
{ |
59 | |
|
60 | |
|
61 | |
final private UserDAO userDAO; |
62 | |
|
63 | |
|
64 | |
final private AgentDAO agentDAO; |
65 | |
|
66 | |
|
67 | |
final private EventDAO eventDAO; |
68 | |
|
69 | |
|
70 | |
final private PortalDAO portalDAO; |
71 | |
|
72 | |
|
73 | |
final private CountryDAO countryDAO; |
74 | |
|
75 | |
|
76 | |
final private UserSessionDAO userSessionDAO; |
77 | |
|
78 | |
|
79 | |
private final GovernmentDAO governmentDAO; |
80 | |
|
81 | |
|
82 | |
private final PoliticalPartyDAO politicalPartyDAO; |
83 | |
|
84 | |
|
85 | |
private final DocumentDAO documentDAO; |
86 | |
|
87 | |
|
88 | |
private final RoleDAO roleDAO; |
89 | |
|
90 | |
|
91 | |
private final RegionDAO regionDAO; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public PortalServiceImpl(UserDAO userDAO, EventDAO eventDAO, |
109 | |
PortalDAO portalDAO, CountryDAO countryDAO, |
110 | |
UserSessionDAO userSessionDAO, PoliticalPartyDAO politicalPartyDAO, |
111 | 4 | GovernmentDAO governmentDAO, AgentDAO agentDAO,DocumentDAO documentDAO,RoleDAO roleDAO,RegionDAO regionDAO) { |
112 | 4 | this.userDAO = userDAO; |
113 | 4 | this.eventDAO = eventDAO; |
114 | 4 | this.portalDAO = portalDAO; |
115 | 4 | this.countryDAO = countryDAO; |
116 | 4 | this.userSessionDAO = userSessionDAO; |
117 | 4 | this.politicalPartyDAO = politicalPartyDAO; |
118 | 4 | this.governmentDAO = governmentDAO; |
119 | 4 | this.agentDAO = agentDAO; |
120 | 4 | this.documentDAO = documentDAO; |
121 | 4 | this.roleDAO = roleDAO; |
122 | 4 | this.regionDAO = regionDAO; |
123 | 4 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public List<Event> getEvents() { |
131 | 1 | return this.eventDAO.getAll(); |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public List<Election> getElections() { |
140 | 1 | List<Election> elections = new ArrayList<Election>(); |
141 | |
|
142 | 1 | for (Government government : this.governmentDAO.getAll()) { |
143 | 1 | elections.addAll(government.getElections()); |
144 | 1 | } |
145 | 1 | return elections; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
public List<Government> getGovernments() { |
154 | 0 | return this.governmentDAO.getAllNationalGovernments(); |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public List<Portal> getPortals() { |
163 | 0 | return this.portalDAO.getAll(); |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
public List<Country> getCountries() { |
172 | 0 | return countryDAO.getAll(); |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public PoliticalParty createParty(CreatePartyCommand command, Long userId) |
182 | |
throws PartyAlreadyExistException { |
183 | 0 | if (politicalPartyDAO.findByName(command.getName()) != null) |
184 | 0 | throw new PartyAlreadyExistException(); |
185 | |
|
186 | 0 | Country country = countryDAO.load(command.getCountryId()); |
187 | 0 | PoliticalParty politicalParty = new OnlinePoliticalParty(); |
188 | 0 | politicalParty.setCountry(country); |
189 | 0 | politicalParty.setName(command.getName()); |
190 | 0 | politicalParty.setOrganisationType(OrganisationType.National); |
191 | 0 | politicalParty.setRegion(country); |
192 | 0 | agentDAO.save(politicalParty); |
193 | |
|
194 | 0 | UserRole role = new UserRole(); |
195 | 0 | role.setName(OrganisationRoles.Member.toString()); |
196 | 0 | role.setGroupAgent(politicalParty); |
197 | 0 | politicalParty.getDefinedRoles().add(role); |
198 | |
|
199 | 0 | politicalPartyDAO.save(politicalParty); |
200 | |
|
201 | 0 | UserSession userSession = this.userSessionDAO.findByUserId(userId); |
202 | 0 | if (userSession != null) { |
203 | 0 | userSession.getUser().getEvents().add( |
204 | |
new Event(userSession.getUser(), |
205 | |
Action.Create_Political_Party, new Date())); |
206 | 0 | this.userSessionDAO.save(userSession); |
207 | |
} |
208 | |
|
209 | 0 | return politicalParty; |
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public List<PoliticalParty> getPoliticalParties() { |
218 | 0 | return politicalPartyDAO.getAll(); |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public PoliticalParty getPoliticalParty(Long partyId) { |
227 | 0 | return politicalPartyDAO.load(partyId); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public OnlinePoliticalParty joinParty(Long partyId, Long userId) { |
237 | 0 | PoliticalParty party = politicalPartyDAO.load(partyId); |
238 | |
|
239 | 0 | User user = userDAO.load(userId); |
240 | |
|
241 | 0 | Role partyMember = party.findDefinedRoleByName(OrganisationRoles.Member.toString()); |
242 | |
|
243 | 0 | user.getPerson().getRoles().add(partyMember); |
244 | |
|
245 | 0 | partyMember.getPlayers().add(user.getPerson()); |
246 | 0 | agentDAO.save(party); |
247 | 0 | userDAO.save(user); |
248 | |
|
249 | 0 | UserSession userSession = this.userSessionDAO.findByUserId(userId); |
250 | 0 | if (userSession != null) { |
251 | 0 | userSession.getUser().getEvents().add( |
252 | |
new Event(userSession.getUser(), |
253 | |
Action.Join_Political_Party, new Date())); |
254 | 0 | this.userSessionDAO.save(userSession); |
255 | |
} |
256 | |
|
257 | 0 | return (OnlinePoliticalParty) party; |
258 | |
} |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
public Government getGovernment(Long governmentId) { |
266 | 0 | return governmentDAO.load(governmentId); |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
public List<UserSession> getActiveUserSessions() { |
275 | 0 | return userSessionDAO.getActiveSessions(); |
276 | |
} |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
public List<User> getUsers() { |
284 | 1 | return this.userDAO.getAll(); |
285 | |
} |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
@Override |
293 | |
public GroupAgent getOrganisation(Long organisationId) { |
294 | 0 | return (GroupAgent) this.agentDAO.load(organisationId); |
295 | |
} |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
@Override |
303 | |
public List<OnlinePoliticalParty> getOnlinePoliticalParties() { |
304 | 0 | return politicalPartyDAO.getAllOnline(); |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
@Override |
316 | |
public PoliticalParty createPoliticalParty(String name, String shortCode, |
317 | |
Country country, Region region) { |
318 | 0 | PoliticalParty politicalParty = new PoliticalParty(); |
319 | 0 | politicalParty.setName(name); |
320 | 0 | politicalParty.setShortCode(shortCode); |
321 | 0 | politicalParty.setOrganisationType(OrganisationType.National); |
322 | 0 | politicalParty.setCountry(country); |
323 | 0 | politicalParty.setRegion(region); |
324 | 0 | agentDAO.save(politicalParty); |
325 | |
|
326 | 0 | Role role = new Role(); |
327 | 0 | role.setGroupAgent(politicalParty); |
328 | 0 | role.setName(Organisation.OrganisationRoles.Member.toString()); |
329 | 0 | politicalParty.getDefinedRoles().add(role); |
330 | 0 | agentDAO.save(politicalParty); |
331 | |
|
332 | 0 | return politicalParty; |
333 | |
} |
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
@Override |
342 | |
public void addMember(Organisation organisation, Person person) { |
343 | 0 | organisation.addMember(person); |
344 | 0 | agentDAO.save(person); |
345 | 0 | agentDAO.save(organisation); |
346 | 0 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
@Override |
355 | |
public void addRolePlayed(Role role, Person person) { |
356 | 0 | role.getPlayers().add(person); |
357 | 0 | person.getRoles().add(role); |
358 | 0 | agentDAO.save(person); |
359 | 0 | agentDAO.save(role.getGroupAgent()); |
360 | 0 | } |
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
@Override |
369 | |
public Role createRoleInOrg(String roleName, Organisation organisation) { |
370 | 0 | Role newRole = new Role(); |
371 | 0 | newRole.setGroupAgent(organisation); |
372 | 0 | newRole.setName(roleName); |
373 | 0 | organisation.getDefinedRoles().add(newRole); |
374 | 0 | agentDAO.save(organisation); |
375 | 0 | return newRole; |
376 | |
} |
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
@Override |
388 | |
public Organisation createOrganisation(String name, String abbr, |
389 | |
Country country, Region region, |
390 | |
OrganisationType organisationType, Organisation parent) throws OrganisationAlreadyExistException { |
391 | 0 | if (parent != null) { |
392 | |
|
393 | 0 | if (parent.findOrgByName(name) != null) { |
394 | 0 | throw new OrganisationAlreadyExistException(); |
395 | |
} |
396 | |
|
397 | 0 | Organisation newOrg = new Organisation(); |
398 | 0 | newOrg.setParent(parent); |
399 | 0 | newOrg.setName(name); |
400 | 0 | newOrg.setAbbreviation(abbr); |
401 | 0 | newOrg.setCountry(country); |
402 | 0 | newOrg.setRegion(region); |
403 | 0 | newOrg.setOrganisationType(organisationType); |
404 | 0 | agentDAO.save(newOrg); |
405 | 0 | Role role = new Role(); |
406 | 0 | role.setGroupAgent(newOrg); |
407 | 0 | role.setName(Organisation.OrganisationRoles.Member.toString()); |
408 | 0 | newOrg.getDefinedRoles().add(role); |
409 | 0 | agentDAO.save(newOrg); |
410 | 0 | parent.getChildren().add(newOrg); |
411 | 0 | agentDAO.save(parent); |
412 | 0 | return newOrg; |
413 | |
} else { |
414 | 0 | Organisation newOrg = new Organisation(); |
415 | 0 | newOrg.setName(name); |
416 | 0 | newOrg.setAbbreviation(abbr); |
417 | 0 | newOrg.setCountry(country); |
418 | 0 | newOrg.setRegion(region); |
419 | 0 | newOrg.setOrganisationType(organisationType); |
420 | 0 | agentDAO.save(newOrg); |
421 | 0 | Role role = new Role(); |
422 | 0 | role.setGroupAgent(newOrg); |
423 | 0 | role.setName(Organisation.OrganisationRoles.Member.toString()); |
424 | 0 | newOrg.getDefinedRoles().add(role); |
425 | 0 | agentDAO.save(newOrg); |
426 | 0 | return newOrg; |
427 | |
} |
428 | |
} |
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
@Override |
438 | |
public Government createGovernment(String name,Long countryId , |
439 | |
GovernmentType governmentType,String headOfstate) { |
440 | |
|
441 | 0 | Country country = countryDAO.load(countryId); |
442 | 0 | Government government = new Government(); |
443 | 0 | government.setName(name); |
444 | 0 | government.setCountry(country); |
445 | 0 | government.setRegion(country); |
446 | 0 | government.setGovernmentType(governmentType); |
447 | 0 | government.setOrganisationType(OrganisationType.National); |
448 | 0 | agentDAO.save(government); |
449 | 0 | Role governmentRole = new Role(); |
450 | 0 | governmentRole.setGroupAgent(government); |
451 | 0 | governmentRole |
452 | |
.setName(Organisation.OrganisationRoles.Member.toString()); |
453 | 0 | government.getDefinedRoles().add(governmentRole); |
454 | 0 | agentDAO.save(government); |
455 | |
|
456 | 0 | Role headofstaterole = createRoleInOrg( |
457 | |
Government.GovernmentRoles.Head_of_State.toString(), |
458 | |
government); |
459 | |
|
460 | 0 | Person headOfState = new Person(); |
461 | 0 | headOfState.setName(headOfstate); |
462 | 0 | agentDAO.save(headOfState); |
463 | 0 | addMember(government, headOfState); |
464 | 0 | addRolePlayed(headofstaterole, headOfState); |
465 | |
|
466 | 0 | Portal portal = portalDAO.findByName("Direct Democracy Portal"); |
467 | |
|
468 | 0 | GovernmentPortal governmentPortal = new GovernmentPortal(); |
469 | 0 | governmentPortal |
470 | |
.setName("Direct Democracy Portal " + country.getName()); |
471 | 0 | governmentPortal.setParent(portal); |
472 | 0 | governmentPortal.setCountry(country); |
473 | 0 | governmentPortal.setRegion(country); |
474 | 0 | governmentPortal.setOrganisationType(OrganisationType.National); |
475 | 0 | governmentPortal.setGovernment(government); |
476 | 0 | agentDAO.save(governmentPortal); |
477 | 0 | portal.getChildren().add(governmentPortal); |
478 | 0 | agentDAO.save(portal); |
479 | |
|
480 | 0 | UserRole governmentPortalRole = new UserRole(); |
481 | 0 | governmentPortalRole.setGroupAgent(governmentPortal); |
482 | 0 | governmentPortalRole.setName(Organisation.OrganisationRoles.Member |
483 | |
.toString()); |
484 | 0 | governmentPortal.getDefinedRoles().add(governmentPortalRole); |
485 | 0 | governmentPortalRole.getRoleActions(); |
486 | 0 | agentDAO.save(governmentPortal); |
487 | |
|
488 | 0 | return government; |
489 | |
} |
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
public Portal getGlobalPortal() { |
495 | 0 | Portal portal = portalDAO.findByName("Direct Democracy Portal"); |
496 | 0 | portal.personsActive(); |
497 | |
|
498 | 0 | return portal; |
499 | |
} |
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
@Override |
511 | |
public Government createRegionalGovernment(String name, Country country, |
512 | |
Region region, OrganisationType organisationType, |
513 | |
Government parentGovernment) { |
514 | |
|
515 | 0 | Government government = new Government(); |
516 | 0 | government.setParent(parentGovernment); |
517 | 0 | government.setName(name); |
518 | 0 | government.setCountry(country); |
519 | 0 | government.setRegion(region); |
520 | 0 | government.setGovernmentType(parentGovernment.getGovernmentType()); |
521 | 0 | government.setOrganisationType(organisationType); |
522 | 0 | agentDAO.save(government); |
523 | 0 | Role role = new Role(); |
524 | 0 | role.setGroupAgent(government); |
525 | 0 | role.setName(Organisation.OrganisationRoles.Member.toString()); |
526 | 0 | government.getDefinedRoles().add(role); |
527 | 0 | agentDAO.save(government); |
528 | 0 | parentGovernment.getChildren().add(government); |
529 | 0 | agentDAO.save(parentGovernment); |
530 | |
|
531 | 0 | GovernmentPortal parentGovernmentPortal = portalDAO |
532 | |
.findGovernmentPortal(parentGovernment); |
533 | |
|
534 | 0 | GovernmentPortal governmentPortal = new GovernmentPortal(); |
535 | 0 | governmentPortal.setName("Direct Democracy Portal " |
536 | |
+ government.getName()); |
537 | 0 | governmentPortal.setParent(parentGovernmentPortal); |
538 | 0 | governmentPortal.setCountry(country); |
539 | 0 | governmentPortal.setRegion(region); |
540 | 0 | governmentPortal.setOrganisationType(organisationType); |
541 | 0 | governmentPortal.setGovernment(government); |
542 | 0 | agentDAO.save(governmentPortal); |
543 | 0 | parentGovernmentPortal.getChildren().add(governmentPortal); |
544 | 0 | agentDAO.save(parentGovernmentPortal); |
545 | |
|
546 | 0 | UserRole governmentPortalRole = new UserRole(); |
547 | 0 | governmentPortalRole.setGroupAgent(governmentPortal); |
548 | 0 | governmentPortalRole.setName(Organisation.OrganisationRoles.Member |
549 | |
.toString()); |
550 | 0 | governmentPortal.getDefinedRoles().add(governmentPortalRole); |
551 | 0 | governmentPortalRole.getRoleActions(); |
552 | 0 | agentDAO.save(governmentPortal); |
553 | |
|
554 | 0 | return government; |
555 | |
} |
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
@Override |
561 | |
public void createResolution(Resolution resolution) { |
562 | 0 | documentDAO.save(resolution); |
563 | 0 | } |
564 | |
|
565 | |
|
566 | |
|
567 | |
|
568 | |
@Override |
569 | |
public void setResolutionDecidedDate(Resolution resolution, Date parseDate) { |
570 | 0 | System.out.println("Resolution decied date set " + parseDate); |
571 | 0 | if(!ResolutionState.Decided.equals(resolution.getResolutionState())) { |
572 | 0 | resolution.setResolutionState(ResolutionState.Decided); |
573 | 0 | resolution.setDecidedDate(parseDate); |
574 | 0 | documentDAO.save(resolution); |
575 | |
} |
576 | 0 | } |
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
public List<Resolution> getDecidedResolutions() { |
582 | 0 | return documentDAO.getDecidedResolutionsInDateOrder(); |
583 | |
} |
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
@Override |
589 | |
public void addResolutionIssue(Resolution resolution, Issue issue, |
590 | |
VoteResult voteResult) { |
591 | 0 | if (!resolution.containsIssue(issue.getName())) { |
592 | |
|
593 | 0 | issue.setVoteResult(voteResult); |
594 | 0 | voteResult.setIssue(issue); |
595 | |
|
596 | 0 | issue.setResolution(resolution); |
597 | 0 | resolution.getIssues().add(issue); |
598 | |
|
599 | 0 | documentDAO.save(resolution); |
600 | 0 | System.out.println("issue saved " + issue.getName()); |
601 | |
} else { |
602 | 0 | System.out.println("issue ignored " + issue.getName()); |
603 | |
} |
604 | 0 | } |
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
@Override |
610 | |
public void updateVoteResult(VoteResult voteResult) { |
611 | 0 | documentDAO.save(voteResult); |
612 | 0 | } |
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
@Override |
618 | |
public Organisation createOrgUnit(String orgName, String shortName, |
619 | |
OrganisationType organisationType, Long orgId) throws OrganisationAlreadyExistException { |
620 | 0 | Organisation org = (Organisation) agentDAO.load(orgId); |
621 | |
|
622 | 0 | return createOrganisation(orgName, shortName, org.getCountry(), org.getRegion(), organisationType, org); |
623 | |
} |
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
@Override |
629 | |
public Organisation findOrgByName(String name) { |
630 | 0 | return (Organisation) agentDAO.findByName(name); |
631 | |
} |
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
@Override |
637 | |
public Person findMemberByNameInOrg(Long orgId, String name) { |
638 | 0 | Organisation organisation = (Organisation) agentDAO.load(orgId); |
639 | 0 | return organisation.findMemberByName(name); |
640 | |
} |
641 | |
|
642 | |
|
643 | |
|
644 | |
|
645 | |
@Override |
646 | |
public void addMemberById(Long orgId, Long personId) { |
647 | 0 | Organisation organisation = (Organisation) agentDAO.load(orgId); |
648 | 0 | Person person = (Person) agentDAO.load(personId); |
649 | 0 | addMember(organisation, person); |
650 | 0 | } |
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
@Override |
656 | |
public void addRolePlayedById(Long roleId, Long agentId) { |
657 | 0 | Role role = roleDAO.load(roleId); |
658 | 0 | Person person = (Person) agentDAO.load(agentId); |
659 | 0 | addRolePlayed(role, person); |
660 | 0 | } |
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | |
@Override |
666 | |
public Country createCountry(String name) { |
667 | 0 | Region world = countryDAO.findRegionByName("World"); |
668 | |
|
669 | 0 | Country country = new Country(); |
670 | 0 | country.setName(name); |
671 | 0 | country.setParent(world); |
672 | 0 | country.setRegionType(RegionType.National); |
673 | 0 | countryDAO.save(country); |
674 | 0 | world.getParts().add(country); |
675 | |
|
676 | 0 | countryDAO.saveRegion(world); |
677 | 0 | return country; |
678 | |
} |
679 | |
|
680 | |
|
681 | |
|
682 | |
|
683 | |
@Override |
684 | |
public Country findCountryByName(String name) { |
685 | 0 | return countryDAO.findByName(name); |
686 | |
} |
687 | |
|
688 | |
|
689 | |
|
690 | |
|
691 | |
public void createElection(String name, ElectionType electionType,Long governmentid) { |
692 | 0 | Government government = governmentDAO.load(governmentid); |
693 | 0 | Election election = new Election(); |
694 | 0 | election.setName(name); |
695 | 0 | election.setType(electionType); |
696 | 0 | election.setGovernment(government); |
697 | 0 | government.getElections().add(election); |
698 | 0 | agentDAO.save(government); |
699 | 0 | } |
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
@Override |
705 | |
public PoliticalParty createPoliticalPartyById(String name, |
706 | |
String shortCode, Long countryId) { |
707 | 0 | Country country = countryDAO.load(countryId); |
708 | |
|
709 | 0 | return createPoliticalParty(name, shortCode, country, country); |
710 | |
} |
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
@Override |
716 | |
public void createOrganisationById(String name, String abbr, |
717 | |
Long countryId,Long regionId, OrganisationType organisationType, Long orgId) throws DataAccessException, OrganisationAlreadyExistException { |
718 | |
|
719 | 0 | Country country = countryDAO.load(countryId); |
720 | 0 | Region region = regionDAO.load(regionId); |
721 | |
|
722 | 0 | createOrganisation(name, abbr, country, region, organisationType,(Organisation) agentDAO.load(orgId)); |
723 | 0 | } |
724 | |
|
725 | |
|
726 | |
|
727 | |
|
728 | |
@Override |
729 | |
public PoliticalParty findPartyByShortCode(String shortCode) { |
730 | 0 | return politicalPartyDAO.findByShortCode(shortCode); |
731 | |
} |
732 | |
|
733 | |
|
734 | |
|
735 | |
|
736 | |
@Override |
737 | |
public Person createPerson(String name) { |
738 | 0 | Person person= new Person(); |
739 | 0 | person.setName(name); |
740 | 0 | agentDAO.save(person); |
741 | 0 | return person; |
742 | |
} |
743 | |
|
744 | |
|
745 | |
|
746 | |
|
747 | |
@Override |
748 | |
public Region findRegionByName(String name) { |
749 | 0 | return regionDAO.findByName(name); |
750 | |
} |
751 | |
|
752 | |
} |