dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11414
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3239: Made User - OrganisationUnit association bi-directional.
------------------------------------------------------------
revno: 3239
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-31 18:28:24 +0200
message:
Made User - OrganisationUnit association bi-directional.
added:
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessagesAction.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java 2011-03-31 15:54:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java 2011-03-31 16:28:24 +0000
@@ -62,7 +62,7 @@
this.text = text;
this.sender = sender;
}
-
+
public int getId()
{
return id;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2011-03-29 20:21:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2011-03-31 16:28:24 +0000
@@ -37,6 +37,7 @@
import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.source.Source;
+import org.hisp.dhis.user.User;
/**
* @author Kristian Nordal
@@ -79,6 +80,8 @@
private Set<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
+ private Set<User> users = new HashSet<User>();
+
private String contactPerson;
private String address;
@@ -512,6 +515,16 @@
this.groups = groups;
}
+ public Set<User> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( Set<User> users )
+ {
+ this.users = users;
+ }
+
public String getContactPerson()
{
return contactPerson;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2011-01-13 15:44:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2011-03-31 16:28:24 +0000
@@ -30,6 +30,7 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -62,7 +63,7 @@
*
* TODO This should have been put in UserCredentials
*/
- private Collection<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
+ private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
// -------------------------------------------------------------------------
// hashCode and equals
@@ -192,7 +193,7 @@
return organisationUnits;
}
- public void setOrganisationUnits( Collection<OrganisationUnit> organisationUnits )
+ public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
{
this.organisationUnits = organisationUnits;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2011-02-17 02:14:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2011-03-31 16:28:24 +0000
@@ -56,6 +56,11 @@
<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="orgunitgroupid"/>
</set>
+ <set name="users" table="usermembership" inverse="true">
+ <key column="organisationunitid"/>
+ <many-to-many class="org.hisp.dhis.user.User" column="userinfoid"/>
+ </set>
+
<!-- Contact info -->
<property name="contactPerson" length="255"/>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2010-05-04 11:36:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2011-03-31 16:28:24 +0000
@@ -25,6 +25,6 @@
<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnit"
column="organisationunitid" foreign-key="fk_userinfo_organisationunitid"/>
</set>
-
+
</class>
</hibernate-mapping>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java 2011-03-31 15:54:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java 2011-03-31 16:28:24 +0000
@@ -27,6 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
import java.util.List;
import org.hisp.dhis.DhisSpringTest;
@@ -34,8 +39,6 @@
import org.hisp.dhis.user.UserService;
import org.junit.Test;
-import static junit.framework.Assert.*;
-
/**
* @author Lars Helge Overland
*/
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java 2011-03-31 07:09:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java 2011-03-31 16:28:24 +0000
@@ -31,9 +31,9 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
-import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
+import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -69,7 +69,7 @@
OrganisationUnit unit2 = new OrganisationUnit( "name2", "shortName2", "organisationUnitCode2", new Date(),
new Date(), true, "comment" );
- Collection<OrganisationUnit> units1 = new HashSet<OrganisationUnit>();
+ Set<OrganisationUnit> units1 = new HashSet<OrganisationUnit>();
units1.add(unit1);
units1.add(unit2);
@@ -109,7 +109,7 @@
// Test getAllUsers
User user2 = new User();
- Collection<OrganisationUnit> units2 = new HashSet<OrganisationUnit>();
+ Set<OrganisationUnit> units2 = new HashSet<OrganisationUnit>();
units2.add(unit2);
user2.setSurname( "User2" );
@@ -130,7 +130,7 @@
OrganisationUnit unit3 = new OrganisationUnit( "name3", "shortName3", "organisationUnitCode3", new Date(),
new Date(), true, "comment" );
organisationUnitService.addOrganisationUnit( unit3 );
- Collection<OrganisationUnit> units3 = new HashSet<OrganisationUnit>();
+ Set<OrganisationUnit> units3 = new HashSet<OrganisationUnit>();
units3.add(unit3);
user.setOrganisationUnits( units3 );
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessagesAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessagesAction.java 2011-03-31 15:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessagesAction.java 2011-03-31 16:28:24 +0000
@@ -1,5 +1,32 @@
package org.hisp.dhis.dashboard.message.action;
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
import java.util.List;
import org.hisp.dhis.message.MessageService;
@@ -7,16 +34,27 @@
import com.opensymphony.xwork2.Action;
+/**
+ * @author Lars Helge Overland
+ */
public class GetMessagesAction
implements Action
{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
private MessageService messageService;
public void setMessageService( MessageService messageService )
{
this.messageService = messageService;
}
-
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
private List<UserMessage> messages;
public List<UserMessage> getMessages()
@@ -24,9 +62,11 @@
return messages;
}
- @Override
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
public String execute()
- throws Exception
{
messages = messageService.getUserMessages( 1, 1000 );
=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java 2011-03-31 16:28:24 +0000
@@ -0,0 +1,125 @@
+package org.hisp.dhis.dashboard.message.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.message.Message;
+import org.hisp.dhis.message.MessageService;
+import org.hisp.dhis.message.UserMessage;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class SendMessageAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private MessageService messageService;
+
+ public void setMessageService( MessageService messageService )
+ {
+ this.messageService = messageService;
+ }
+
+ private SelectionTreeManager selectionTreeManager;
+
+ public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+ {
+ this.selectionTreeManager = selectionTreeManager;
+ }
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private String subject;
+
+ public void setSubject( String subject )
+ {
+ this.subject = subject;
+ }
+
+ private String text;
+
+ public void setText( String text )
+ {
+ this.text = text;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ {
+ User sender = currentUserService.getCurrentUser();
+
+ Message message = new Message( subject, text, sender );
+
+ Set<UserMessage> userMessages = getUserMessages( message );
+
+ message.setUserMessages( userMessages );
+
+ messageService.saveMessage( message );
+
+ return SUCCESS;
+ }
+
+ private Set<UserMessage> getUserMessages( Message message )
+ {
+ Set<UserMessage> userMessages = new HashSet<UserMessage>();
+
+ for ( OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits() )
+ {
+ for ( User user : unit.getUsers() )
+ {
+ userMessages.add( new UserMessage( user, message ) );
+ }
+ }
+
+ return userMessages;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml 2011-03-31 15:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml 2011-03-31 16:28:24 +0000
@@ -79,4 +79,12 @@
<property name="messageService" ref="org.hisp.dhis.message.MessageService"/>
</bean>
+ <bean id="org.hisp.dhis.dashboard.message.action.SendMessageAction"
+ class="org.hisp.dhis.dashboard.message.action.SendMessageAction"
+ scope="prototype">
+ <property name="messageService" ref="org.hisp.dhis.message.MessageService"/>
+ <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
+ </bean>
+
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml 2011-03-31 15:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml 2011-03-31 16:28:24 +0000
@@ -63,5 +63,9 @@
<param name="menu">/dhis-web-commons/about/menu.vm</param>
</action>
+ <action name="sendMessage" class="org.hisp.dhis.dashboard.message.action.SendMessageAction">
+ <result name="success" type="redirect">message.action</result>
+ </action>
+
</package>
</struts>