1 5 package org.exoplatform.services.organization.hibernate; 6 7 import java.util.Collection ; 8 import java.util.List ; 9 10 import org.exoplatform.commons.utils.ListenerStack; 11 import org.exoplatform.commons.utils.PageList; 12 import org.exoplatform.services.database.HibernateService; 13 import org.exoplatform.services.organization.Group; 14 import org.exoplatform.services.organization.GroupEventListener; 15 import org.exoplatform.services.organization.Membership; 16 import org.exoplatform.services.organization.MembershipEventListener; 17 import org.exoplatform.services.organization.MembershipType; 18 import org.exoplatform.services.organization.OrganizationService; 19 import org.exoplatform.services.organization.OrganizationServiceListener; 20 import org.exoplatform.services.organization.Query; 21 import org.exoplatform.services.organization.User; 22 import org.exoplatform.services.organization.UserEventListener; 23 import org.exoplatform.services.organization.UserProfile; 24 import org.exoplatform.services.organization.UserProfileEventListener; 25 import org.exoplatform.services.organization.impl.GroupImpl; 26 import org.exoplatform.services.organization.impl.MembershipImpl; 27 import org.exoplatform.services.organization.impl.MembershipTypeImpl; 28 import org.exoplatform.services.organization.impl.UserImpl; 29 import org.exoplatform.services.organization.impl.UserProfileImpl; 30 import org.picocontainer.Startable; 31 32 33 42 public class OrganizationServiceImpl implements OrganizationService, Startable { 43 44 static private String [] MAPPING = 45 { 46 "org/exoplatform/services/organization/impl/UserImpl.hbm.xml", 47 "org/exoplatform/services/organization/impl/MembershipImpl.hbm.xml" , 48 "org/exoplatform/services/organization/impl/GroupImpl.hbm.xml" , 49 "org/exoplatform/services/organization/impl/MembershipTypeImpl.hbm.xml" , 50 "org/exoplatform/services/organization/hibernate/UserProfileData.hbm.xml" 51 } ; 52 53 UserQueryHandler userQueryHandler_ ; 54 UserProfileQueryHandler userProfileQueryHandler_ ; 55 GroupQueryHandler groupQueryHandler_ ; 56 MembershipQueryHandler membershipQueryHandler_ ; 57 MembershipTypeQueryHandler membershipTypeQueryHandler_ ; 58 private List listeners_ ; 59 60 public OrganizationServiceImpl(HibernateService hibernateService, 61 UserQueryHandler userQueryHandler, 62 GroupQueryHandler groupQueryHandler, 63 MembershipQueryHandler membershipQueryHandler, 64 MembershipTypeQueryHandler membershipTypeQueryHandler, 65 UserProfileQueryHandler userProfileQueryHandler) { 66 hibernateService.addMappingFiles(MAPPING) ; 67 68 userQueryHandler_ = userQueryHandler ; 69 userProfileQueryHandler_ = userProfileQueryHandler ; 70 groupQueryHandler_ = groupQueryHandler ; 71 membershipQueryHandler_ = membershipQueryHandler ; 72 membershipTypeQueryHandler_ = membershipTypeQueryHandler ; 73 listeners_ = new ListenerStack(5) ; 74 } 75 76 public void start() { 77 for(int i = 0 ; i < listeners_.size(); i++) { 78 OrganizationServiceListener listener = (OrganizationServiceListener) listeners_.get(i) ; 79 listener.inititalize(this) ; 80 } 81 } 82 83 public void stop() {} 84 85 synchronized public void addListener(OrganizationServiceListener listener) { 86 listeners_.add(listener) ; 87 } 88 89 90 synchronized public void removeListener(OrganizationServiceListener listener) { 91 listeners_.remove(listener) ; 92 } 93 94 public User createUserInstance() { 95 return new UserImpl() ; 96 } 97 98 final public List getUserEventListeners() { 99 return userQueryHandler_.getUserEventListeners() ; 100 } 101 102 public void addUserEventListener(UserEventListener listener) { 103 userQueryHandler_.addUserEventListener(listener) ; 104 } 105 106 final public void createUser(User user) throws Exception { 107 userQueryHandler_.createUser(user) ; 108 } 109 110 final public void saveUser(User user) throws Exception { 111 userQueryHandler_.saveUser(user) ; 112 } 113 114 115 final public User removeUser(String user) throws Exception { 116 return userQueryHandler_.removeUser(user) ; 117 } 118 119 120 final public User findUserByName(String userName) throws Exception { 121 return userQueryHandler_.findUserByName(userName) ; 122 } 123 124 public PageList getUserPageList(int pageSize) throws Exception { 125 return userQueryHandler_.getUserPageList(pageSize) ; 126 } 127 128 final public PageList findUsers(Query query) throws Exception { 129 return userQueryHandler_.findUsers(query) ; 130 } 131 132 final public PageList findUsersByGroup(String groupId) throws Exception { 133 return userQueryHandler_.findUsersByGroup(groupId) ; 134 } 135 136 public void addUserProfileEventListener(UserProfileEventListener listener) { 137 userProfileQueryHandler_.addUserProfileEventListener(listener) ; 138 } 139 140 141 final public UserProfile createUserProfileInstance() { 142 return new UserProfileImpl() ; 143 } 144 145 final public void saveUserProfile(UserProfile profile) throws Exception { 146 userProfileQueryHandler_.saveUserProfile(profile) ; 147 } 148 149 final public UserProfile removeUserProfile(String user) throws Exception { 150 return userProfileQueryHandler_.removeUserProfile(user) ; 151 } 152 153 final public UserProfile findUserProfileByName(String userName) throws Exception { 154 return userProfileQueryHandler_.findUserProfileByName(userName) ; 155 } 156 157 final public Collection findUserProfiles() throws Exception { 158 return userProfileQueryHandler_.findUserProfiles() ; 159 } 160 161 public void addGroupEventListener(GroupEventListener listener) { 162 groupQueryHandler_.addGroupEventListener(listener) ; 163 } 164 165 final public Group createGroupInstance() { 166 return new GroupImpl(); 167 } 168 169 final public void createGroup(Group group) throws Exception { 170 groupQueryHandler_.createGroup(group) ; 171 } 172 173 final public void addChild(Group parent, Group child) throws Exception { 174 groupQueryHandler_.addChild(parent, child) ; 175 } 176 177 final public void saveGroup(Group group) throws Exception { 178 groupQueryHandler_.saveGroup(group) ; 179 } 180 181 final public Group removeGroup(Group group) throws Exception { 182 return groupQueryHandler_.removeGroup(group) ; 183 } 184 185 final public Collection findGroupByMembership(String userName, String membershipType) throws Exception { 186 return groupQueryHandler_.findGroupByMembership(userName, membershipType) ; 187 } 188 189 public Group findGroupById(String groupId) throws Exception { 190 return groupQueryHandler_.findGroupById(groupId) ; 191 } 192 193 final public Collection findGroups(Group parent) throws Exception { 194 return groupQueryHandler_.findGroups(parent) ; 195 } 196 197 final public Collection findGroupsOfUser(String user) throws Exception { 198 return groupQueryHandler_.findGroupsOfUser(user) ; 199 } 200 201 public void addMembershipEventListener(MembershipEventListener listener) { 202 membershipQueryHandler_.addMembershipEventListener(listener) ; 203 } 204 205 final public Membership createMembershipInstance() { 206 return new MembershipImpl(); 207 } 208 209 final public void createMembership(Membership m) throws Exception { 210 membershipQueryHandler_.createMembership(m) ; 211 } 212 213 final public void linkMembership(String userName, Group group, Membership m) throws Exception { 214 membershipQueryHandler_.linkMembership(userName, group, m) ; 215 } 216 217 final public void saveMembership(Membership m) throws Exception { 218 membershipQueryHandler_.saveMembership( m) ; 219 } 220 221 final public Membership removeMembership(String id) throws Exception { 222 return membershipQueryHandler_.removeMembership(id) ; 223 } 224 225 public Membership findMembershipByUserGroupAndType(String userName, 226 String groupId, 227 String type) throws Exception { 228 return membershipQueryHandler_.findMembershipByUserGroupAndType(userName, groupId, type) ; 229 } 230 231 final public Collection findMembershipsByUserAndGroup(String userName, String groupId) throws Exception { 232 return membershipQueryHandler_.findMembershipsByUserAndGroup(userName, groupId) ; 233 } 234 235 final public Collection findMembershipsByUser(String userName) throws Exception { 236 return membershipQueryHandler_.findMembershipsByUser(userName) ; 237 } 238 239 final public Collection findMembershipsByGroup(Group group) throws Exception { 240 return membershipQueryHandler_.findMembershipsByGroup(group) ; 241 } 242 243 final public Membership findMembership(String id) throws Exception { 244 return membershipQueryHandler_.findMembership(id) ; 245 } 246 247 final public MembershipType createMembershipTypeInstance() { 248 return new MembershipTypeImpl() ; 249 } 250 251 final public MembershipType createMembershipType(MembershipType mt) throws Exception { 252 return membershipTypeQueryHandler_.createMembershipType(mt) ; 253 } 254 255 final public MembershipType saveMembershipType(MembershipType mt) throws Exception { 256 return membershipTypeQueryHandler_.saveMembershipType(mt) ; 257 } 258 259 final public MembershipType findMembershipType(String name) throws Exception { 260 return membershipTypeQueryHandler_.findMembershipType(name) ; 261 } 262 263 final public MembershipType removeMembershipType(String name) throws Exception { 264 return membershipTypeQueryHandler_.removeMembershipType(name) ; 265 } 266 267 final public Collection findMembershipTypes() throws Exception { 268 return membershipTypeQueryHandler_.findMembershipTypes() ; 269 } 270 271 public boolean authenticate(String username, String password) throws Exception { 272 User user = findUserByName(username); 273 if(user == null) return false ; 274 return user.getPassword().equals(password) ; 275 } 276 } | Popular Tags |