KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > core > impl > GroupManagerImpl


1 /*
2  * Copyright 2005 Blandware (http://www.blandware.com)
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 com.blandware.atleap.service.core.impl;
17
18 import com.blandware.atleap.service.core.GroupManager;
19 import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
20 import com.blandware.atleap.service.exception.BeanNotFoundException;
21 import com.blandware.atleap.persistence.core.RoleDAO;
22 import com.blandware.atleap.persistence.core.GroupDAO;
23 import com.blandware.atleap.model.core.Role;
24 import com.blandware.atleap.model.core.Group;
25 import com.blandware.atleap.common.util.PartialCollection;
26 import com.blandware.atleap.common.util.QueryInfo;
27
28 /**
29  * <p>Implementation of GroupManager interface.
30  * </p>
31  * <p><a HREF="GroupManagerImpl.java.htm"><i>View source</i></a></p>
32  *
33  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
34  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
35  * @version $Revision: 1.1 $ $Date: 2006/03/06 18:12:30 $
36  */

37 public class GroupManagerImpl extends BaseManagerImpl implements GroupManager {
38
39     /**
40      * Group DAO
41      */

42     protected GroupDAO groupDAO;
43
44     /**
45      * Sets DAO to work with groups
46      *
47      * @param dao DAO to set
48      */

49     public void setGroupDAO(GroupDAO dao) {
50         this.groupDAO = dao;
51     }
52
53     // ~ CRUD Methods ================================================================
54

55     /**
56      * @see com.blandware.atleap.service.core.GroupManager#createGroup(com.blandware.atleap.model.core.Group)
57      */

58     public void createGroup(Group group) throws BeanAlreadyExistsException {
59         if ( log.isDebugEnabled() ) {
60             log.debug("Creating new Group [groupName=" + group.getName() + "]...");
61         }
62
63         // check is done directly, because it is impossible to write one query for create and update methods
64
Group tmp = groupDAO.retrieveGroup(group.getName());
65         if ( tmp != null ) {
66             // group with the same name already exists
67
String JavaDoc errorMessage = "Group with the name '" + group.getName() + "' already exists";
68             if ( log.isErrorEnabled() ) {
69                 log.error(errorMessage);
70             }
71             throw new BeanAlreadyExistsException(errorMessage);
72         }
73         tmp = groupDAO.findGroupByTitle(group.getTitle());
74         if ( tmp != null ) {
75             // group with the same title already exists
76
String JavaDoc errorMessage = "Group with the title '" + group.getTitle() + "' already exists";
77             if ( log.isErrorEnabled() ) {
78                 log.error(errorMessage);
79             }
80             throw new BeanAlreadyExistsException(errorMessage);
81         }
82         groupDAO.createGroup(group);
83
84         if ( log.isDebugEnabled() ) {
85             log.debug("New group has been created succesfully");
86         }
87     }
88
89     /**
90      * @see com.blandware.atleap.service.core.GroupManager#retrieveGroup(String)
91      */

92     public Group retrieveGroup(String JavaDoc groupName) {
93         Group group = null;
94         group = groupDAO.retrieveGroup(groupName);
95         return group;
96     }
97
98     /**
99      * @see com.blandware.atleap.service.core.GroupManager#updateGroup(com.blandware.atleap.model.core.Group)
100      */

101     public void updateGroup(Group group) throws BeanAlreadyExistsException {
102
103         // remove group from cache in order to prevent Hibernate from assigning new version number
104
groupDAO.removeFromCache(group);
105         if ( log.isDebugEnabled() ) {
106             log.debug("Updating Group [groupName=" + group.getName() + "]...");
107         }
108
109         if ( groupDAO.hasDuplicates(group) ) {
110             throw new BeanAlreadyExistsException("Group with the same title already exists");
111         }
112
113         groupDAO.updateGroup(group);
114
115         if ( log.isDebugEnabled() ) {
116             log.debug("Group has been updated succesfully");
117         }
118     }
119
120     /**
121      * @see com.blandware.atleap.service.core.GroupManager#deleteGroup(String)
122      */

123     public void deleteGroup(String JavaDoc groupName) throws BeanNotFoundException {
124         Group group = groupDAO.retrieveGroup(groupName);
125         if ( group == null ) {
126             String JavaDoc errorMessage = "No group with ID=" + group + "could be found";
127             throw new BeanNotFoundException(errorMessage);
128         }
129         groupDAO.deleteGroup(group);
130     }
131
132     // ~ Additional methods ================================================================
133

134     /**
135      * @see com.blandware.atleap.service.core.GroupManager#listGroups(com.blandware.atleap.common.util.QueryInfo)
136      */

137     public PartialCollection listGroups(QueryInfo queryInfo) {
138         return groupDAO.listGroups(queryInfo);
139     }
140
141 }
142
Popular Tags