[Comsuite-svn] SF.net SVN: comsuite: [125] trunk/code/CSMiddleware/src/org/commsuite/dao/ hibernate
Brought to you by:
zduniak
|
From: <ma...@us...> - 2006-09-03 09:40:04
|
Revision: 125
http://svn.sourceforge.net/comsuite/?rev=125&view=rev
Author: marasm
Date: 2006-09-03 02:38:59 -0700 (Sun, 03 Sep 2006)
Log Message:
-----------
javadocs added
Modified Paths:
--------------
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ActionDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ContentsDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/GroupDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/MessageDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/RoleDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SAPInstanceDefDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SentContentDaoImpl.java
trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/UserDaoImpl.java
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ActionDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ActionDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ActionDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -27,88 +27,111 @@
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
- * Class to communicate with database - gets and saves actions. Uses hibernate
+ * Class to communicate with database - gets and saves Actions. Uses hibernate
*
* @since 1.0
* @author Marek Musielak
*/
public class ActionDaoImpl extends HibernateDaoSupport implements ActionDao {
-
+
public ActionDaoImpl() {
super();
}
/**
+ * Lists all Actions
+ *
* @return list of all actions
*/
@SuppressWarnings("unchecked")
public List<Action> getActions() {
- final List<Action> actionsList = getHibernateTemplate().loadAll(Action.class);
+ final List<Action> actionsList = getHibernateTemplate().loadAll(
+ Action.class);
return actionsList;
}
/**
* Saves or updates action in database
*
- * @param action - action to save in db
+ * @param action -
+ * action to save in db
* @return saved action
*/
public Action saveAction(Action action) {
getHibernateTemplate().saveOrUpdate(action);
return action;
}
-
+
/**
- * @param id of action
- * @return action with specified id
+ * return Action with specified id
+ *
+ * @param id
+ * of action
+ * @return action with specified id or null if action with given id does not
+ * exist
*/
public Action getAction(Long id) {
- final List list = getHibernateTemplate().find("from Action a where a.id = ?", id);
+ final List list = getHibernateTemplate().find(
+ "from Action a where a.id = ?", id);
return (Action) (list.size() > 0 ? list.get(0) : null);
}
/**
* Deletes action with specified id from database.
- * @param id of action
+ *
+ * @param id
+ * of action
*/
public void deleteAction(Long id) {
- final List list = getHibernateTemplate().find("from Action a where a.id = ?", id);
- if (list.size() > 0){
- Object action = (Action)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Action a where a.id = ?", id);
+ if (list.size() > 0) {
+ Object action = (Action) list.get(0);
getHibernateTemplate().delete(action);
}
}
/**
* deletes specified action
- * @param action to delete
+ *
+ * @param action
+ * to delete
*/
public void deleteAction(Action action) {
- final List list = getHibernateTemplate().find("from Action a where a.id = ?", action.getId());
- if (list.size() > 0){
- Object actionToDelete = (Action)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Action a where a.id = ?", action.getId());
+ if (list.size() > 0) {
+ Object actionToDelete = (Action) list.get(0);
getHibernateTemplate().delete(actionToDelete);
}
}
/**
- * @param id - id of Role
+ * lists all Actions for Role with given id
+ *
+ * @param id -
+ * id of Role
* @return list of actions for Role with given id
*/
@SuppressWarnings("unchecked")
- public List<Action> getActionsByRole(String id){
+ public List<Action> getActionsByRole(String id) {
String query = "select action from Action action join action.roles role where role.id = ?";
- List<Action> result = getHibernateTemplate().find(query, Long.valueOf(id));
+ List<Action> result = getHibernateTemplate().find(query,
+ Long.valueOf(id));
return result;
}
/**
- * @param name - name of actions
+ * lists Actions with given name
+ *
+ * @param name -
+ * name of actions
* @return list of actions with specified name
*/
@SuppressWarnings("unchecked")
public List<Action> getActions(String name) {
- final List list = getHibernateTemplate().find("select a from Action a where a.name like '%"+ name+ "%'");
+ final List list = getHibernateTemplate().find(
+ "select a from Action a where a.name like '%" + name + "%'");
return list;
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ContentsDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ContentsDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/ContentsDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -27,7 +27,7 @@
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
- * Class to communicate with database - gets and saves actions. Uses hibernate
+ * Class to communicate with database - gets and saves Contents. Uses hibernate
*
* @since 1.0
* @author Marek Musielak
@@ -39,18 +39,22 @@
}
/**
+ * lists all Contents
+ *
* @return list of all contents
*/
@SuppressWarnings("unchecked")
public List<Contents> getContentsList() {
- final List<Contents> contentsList = getHibernateTemplate().loadAll(Contents.class);
+ final List<Contents> contentsList = getHibernateTemplate().loadAll(
+ Contents.class);
return contentsList;
}
/**
* Saves or updates contents in database
*
- * @param contents - contents to save in db
+ * @param contents -
+ * contents to save in db
* @return saved contents
*/
public Contents saveContents(Contents contents) {
@@ -59,56 +63,73 @@
}
/**
- * @param id of Contents
- * @return Contents with specified id
+ * get Contents with specified id from database
+ *
+ * @param id
+ * of Contents
+ * @return Contents with specified id or null if Contents with given id does
+ * not exist
*/
public Contents getContents(Long id) {
- final List list = getHibernateTemplate().find("from Contents c where c.id = ?", id);
+ final List list = getHibernateTemplate().find(
+ "from Contents c where c.id = ?", id);
return (Contents) (list.size() > 0 ? list.get(0) : null);
}
/**
* Deletes contents with specified id from database.
- * @param id of contents
+ *
+ * @param id
+ * of contents
*/
public void deleteContents(Long id) {
- final List list = getHibernateTemplate().find("from Contents c where c.id = ?", id);
- if (list.size() > 0){
- Object contents = (Contents)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Contents c where c.id = ?", id);
+ if (list.size() > 0) {
+ Object contents = (Contents) list.get(0);
getHibernateTemplate().delete(contents);
}
}
/**
* deletes specified contents
- * @param contents to delete
+ *
+ * @param contents
+ * to delete
*/
public void deleteContents(Contents contents) {
- final List list = getHibernateTemplate().find("from Contents c where c.id = ?", contents.getId());
- if (list.size() > 0){
- Object contentsToDelete = (Contents)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Contents c where c.id = ?", contents.getId());
+ if (list.size() > 0) {
+ Object contentsToDelete = (Contents) list.get(0);
getHibernateTemplate().delete(contentsToDelete);
}
}
-
+
/**
- * @param id - id of message
+ * lists Contents for Message with given id
+ *
+ * @param id -
+ * id of message
* @return list of contents for Message with given id
*/
@SuppressWarnings("unchecked")
public List<Contents> getContentsByMessage(String id) {
- String query = "select s.content from SentContent s where s.message.id = ? order by s.id";
- return getHibernateTemplate().find(query, Long.valueOf(id));
- }
-
+ String query = "select s.content from SentContent s where s.message.id = ? order by s.id";
+ return getHibernateTemplate().find(query, Long.valueOf(id));
+ }
+
/**
- * @param id - id of SentContent
+ * lists all Contents for SentContent with given id
+ *
+ * @param id -
+ * id of SentContent
* @return list of contents for SentContent with given id
*/
@SuppressWarnings("unchecked")
public List<Contents> getContentsBySentContent(String id) {
- String query = "select s.content from SentContent s where s.id = ? order by s.id";
- return getHibernateTemplate().find(query, Long.valueOf(id));
- }
-
+ String query = "select s.content from SentContent s where s.id = ? order by s.id";
+ return getHibernateTemplate().find(query, Long.valueOf(id));
+ }
+
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/GroupDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/GroupDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/GroupDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -1,23 +1,23 @@
- /* $Id$
- *
- * Communications Suite.
- * Copyright (C) 2006 Szymon Kuzniak, Rafal Malinowski, Marek Musielak, Pawel Walkiewicz,
- * Agnieszka Wisniewska, Marcin Zduniak, Liliana Ziolek.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
+/* $Id$
+ *
+ * Communications Suite.
+ * Copyright (C) 2006 Szymon Kuzniak, Rafal Malinowski, Marek Musielak, Pawel Walkiewicz,
+ * Agnieszka Wisniewska, Marcin Zduniak, Liliana Ziolek.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
package org.commsuite.dao.hibernate;
import java.util.List;
@@ -36,7 +36,7 @@
* @author Szymon Kuzniak
*/
public class GroupDaoImpl extends HibernateDaoSupport implements GroupDao {
-
+
private static final Logger logger = Logger.getLogger(GroupDaoImpl.class);
public GroupDaoImpl() {
@@ -44,77 +44,98 @@
}
/**
+ * lists all Groups from database
+ *
* @return list of all groups
*/
@SuppressWarnings("unchecked")
public List<Group> getGroups() {
- final List<Group> groupsList = getHibernateTemplate().loadAll(Group.class);
+ final List<Group> groupsList = getHibernateTemplate().loadAll(
+ Group.class);
return groupsList;
}
/**
* Saves or updates group in database
*
- * @param group - group to save in db
+ * @param group -
+ * group to save in db
* @return saved group
*/
public Group saveGroup(Group group) {
- logger.debug("ROLES BEFORE SAVE: "+ group.getRoles());
+ logger.debug("ROLES BEFORE SAVE: " + group.getRoles());
getHibernateTemplate().saveOrUpdate(group);
- logger.debug("ROLES AFTER SAVE: "+ group.getRoles());
+ logger.debug("ROLES AFTER SAVE: " + group.getRoles());
return group;
}
/**
- * @param id of group
- * @return group with specified id
+ * @param id
+ * of group
+ * @return group with specified id or null if Group with given id does not
+ * exist
*/
public Group getGroup(Long id) {
- final List list = getHibernateTemplate().find("from Group g where g.id = ?", id);
+ final List list = getHibernateTemplate().find(
+ "from Group g where g.id = ?", id);
return (Group) (list.size() > 0 ? list.get(0) : null);
}
/**
* Deletes group with specified id from database.
- * @param id of group
+ *
+ * @param id
+ * of group
*/
public void deleteGroup(Long id) {
- final List list = getHibernateTemplate().find("from Group g where g.id = ?", id);
- if (list.size() > 0){
- Object group = (Group)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Group g where g.id = ?", id);
+ if (list.size() > 0) {
+ Object group = (Group) list.get(0);
getHibernateTemplate().delete(group);
}
}
/**
* deletes specified group
- * @param group to delete
+ *
+ * @param group
+ * to delete
*/
public void deleteGroup(Group group) {
- final List list = getHibernateTemplate().find("from Group g where g.id = ?", group.getId());
- if (list.size() > 0){
- Object groupToDelete = (Group)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Group g where g.id = ?", group.getId());
+ if (list.size() > 0) {
+ Object groupToDelete = (Group) list.get(0);
getHibernateTemplate().delete(groupToDelete);
}
}
/**
- * @param name - name of groups
+ * lists all Groups with given name
+ *
+ * @param name -
+ * name of groups
* @return list of groups with specified name
*/
@SuppressWarnings("unchecked")
public List<Group> getGroups(String name) {
- final List list = getHibernateTemplate().find("select g from Group g where g.name like '%"+ name+ "%'");
+ final List list = getHibernateTemplate().find(
+ "select g from Group g where g.name like '%" + name + "%'");
return list;
}
-
+
/**
- * @param id - id of group
- * @return list of roles directly attached to group with given id
+ * lists all Groups directly attached to given user
+ *
+ * @param id -
+ * id of group
+ * @return list of groups directly attached to user with given id
*/
@SuppressWarnings("unchecked")
public List<Group> getGroupsDirectlyAttachedToUser(Long userId) {
- return (List<Group>)getHibernateTemplate().find("select g from User u join u.groups g where u.id = ?", userId);
+ return (List<Group>) getHibernateTemplate().find(
+ "select g from User u join u.groups g where u.id = ?", userId);
}
-
+
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/MessageDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/MessageDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/MessageDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -41,160 +41,197 @@
*/
public class MessageDaoImpl extends HibernateDaoSupport implements MessageDao {
- private final static Logger logger = Logger.getLogger(MessageDaoImpl.class);
+ private final static Logger logger = Logger.getLogger(MessageDaoImpl.class);
- public MessageDaoImpl() {
- super();
- }
+ public MessageDaoImpl() {
+ super();
+ }
/**
+ * lists all Messages from database
+ *
* @return list of all messages
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public List<Message> getMessages() {
- final List<Message> messagesList = getHibernateTemplate().loadAll(Message.class);
+ final List<Message> messagesList = getHibernateTemplate().loadAll(
+ Message.class);
return messagesList;
- }
+ }
/**
* Saves or updates message in database
*
- * @param message - message to save in db
+ * @param message -
+ * message to save in db
* @return saved message
*/
- public Message saveMessage(Message message) {
- for (SentContent sc : message.getSentContents()) {
+ public Message saveMessage(Message message) {
+ for (SentContent sc : message.getSentContents()) {
getHibernateTemplate().saveOrUpdate(sc.getContent());
getHibernateTemplate().saveOrUpdate(sc.getMessage());
getHibernateTemplate().saveOrUpdate(sc);
}
- return message;
- }
+ return message;
+ }
/**
- * @param id of message
- * @return message with specifies id
+ * get message with specified id
+ *
+ * @param id
+ * of message
+ * @return message with specifies id or null if Message with given id does
+ * not exist
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public Message getMessage(Long id) {
- final List<Message> list = getHibernateTemplate().find("from Message m where m.id = ?", id);
- return (list.size() > 0 ? list.get(0) : (Message) null);
- }
+ final List<Message> list = getHibernateTemplate().find(
+ "from Message m where m.id = ?", id);
+ return (list.size() > 0 ? list.get(0) : (Message) null);
+ }
/**
- * Deletes message with specified id from database. It deletes also all sentContents of this message
- * and Contents (if there are not used anymore)
+ * Deletes message with specified id from database. It deletes also all
+ * sentContents of this message and Contents (if there are not used anymore)
*
- * @param id of message
+ * @param id
+ * of message
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public void deleteMessage(Long id) {
- final List<Message> list = getHibernateTemplate().find("from Message m where m.id = ?", id);
- for (Message message : list) {
- final List<Contents> contentsList = message.listContents();
-
- for (SentContent sentContent : message.getSentContents()) {
- sentContent.getContent().removeSentContentByInternalId(sentContent.getInternalId());
+ final List<Message> list = getHibernateTemplate().find(
+ "from Message m where m.id = ?", id);
+ for (Message message : list) {
+ final List<Contents> contentsList = message.listContents();
+
+ for (SentContent sentContent : message.getSentContents()) {
+ sentContent.getContent().removeSentContentByInternalId(
+ sentContent.getInternalId());
getHibernateTemplate().delete(sentContent);
}
-
- for (Contents contents : contentsList) {
- if (0 == contents.getSentContents().size()){
+
+ for (Contents contents : contentsList) {
+ if (0 == contents.getSentContents().size()) {
getHibernateTemplate().delete(contents);
}
}
-
- getHibernateTemplate().delete(message);
+
+ getHibernateTemplate().delete(message);
}
- }
+ }
/**
* deletes specified message
- * @param message to delete
+ *
+ * @param message
+ * to delete
*/
- public void deleteMessage(Message message) {
- deleteMessage(message.getId());
- }
+ public void deleteMessage(Message message) {
+ deleteMessage(message.getId());
+ }
/**
- * @param sapID - id given to message by sap server
- * @param sapInstanceDef - sap server (owner of message)
- * @return message with specified sapID and specified sapInstaceDef
+ * get Message with specified sapId and sapInstanceDef
+ *
+ * @param sapID -
+ * id given to message by sap server
+ * @param sapInstanceDef -
+ * sap server (owner of message)
+ * @return message with specified sapID and specified sapInstaceDef or null
+ * if there is not appropriate Message in database
*/
- @SuppressWarnings("unchecked")
- public Message getMessageBySapIdAndSAPInstanceDef(String sapID, SAPInstanceDef sapInstanceDef) {
- final List<Message> messages = getHibernateTemplate().find(
- "from Message m where m.sapID = ? and m.sapInstanceDefOwner = ?",
- new Object[] { sapID, sapInstanceDef });
- if (messages.size() == 1) {
- return messages.get(0);
- }
- if (messages.size() > 1) {
- // REVIEW: strange situation, we have more than one message with identical sapID
- // associated with thesame SAP server instance.
- logger.warn("More than one message with identical sapID (" + sapID
- + ") associated with thesame SAP server instance: " + sapInstanceDef);
- return messages.get(0);
- } else {
- return null;
- }
- }
+ @SuppressWarnings("unchecked")
+ public Message getMessageBySapIdAndSAPInstanceDef(String sapID,
+ SAPInstanceDef sapInstanceDef) {
+ final List<Message> messages = getHibernateTemplate()
+ .find(
+ "from Message m where m.sapID = ? and m.sapInstanceDefOwner = ?",
+ new Object[] { sapID, sapInstanceDef });
+ if (messages.size() == 1) {
+ return messages.get(0);
+ }
+ if (messages.size() > 1) {
+ // REVIEW: strange situation, we have more than one message with
+ // identical sapID
+ // associated with thesame SAP server instance.
+ logger.warn("More than one message with identical sapID (" + sapID
+ + ") associated with thesame SAP server instance: "
+ + sapInstanceDef);
+ return messages.get(0);
+ } else {
+ return null;
+ }
+ }
/**
- * @param id - id of SentContent
+ * get Message - owner of specified SentContent
+ *
+ * @param id -
+ * id of SentContent
* @return message - owner of specified sentContent
*/
@SuppressWarnings("unchecked")
public Message getMessageBySentContentId(Long scId) {
- return (Message)getHibernateTemplate().find("select m from SentContent s join s.message m where s.id = ?", scId).get(0);
+ return (Message) getHibernateTemplate().find(
+ "select m from SentContent s join s.message m where s.id = ?",
+ scId).get(0);
}
-
+
@SuppressWarnings("unchecked")
public List<Message> getSelectedMessges(SearchMessageModel message) {
- logger.debug("MESSAGE: "+ message);
- String query = "select m from Message m" +
- " where m.description like '%" +message.getDescription()+ "%'"+
- (message.getReceiver().trim().length() != 0 ? " and m.receiver like '%" +message.getReceiver()+ "%'" : "")+
- (message.getSapID().trim().length() != 0 ? " and m.sapId like '%" +message.getSapID()+ "%'" : "")+
- (message.getSender().trim().length() != 0 ? " and m.sender like '%" +message.getSender()+ "%'" : "")+
- // this.createDateConstraints(message)+
- this.createComboConstraints(message);
- logger.debug("QUERY: "+ query);
+ logger.debug("MESSAGE: " + message);
+ String query = "select m from Message m"
+ + " where m.description like '%"
+ + message.getDescription()
+ + "%'"
+ + (message.getReceiver().trim().length() != 0 ? " and m.receiver like '%"
+ + message.getReceiver() + "%'"
+ : "")
+ + (message.getSapID().trim().length() != 0 ? " and m.sapId like '%"
+ + message.getSapID() + "%'"
+ : "")
+ + (message.getSender().trim().length() != 0 ? " and m.sender like '%"
+ + message.getSender() + "%'"
+ : "") +
+ // this.createDateConstraints(message)+
+ this.createComboConstraints(message);
+ logger.debug("QUERY: " + query);
final List list = getHibernateTemplate().find(query);
return list;
}
-
+
private String createComboConstraints(SearchMessageModel message) {
StringBuffer str = new StringBuffer();
if (null != message.getDirection()) {
- str.append(" and m.direction = "+ message.getDirection().ordinal());
+ str
+ .append(" and m.direction = "
+ + message.getDirection().ordinal());
}
if (null != message.getFormatType()) {
- str.append(" and m.formatType = "+ message.getFormatType().ordinal());
+ str.append(" and m.formatType = "
+ + message.getFormatType().ordinal());
}
if (null != message.getPriority()) {
- str.append(" and m.priority = "+ message.getPriority().ordinal());
+ str.append(" and m.priority = " + message.getPriority().ordinal());
}
if (null != message.getStatus()) {
- str.append(" and m.status = "+ message.getStatus().ordinal());
+ str.append(" and m.status = " + message.getStatus().ordinal());
}
-
+
return str.toString();
}
-
-/* private String createDateConstraints(SearchMessageModel message) {
-
- StringBuffer str = new StringBuffer();
- if (null != message.getSendDateFrom()){
- // logger.debug("DATE FROM: "+ new Timestamp(message.getSendDateFrom().getTime()));
- str.append(" and m.sendDate >= "+ message.getSendDateFrom());
- }
- if (null != message.getSendDateTo()) {
- // logger.debug("DATE TO: "+ new Timestamp(message.getSendDateTo().getTime()));
- str.append(" and m.sendDate <= "+ message.getSendDateTo());
- }
- return str.toString();
- }*/
+ /*
+ * private String createDateConstraints(SearchMessageModel message) {
+ *
+ * StringBuffer str = new StringBuffer(); if (null !=
+ * message.getSendDateFrom()){ // logger.debug("DATE FROM: "+ new
+ * Timestamp(message.getSendDateFrom().getTime())); str.append(" and
+ * m.sendDate >= "+ message.getSendDateFrom()); } if (null !=
+ * message.getSendDateTo()) { // logger.debug("DATE TO: "+ new
+ * Timestamp(message.getSendDateTo().getTime())); str.append(" and
+ * m.sendDate <= "+ message.getSendDateTo()); } return str.toString(); }
+ */
+
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/RoleDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/RoleDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/RoleDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -1,23 +1,23 @@
- /* $Id$
- *
- * Communications Suite.
- * Copyright (C) 2006 Szymon Kuzniak, Rafal Malinowski, Marek Musielak, Pawel Walkiewicz,
- * Agnieszka Wisniewska, Marcin Zduniak, Liliana Ziolek.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
+/* $Id$
+ *
+ * Communications Suite.
+ * Copyright (C) 2006 Szymon Kuzniak, Rafal Malinowski, Marek Musielak, Pawel Walkiewicz,
+ * Agnieszka Wisniewska, Marcin Zduniak, Liliana Ziolek.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
package org.commsuite.dao.hibernate;
import java.util.List;
@@ -42,6 +42,8 @@
}
/**
+ * lists all Roles from database
+ *
* @return list of all roles
*/
@SuppressWarnings("unchecked")
@@ -53,7 +55,8 @@
/**
* Saves or updates role in database
*
- * @param role - role to save in db
+ * @param role -
+ * role to save in db
* @return saved role
*/
public Role saveRole(Role role) {
@@ -63,64 +66,87 @@
}
/**
- * @param id of role
- * @return role with specified id
+ * get Role with specified id
+ *
+ * @param id
+ * of role
+ * @return role with specified id or null if Role with given id does not
+ * exist
*/
public Role getRole(Long id) {
- final List list = getHibernateTemplate().find("from Role r where r.id = ?", id);
+ final List list = getHibernateTemplate().find(
+ "from Role r where r.id = ?", id);
return (Role) (list.size() > 0 ? list.get(0) : null);
}
/**
* Deletes role with specified id from database.
- * @param id of role
+ *
+ * @param id
+ * of role
*/
public void deleteRole(Long id) {
- final List list = getHibernateTemplate().find("from Role r where r.id = ?", id);
- if (list.size() > 0){
- Object role = (Role)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Role r where r.id = ?", id);
+ if (list.size() > 0) {
+ Object role = (Role) list.get(0);
getHibernateTemplate().delete(role);
}
}
/**
* deletes specified role
- * @param role to delete
+ *
+ * @param role
+ * to delete
*/
public void deleteRole(Role role) {
- final List list = getHibernateTemplate().find("from Role r where r.id = ?", role.getId());
- if (list.size() > 0){
- Object roleToDelete = (Role)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from Role r where r.id = ?", role.getId());
+ if (list.size() > 0) {
+ Object roleToDelete = (Role) list.get(0);
getHibernateTemplate().delete(roleToDelete);
}
}
/**
- * @param name - name of roles
+ * lists all Roles with given name
+ *
+ * @param name -
+ * name of roles
* @return list of roles with specified name
*/
@SuppressWarnings("unchecked")
public List<Role> getRoles(String name) {
- final List list = getHibernateTemplate().find("select r from Role r where r.name like '%"+ name+ "%'");
+ final List list = getHibernateTemplate().find(
+ "select r from Role r where r.name like '%" + name + "%'");
return list;
}
-
+
/**
- * @param id - id of group
+ * lists all Roles directly attached to group with given id
+ *
+ * @param id -
+ * id of group
* @return list of roles directly attached to group with given id
*/
@SuppressWarnings("unchecked")
public List<Role> getRolesDirectlyAttachedToGroup(Long groupId) {
- return (List<Role>)getHibernateTemplate().find("select r from Group g join g.roles r where g.id = ?", groupId);
+ return (List<Role>) getHibernateTemplate().find(
+ "select r from Group g join g.roles r where g.id = ?", groupId);
}
-
+
/**
- * @param id - id of group
- * @return list of roles directly attached to group with given id
+ * lists all Roles directly attached to user with given id
+ *
+ * @param id -
+ * id of user
+ * @return list of roles directly attached to user with given id
*/
@SuppressWarnings("unchecked")
public List<Role> getRolesDirectlyAttachedToUser(Long userId) {
- return (List<Role>)getHibernateTemplate().find("select r from User u join u.roles r where u.id = ?", userId);
+ return (List<Role>) getHibernateTemplate().find(
+ "select r from User u join u.roles r where u.id = ?", userId);
}
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SAPInstanceDefDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SAPInstanceDefDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SAPInstanceDefDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -28,7 +28,8 @@
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
- * Class to communicate with database - gets and saves sap instances. Uses hibernate
+ * Class to communicate with database - gets and saves sap instances. Uses
+ * hibernate
*
* @since 1.0
* @author Marek Musielak
@@ -36,26 +37,31 @@
*/
public class SAPInstanceDefDaoImpl extends HibernateDaoSupport implements
SAPInstanceDefDao {
-
- private static final Logger logger = Logger.getLogger(SAPInstanceDefDaoImpl.class);
+ private static final Logger logger = Logger
+ .getLogger(SAPInstanceDefDaoImpl.class);
+
public SAPInstanceDefDaoImpl() {
super();
}
/**
+ * lists all sap instances
+ *
* @return list of all sap instances
*/
@SuppressWarnings("unchecked")
public List<SAPInstanceDef> getSAPInstances() {
- final List<SAPInstanceDef> sapInstancesList = getHibernateTemplate().loadAll(SAPInstanceDef.class);
+ final List<SAPInstanceDef> sapInstancesList = getHibernateTemplate()
+ .loadAll(SAPInstanceDef.class);
return sapInstancesList;
}
/**
* Saves or updates sap instance in database
*
- * @param sapInstanceDef - sap instance to save in db
+ * @param sapInstanceDef -
+ * sap instance to save in db
* @return saved sap instance
*/
public void saveSAPInstanceDef(SAPInstanceDef sapInstanceDef) {
@@ -63,84 +69,133 @@
}
/**
- * @param id of sap instance
- * @return sap instance with specified id
+ * get SapInstanceDef with given id
+ *
+ * @param id
+ * of sap instance
+ * @return sap instance with specified id or null if SapInstanceDef with
+ * given id does not exist
*/
public SAPInstanceDef getSAPInstanceDef(Long id) {
- final List list = getHibernateTemplate().find("from SAPInstanceDef s where s.id = ?", id);
+ final List list = getHibernateTemplate().find(
+ "from SAPInstanceDef s where s.id = ?", id);
return (SAPInstanceDef) (list.size() > 0 ? list.get(0) : null);
}
/**
* Deletes sap instance with specified id from database.
- * @param id of sap instance
+ *
+ * @param id
+ * of sap instance
*/
public void deleteSAPInstanceDef(Long id) {
- final List list = getHibernateTemplate().find("from SAPInstanceDef s where s.id = ?", id);
- if (list.size() > 0){
- Object sapInstanceDef = (SAPInstanceDef)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from SAPInstanceDef s where s.id = ?", id);
+ if (list.size() > 0) {
+ Object sapInstanceDef = (SAPInstanceDef) list.get(0);
getHibernateTemplate().delete(sapInstanceDef);
}
}
/**
* deletes specified sap instance
- * @param sap instance to delete
+ *
+ * @param sap
+ * instance to delete
*/
public void deleteSAPInstanceDef(SAPInstanceDef sapInstanceDef) {
- final List list = getHibernateTemplate().find("from SAPInstanceDef s where s.id = ?", sapInstanceDef.getId());
- if (list.size() > 0){
- Object sapToDelete = (SAPInstanceDef)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from SAPInstanceDef s where s.id = ?", sapInstanceDef.getId());
+ if (list.size() > 0) {
+ Object sapToDelete = (SAPInstanceDef) list.get(0);
getHibernateTemplate().delete(sapToDelete);
}
}
-
+
/**
- * @param messageId - id of message
+ * get SapInstanceDef - owner of Message with specified id
+ *
+ * @param messageId -
+ * id of message
* @return sapInstanceDef (owner of specified message)
*/
public SAPInstanceDef getSAPInstanceDefByMessageId(Long messageId) {
- final List sapList = getHibernateTemplate().find("select s from Message m join m.SAPInstanceDefOwner s where m.id = ?", messageId);
-
+ final List sapList = getHibernateTemplate()
+ .find(
+ "select s from Message m join m.SAPInstanceDefOwner s where m.id = ?",
+ messageId);
+
if (sapList.size() == 0)
return null;
else
- return (SAPInstanceDef)sapList.get(0);
+ return (SAPInstanceDef) sapList.get(0);
}
-
+
/**
- * @param instance - instance with some fields filled
+ * @param instance -
+ * instance with some fields filled
* @return list of sap instances with fields matching to given instance
*/
@SuppressWarnings("unchecked")
public List<SAPInstanceDef> getMatchingServers(SAPInstanceDef instance,
boolean defaultSearch, boolean loadSearch, boolean unicodeSearch) {
- logger.debug("INSTANCE: "+ instance);
- String query = "select s from SAPInstanceDef s where" +
- " s.name like '%" +instance.getName()+ "%'"+
- (defaultSearch ? " and s.defaultInstance = "+ instance.isDefaultInstance() : "")+
- (0 != instance.getMaxConnectionsInPool() ? " and s.maxConnectionsInPool = "+ instance.getMaxConnectionsInPool() : "")+
- (instance.getUser().trim().length() != 0 ? " and s.user like '%" +instance.getUser()+ "%'" : "")+
- (instance.getPassword().trim().length() != 0 ? " and s.password like '%" +instance.getPassword()+ "%'" : "")+
- (instance.getClient().trim().length() != 0 ? " and s.client like '%" +instance.getClient()+ "%'" : "")+
- (instance.getHost().trim().length() != 0 ? " and s.host like '%" +instance.getHost()+ "%'" : "")+
- (instance.getR3name().trim().length() != 0 ? " and s.r3name like '%" +instance.getR3name()+ "%'" : "")+
- (instance.getGroup().trim().length() != 0 ? " and s.group like '%" +instance.getGroup()+ "%'" : "")+
- (instance.getSystemNumber().trim().length() != 0 ? " and s.systemNumber like '%" +instance.getSystemNumber()+ "%'" : "")+
- (loadSearch ? " and s.loadBalancing = "+ instance.isLoadBalancing() : "")+
- (instance.getGwhost().trim().length() != 0 ? " and s.gwhost like '%" +instance.getGwhost()+ "%'" : "")+
- (instance.getGwserv().trim().length() != 0 ? " and s.gwserv like '%" +instance.getGwserv()+ "%'" : "")+
- (instance.getProgid().trim().length() != 0 ? " and s.progid like '%" +instance.getProgid()+ "%'" : "")+
- (unicodeSearch ? " and s.unicode = "+ instance.isUnicode() : "")+
- (instance.getAdminEmail().trim().length() != 0 ? " and s.name like '%" +instance.getAdminEmail()+ "%'" : "");
- logger.debug("QUERY: "+ query);
+ logger.debug("INSTANCE: " + instance);
+ String query = "select s from SAPInstanceDef s where"
+ + " s.name like '%"
+ + instance.getName()
+ + "%'"
+ + (defaultSearch ? " and s.defaultInstance = "
+ + instance.isDefaultInstance() : "")
+ + (0 != instance.getMaxConnectionsInPool() ? " and s.maxConnectionsInPool = "
+ + instance.getMaxConnectionsInPool()
+ : "")
+ + (instance.getUser().trim().length() != 0 ? " and s.user like '%"
+ + instance.getUser() + "%'"
+ : "")
+ + (instance.getPassword().trim().length() != 0 ? " and s.password like '%"
+ + instance.getPassword() + "%'"
+ : "")
+ + (instance.getClient().trim().length() != 0 ? " and s.client like '%"
+ + instance.getClient() + "%'"
+ : "")
+ + (instance.getHost().trim().length() != 0 ? " and s.host like '%"
+ + instance.getHost() + "%'"
+ : "")
+ + (instance.getR3name().trim().length() != 0 ? " and s.r3name like '%"
+ + instance.getR3name() + "%'"
+ : "")
+ + (instance.getGroup().trim().length() != 0 ? " and s.group like '%"
+ + instance.getGroup() + "%'"
+ : "")
+ + (instance.getSystemNumber().trim().length() != 0 ? " and s.systemNumber like '%"
+ + instance.getSystemNumber() + "%'"
+ : "")
+ + (loadSearch ? " and s.loadBalancing = "
+ + instance.isLoadBalancing() : "")
+ + (instance.getGwhost().trim().length() != 0 ? " and s.gwhost like '%"
+ + instance.getGwhost() + "%'"
+ : "")
+ + (instance.getGwserv().trim().length() != 0 ? " and s.gwserv like '%"
+ + instance.getGwserv() + "%'"
+ : "")
+ + (instance.getProgid().trim().length() != 0 ? " and s.progid like '%"
+ + instance.getProgid() + "%'"
+ : "")
+ + (unicodeSearch ? " and s.unicode = " + instance.isUnicode()
+ : "")
+ + (instance.getAdminEmail().trim().length() != 0 ? " and s.name like '%"
+ + instance.getAdminEmail() + "%'"
+ : "");
+ logger.debug("QUERY: " + query);
final List list = getHibernateTemplate().find(query);
- logger.debug("SIZE OF INSTANCES MATCHING TO GIVES PATTERN: " + list.size());
+ logger.debug("SIZE OF INSTANCES MATCHING TO GIVES PATTERN: "
+ + list.size());
return list;
}
-
+
public void deactivateInstance(String id, boolean mode) {
- SAPInstanceDef instance = getSAPInstanceDef(Long.getLong(id).longValue());
+ SAPInstanceDef instance = getSAPInstanceDef(Long.getLong(id)
+ .longValue());
instance.setActiveInstance(mode);
getHibernateTemplate().saveOrUpdate(id, instance);
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SentContentDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SentContentDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/SentContentDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -27,31 +27,37 @@
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
- * Class to communicate with database - gets and saves sent contents. Uses hibernate
+ * Class to communicate with database - gets and saves sent contents. Uses
+ * hibernate
*
* @since 1.0
* @author Marek Musielak
* @author Rafał Malinowski
*/
-public class SentContentDaoImpl extends HibernateDaoSupport implements SentContentDao {
+public class SentContentDaoImpl extends HibernateDaoSupport implements
+ SentContentDao {
public SentContentDaoImpl() {
super();
}
/**
+ * lists all SentContents
+ *
* @return list of all sent contents
*/
@SuppressWarnings("unchecked")
public List<SentContent> getSentContentsList() {
- final List<SentContent> sentContentsList = getHibernateTemplate().loadAll(SentContent.class);
+ final List<SentContent> sentContentsList = getHibernateTemplate()
+ .loadAll(SentContent.class);
return sentContentsList;
}
/**
* Saves or updates sentContent in database
*
- * @param sentContent - SentContent to save in db
+ * @param sentContent -
+ * SentContent to save in db
* @return saved sentContent
*/
public SentContent saveSentContent(SentContent sentContent) {
@@ -62,35 +68,47 @@
}
/**
- * @param internalId - internalId of sentContent
- * @return SentContent with specified id
+ * get SentContent with specified id
+ *
+ * @param internalId -
+ * internalId of sentContent
+ * @return SentContent with specified id or null if SentContent with given
+ * id does not exist
*/
public SentContent getSentContentByInternalId(String internalId) {
- final List list = getHibernateTemplate().find("from SentContent sc where sc.internalId = ?", internalId);
+ final List list = getHibernateTemplate().find(
+ "from SentContent sc where sc.internalId = ?", internalId);
return (SentContent) (list.size() > 0 ? list.get(0) : null);
}
/**
* deletes specified sentContent
- * @param sentContent to delete
+ *
+ * @param sentContent
+ * to delete
*/
public void deleteSentContent(SentContent sentContent) {
- final List list = getHibernateTemplate().find("from SentContent c where c.id = ?", sentContent.getId());
- if (list.size() > 0){
- Object sentContentToDelete = (SentContent)list.get(0);
+ final List list = getHibernateTemplate().find(
+ "from SentContent c where c.id = ?", sentContent.getId());
+ if (list.size() > 0) {
+ Object sentContentToDelete = (SentContent) list.get(0);
getHibernateTemplate().delete(sentContentToDelete);
}
}
-
+
/**
- * @param id - id of Message
+ * lists all SentContent for message with given id
+ *
+ * @param id -
+ * id of Message
* @return list of SentContent for Message with given id
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public List<SentContent> getSentContentsByMessage(String id) {
- String query = "select s from SentContent s where s.message.id = ? order by s.id";
- List<SentContent> result = getHibernateTemplate().find(query, Long.valueOf(id));
- return result;
- }
-
+ String query = "select s from SentContent s where s.message.id = ? order by s.id";
+ List<SentContent> result = getHibernateTemplate().find(query,
+ Long.valueOf(id));
+ return result;
+ }
+
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/UserDaoImpl.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/UserDaoImpl.java 2006-09-03 09:38:37 UTC (rev 124)
+++ trunk/code/CSMiddleware/src/org/commsuite/dao/hibernate/UserDaoImpl.java 2006-09-03 09:38:59 UTC (rev 125)
@@ -43,278 +43,346 @@
*/
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
- public UserDaoImpl() {
- super();
- }
+ public UserDaoImpl() {
+ super();
+ }
/**
+ * lists all Users
+ *
* @return list of all users
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public List<User> getUsers() {
- final List<User> usersList = getHibernateTemplate().loadAll(User.class);
- return usersList;
- }
+ final List<User> usersList = getHibernateTemplate().loadAll(User.class);
+ return usersList;
+ }
/**
* Saves or updates user in database
*
- * @param user - user to save in db
+ * @param user -
+ * user to save in db
* @return saved user
*/
- public User saveUser(User user) {
- getHibernateTemplate().saveOrUpdate(user);
- return user;
- }
+ public User saveUser(User user) {
+ getHibernateTemplate().saveOrUpdate(user);
+ return user;
+ }
/**
- * @param id of user
- * @return user with specified id
+ * get User with specified id
+ *
+ * @param id
+ * of user
+ * @return user with specified id or null if User with given id does not
+ * exist
*/
- public User getUser(Long id) {
- final List list = getHibernateTemplate().find("from User u where u.id = ?", id);
- return (User) (list.size() > 0 ? list.get(0) : null);
- }
+ public User getUser(Long id) {
+ final List list = getHibernateTemplate().find(
+ "from User u where u.id = ?", id);
+ return (User) (list.size() > 0 ? list.get(0) : null);
+ }
/**
* Deletes user with specified id from database.
- * @param id of user
+ *
+ * @param id
+ * of user
*/
- public void deleteUser(Long id) {
- final List list = getHibernateTemplate().find("from User u where u.id = ?", id);
- if (list.size() > 0) {
- User user = (User) list.get(0);
- getHibernateTemplate().delete(user);
- }
- }
+ public void deleteUser(Long id) {
+ final List list = getHibernateTemplate().find(
+ "from User u where u.id = ?", id);
+ if (list.size() > 0) {
+ User user = (User) list.get(0);
+ getHibernateTemplate().delete(user);
+ }
+ }
/**
* deletes specified user
- * @param user to delete
+ *
+ * @param user
+ * to delete
*/
- public void deleteUser(User user) {
- final List list = getHibernateTemplate().find("from User u where u.id = ?", user.getId());
- if (list.size() > 0) {
- User userToDelete = (User) list.get(0);
- getHibernateTemplate().delete(userToDelete);
- }
- }
+ public void deleteUser(User user) {
+ final List list = getHibernateTemplate().find(
+ "from User u where u.id = ?", user.getId());
+ if (list.size() > 0) {
+ User userToDelete = (User) list.get(0);
+ getHibernateTemplate().delete(userToDelete);
+ }
+ }
- /**
- * Check if user has assigned role
- * @param role - role to check
- * @param user - user to check
- *
- * @return if user has specified role
- */
- public boolean hasRole(User user, Role role) {
- for (Role roleToCheck : user.getRoles()) {
+ /**
+ * Check if user has assigned role
+ *
+ * @param role -
+ * role to check
+ * @param user -
+ * user to check
+ *
+ * @return if user has specified role
+ */
+ public boolean hasRole(User user, Role role) {
+ for (Role roleToCheck : user.getRoles()) {
if (role.equals(roleToCheck)) {
return true;
}
}
- List<Group> checkedGroups = new ArrayList<Group>();
- List<Group> groupsToCheck = new ArrayList<Group>();
-
- groupsToCheck = addUserGroupsToList(user, groupsToCheck);
+ List<Group> checkedGroups = new ArrayList<Group>();
+ List<Group> groupsToCheck = new ArrayList<Group>();
- while (groupsToCheck.size() != 0) {
- Group group = groupsToCheck.get(0);
- groupsToCheck.remove(0);
- checkedGroups.add(group);
+ groupsToCheck = addUserGroupsToList(user, groupsToCheck);
- for (Role roleToCheck : group.getRoles()) {
- if (role.equals(roleToCheck)) {
- return true;
- }
- }
+ while (groupsToCheck.size() != 0) {
+ Group group = groupsToCheck.get(0);
+ groupsToCheck.remove(0);
+ checkedGroups.add(group);
- groupsToCheck = addSubGroupsToList(group, groupsToCheck, checkedGroups);
- }
+ for (Role roleToCheck : group.getRoles()) {
+ if (role.equals(roleToCheck)) {
+ return true;
+ }
+ }
- return false;
- }
-
- private List<Group> addUserGroupsToList(User user, List<Group> groupsList) {
- for (Group group : user.getGroups()) {
- if (-1 == groupsList.indexOf(group)) {
- groupsList.add(group);
- }
- }
- return groupsList;
- }
-
- private List<Group> addSubGroupsToList(Group supGroup, List<Group> groupsList, List<Group> alreadyCheckedGroups) {
- for (Group g : supGroup.getSupGroups()) {
- if (-1 == groupsList.indexOf(g) && -1 == alreadyCheckedGroups.indexOf(g))
- groupsList.add(g);
- }
- return groupsList;
- }
+ groupsToCheck = addSubGroupsToList(group, groupsToCheck,
+ checkedGroups);
+ }
- private List<Role> addRolesToListWithoutDuplicates(List<Role> roles, List<Role> rolesToAdd) {
- for (Role r : rolesToAdd) {
- if (-1 == roles.indexOf(r))
- roles.add(r);
- }
-
- return roles;
- }
-
- private List<Role> addRolesToListWithoutDuplicates(List<Role> roles, Set<Role> rolesToAdd) {
- for (Role r : rolesToAdd) {
- if (-1 == roles.indexOf(r))
- roles.add(r);
- }
-
- return roles;
- }
-
- private List<Group> addGroupsToListWithoutDuplicates(List<Group> groups, List<Group> groupsToAdd) {
- for (Group g : groupsToAdd) {
- if (-1 == groups.indexOf(g))
- groups.add(g);
- }
-
- return groups;
- }
-
- /**
- * Return all actions for user
- * @param user - for this user we search actions
- *
- * @return list of actions for specifies user
- */
- @SuppressWarnings("unchecked")
+ return false;
+ }
+
+ private List<Group> addUserGroupsToList(User user, List<Group> groupsList) {
+ for (Group group : user.getGroups()) {
+ if (-1 == groupsList.indexOf(group)) {
+ groupsList.add(group);
+ }
+ }
+ return groupsList;
+ }
+
+ private List<Group> addSubGroupsToList(Group supGroup,
+ List<Group> groupsList, List<Group> alreadyCheckedGroups) {
+ for (Group g : supGroup.getSupGroups()) {
+ if (-1 == groupsList.indexOf(g)
+ && -1 == alreadyCheckedGroups.indexOf(g))
+ groupsList.add(g);
+ }
+ return groupsList;
+ }
+
+ private List<Role> addRolesToListWithoutDuplicates(List<Role> roles,
+ List<Role> rolesToAdd) {
+ for (Role r : rolesToAdd) {
+ if (-1 == roles.indexOf(r))
+ roles.add(r);
+ }
+
+ return roles;
+ }
+
+ private List<Role> addRolesToListWithoutDuplicates(List<Role> roles,
+ Set<Role> rolesToAdd) {
+ for (Role r : rolesToAdd) {
+ if (-1 == roles.indexOf(r))
+ roles.add(r);
+ }
+
+ return roles;
+ }
+
+ private List<Group> addGroupsToListWithoutDuplicates(List<Group> groups,
+ List<Group> groupsToAdd) {
+ for (Group g : groupsToAdd) {
+ if (-1 == groups.indexOf(g))
+ groups.add(g);
+ }
+
+ return groups;
+ }
+
+ /**
+ * Return all actions for user
+ *
+ * @param user -
+ * for this user we search actions
+ *
+ * @return list of actions for specifies user
+ */
+ @SuppressWarnings("unchecked")
public Set<Action> getActions(User user) {
- List<Role> userRoles = getHibernateTemplate().find("select u.roles from User u where u.id = ?", Long.valueOf(user.getId()));
- List<Group> userGroups = getHibernateTemplate().find("select u.groups from User u where u.id = ?", Long.valueOf(user.getId()));
-
- List<Role> roles = new ArrayList<Role>();
+ List<Role> userRoles = getHibernateTemplate().find(
+ "select u.roles from User u where u.id = ?",
+ Long.valueOf(user.getId()));
+ List<Group> userGroups = getHibernateTemplate().find(
+ "select u.groups from User u where u.id = ?",
+ Long.valueOf(user.getId()));
- roles = addRolesToListWithoutDuplicates(roles, userRoles);
+ List<Role> roles = new ArrayList<Role>();
- List<Group> checkedGroups = new ArrayList<Group>();
- List<Group> groupsToCheck = new ArrayList<Group>();
+ roles = addRolesToListWithoutDuplicates(roles, userRoles);
- groupsToCheck = addGroupsToListWithoutDuplicates(groupsToCheck, userGroups);
+ List<Group> checkedGroups = new ArrayList<Group>();
+ List<Group> groupsToCheck = new ArrayList<Group>();
- while (groupsToCheck.size() != 0) {
- Group group = groupsToCheck.get(0);
- groupsToCheck.remove(0);
- checkedGroups.add(group);
+ groupsToCheck = addGroupsToListWithoutDuplicates(groupsToCheck,
+ userGroups);
- roles = addRolesToListWithoutDuplicates(roles, group.getRoles());
+ while (groupsToCheck.size() != 0) {
+ Group group = groupsToCheck.get(0);
+ groupsToCheck.remove(0);
+ checkedGroups.add(group);
- groupsToCheck = addSubGroupsToList(group, groupsToCheck, checkedGroups);
- }
-
- return getActionsFromRoles(roles);
+ roles = addRolesToListWithoutDuplicates(roles, group.getRoles());
- }
-
- private Set<Action> getActionsFromRoles(List<Role> roles) {
- Set<Action> actions = new HashSet<Action>();
- for (Role r : roles) {
- for (Action a : (Set<Action>) r.getActions()) {
- if (!actions.contains(a))
- actions.add(a);
- }
- }
+ groupsToCheck = addSubGroupsToList(group, groupsToCheck,
+ checkedGroups);
+ }
- return actions;
+ return getActionsFromRoles(roles);
- }
+ }
- /**
- * @param login - login of user
- * @param password - password of user
- *
- * @return user with specified login and password
- */
- public User getUserByLoginAndPassword(String login, String password) {
- final List list = getHibernateTemplate().find(
- "from User u where u.login = ? and u.password = ?",
- new Object[] { login, password });
- if (list.size() > 0) {
- final User user = (User) list.get(0);
- return user;
- } else {
- return null;
- }
- }
-
- /**
- * @param name - name of user
- *
- * @return user with specified name
- */
- public User getUserByName(String name) {
- final List list = getHibernateTemplate().find(
- "from User u where u.login = ?", name);
- if (list.size() > 0) {
- final User user = (User) list.get(0);
- return user;
- } else {
- return null;
- }
- }
+ private Set<Action> getActionsFromRoles(List<Role> roles) {
+ Set<Action> actions = new HashSet<Action>();
+ for (Role r : roles) {
+ for (Action a : (Set<Action>) r.getActions()) {
+ if (!actions.contains(a))
+ actions.add(a);
+ }
+ }
+ return actions;
+
+ }
+
/**
- * @param user - user with some fields filled
+ * @param login -
+ * login of user
+ * @param password -
+ * password of user
+ *
+ * @return user with specified login and password
+ */
+ public User getUserByLoginAndPassword(String login, String password) {
+ final List list = getHibernateTemplate().find(
+ "from User u where u.login = ? and u.password = ?",
+ new Object[] { login, password });
+ if (list.size() > 0) {
+ final User user = (User) list.get(0);
+ return user;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @param name -
+ * name of user
+ *
+ * @return user with specified name
+ */
+ public User getUserByName(String name) {
+ final List list = getHibernateTemplate().find(
+ "from User u where u.login = ?", name);
+ if (list.size() > 0) {
+ final User user = (User) list.get(0);
+ return user;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @param user -
+ * user with some fields filled
* @return list of users with fields matching to given user
*/
@SuppressWarnings("unchecked")
public List<User> getMatchingUsers(User user, boolean enabledSearch) {
- // REVIEW: [SK] a co w przypadku gdy jakichs z ponizszych atrybutow bedzie nullem ?
- // REVIEW: [MZ] jesli atrybut == null wowczas zapytanie bedzie << like '%%' >> zatem zwroci wszystkie
+ // REVIEW: [SK] a co w przypadku gdy jakichs z ponizszych atrybutow
+ // bedzie nullem ?
+ // REVIEW: [MZ] jesli atrybut == null wowczas zapytanie bedzie << like
+ // '%%' >> zatem zwroci wszystkie
// komentarze do usuniecia
- String query = "select u from User u" +
- " where u.login like '%"+ user.getLogin() +"%'"+
- (user.getFirstName().trim().length() != 0 ? " and u.firstName like '%" +user.getFirstName()+ "%'" : "")+
- (user.getLastName().trim().length() != 0 ? " and u.lastName like '%"+ user.getLastName()+ "%'" : "")+
- (user.getEmail().trim().length() != 0 ? " and u.email like '%"+ user.getEmail()+ "%'" : "")+
- (user.getTelephone().trim().length() != 0 ? " and u.telephone like '%"+ user.getTelephone()+ "%'" : "")+
- (user.getFax().trim().length() != 0 ? " and u.fax like '%"+ user.getFax()+ "%'" : "")+
- (user.getMobile().trim().length() != 0 ? " and u.mobile like '%"+ user.getMobile()+ "%'" : "")+
- (user.getStreet().trim().length() != 0 ? " and u.street like '%"+ user.getStreet()+ "%'" : "")+
- (user.getCity().trim().length() != 0 ? " and u.city like '%"+ user.getCity()+ "%'" : "")+
- (user.getState().trim().length() != 0 ? " and u.state like '%"+ user.getState()+ "%'" : "")+
- (user.getPostalCode().trim().length() != 0 ? " and u.postalCode like '%"+ user.getPostalCode()+ "%'" : "")+
- (user.getCountry() != null ? " and u.country = "+ user.getCountry().ordinal() : "")+
- (user.getLanguage() != null ? " and u.language = "+ user.getLanguage().ordinal() : "")+
- (user.getTimeZone() != null ? " and u.timeZone = "+ user.getTimeZo...
[truncated message content] |