01: package org.osbl.orga.logic;
02:
03: import org.osbl.orga.model.*;
04: import org.osbl.persistence.logic.DefaultTreeLogic;
05: import org.hibernate.*;
06:
07: import java.util.*;
08:
09: /**
10: * @author hengels
11: * @version $Revision$
12: */
13: public class DefaultOrgaStructureLogic extends
14: DefaultTreeLogic<Organisation, Group> implements
15: OrgaStructureLogic {
16: protected String getNodeType() {
17: return Group.class.getName();
18: }
19:
20: protected String getTreeType() {
21: return Organisation.class.getName();
22: }
23:
24: public List<Group> groupsByContainedGroup(Long tree,
25: Long groupName, String inRole) {
26: return null; //To change body of implemented methods use File | Settings | File Templates.
27: }
28:
29: public List<Group> groupsByContainedIdentity(Long tree,
30: Long identity, String role) {
31: Session session = sessionFactory.getCurrentSession();
32: Query query = session
33: .createQuery("select n from Group n join n.memberships as m where n.tree = :tree and m.role = :role and m.member.identity.id = :identity");
34: query.setLong("tree", tree);
35: query.setLong("identity", identity);
36: query.setString("role", role);
37: return query.list();
38: }
39:
40: public List<Membership> memberships(Long identity) {
41: Session session = sessionFactory.getCurrentSession();
42: Query query = session
43: .createQuery("select m from Membership m where m.member.identity = :identity");
44: query.setLong("identity", identity);
45: return query.list();
46: }
47:
48: public List<Relationship> relationships(Long identity) {
49: Session session = sessionFactory.getCurrentSession();
50: Query query = session
51: .createQuery("select r from Relationship r where r.member.identity = :identity");
52: query.setLong("identity", identity);
53: return query.list();
54: }
55:
56: public int importMembers(Organisation organisation, String createdBy) {
57: Session session = sessionFactory.getCurrentSession();
58: Query query = session
59: .createQuery("insert into Member (key, created, createdBy, organisation, identity)"
60: + " select '"
61: + organisation.getKey()
62: + "'||'_'||i.key, current_timestamp(), '"
63: + createdBy
64: + "', (select o from Organisation o where o = :organisation), i from Identity i"
65: + " where i not in (select m.identity from Member m where m.organisation = :organisation)");
66: query.setParameter("organisation", organisation);
67: return query.executeUpdate();
68: }
69: }
|