=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message' === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/Message.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/Message.java 2014-08-15 07:40:20 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/Message.java 1970-01-01 00:00:00 +0000 @@ -1,153 +0,0 @@ -package org.hisp.dhis.dxf2.message; - -/* - * Copyright (c) 2004-2014, 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 com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import org.hisp.dhis.common.BaseIdentifiableObject; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.common.view.DetailedView; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.user.User; -import org.hisp.dhis.user.UserGroup; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author Morten Olav Hansen - */ -@JacksonXmlRootElement( localName = "message", namespace = DxfNamespaces.DXF_2_0 ) -public class Message -{ - private String subject; - - private String text; - - private Set organisationUnits = new HashSet<>(); - - private Set users = new HashSet<>(); - - private Set userGroups = new HashSet<>(); - - public Message() - { - } - - public Message( String subject, String text ) - { - this.subject = subject; - this.text = text; - } - - @JsonProperty - @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public String getSubject() - { - return subject; - } - - public void setSubject( String subject ) - { - this.subject = subject; - } - - @JsonProperty - @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public String getText() - { - return text; - } - - public void setText( String text ) - { - this.text = text; - } - - @JsonProperty - @JsonSerialize( contentAs = BaseIdentifiableObject.class ) - @JsonView( { DetailedView.class } ) - @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 ) - @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 ) - public Set getOrganisationUnits() - { - return organisationUnits; - } - - public void setOrganisationUnits( Set organisationUnits ) - { - this.organisationUnits = organisationUnits; - } - - @JsonProperty - @JsonSerialize( contentAs = BaseIdentifiableObject.class ) - @JsonView( { DetailedView.class } ) - @JacksonXmlElementWrapper( localName = "users", namespace = DxfNamespaces.DXF_2_0 ) - @JacksonXmlProperty( localName = "user", namespace = DxfNamespaces.DXF_2_0 ) - public Set getUsers() - { - return users; - } - - public void setUsers( Set users ) - { - this.users = users; - } - - @JsonProperty - @JsonSerialize( contentAs = BaseIdentifiableObject.class ) - @JsonView( { DetailedView.class } ) - @JacksonXmlElementWrapper( localName = "userGroups", namespace = DxfNamespaces.DXF_2_0 ) - @JacksonXmlProperty( localName = "userGroup", namespace = DxfNamespaces.DXF_2_0 ) - public Set getUserGroups() - { - return userGroups; - } - - public void setUserGroups( Set userGroups ) - { - this.userGroups = userGroups; - } - - @Override - public String toString() - { - return "Message{" + - "subject='" + subject + '\'' + - ", text='" + text + '\'' + - ", organisationUnits=" + organisationUnits + - ", users=" + users + - ", userGroups=" + userGroups + - '}'; - } -} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MessageConversationController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MessageConversationController.java 2014-10-01 09:58:24 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MessageConversationController.java 2014-10-14 03:55:34 +0000 @@ -31,11 +31,10 @@ import com.google.common.collect.Lists; import org.hisp.dhis.acl.AclService; import org.hisp.dhis.common.Pager; -import org.hisp.dhis.dxf2.message.Message; +import org.hisp.dhis.webapi.webdomain.MessageConversation; import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException; import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException; -import org.hisp.dhis.message.MessageConversation; import org.hisp.dhis.message.MessageService; import org.hisp.dhis.node.types.CollectionNode; import org.hisp.dhis.node.types.RootNode; @@ -77,7 +76,7 @@ @Controller @RequestMapping( value = MessageConversationSchemaDescriptor.API_ENDPOINT ) public class MessageConversationController - extends AbstractCrudController + extends AbstractCrudController { @Autowired private MessageService messageService; @@ -95,7 +94,7 @@ private CurrentUserService currentUserService; @Override - public void postProcessEntity( MessageConversation entity, WebOptions options, Map parameters ) throws Exception + public void postProcessEntity( org.hisp.dhis.message.MessageConversation entity, WebOptions options, Map parameters ) throws Exception { Boolean markRead = Boolean.parseBoolean( parameters.get( "markRead" ) ); @@ -110,9 +109,9 @@ public RootNode getObject( @PathVariable String uid, Map parameters, HttpServletRequest request, HttpServletResponse response ) throws Exception { - MessageConversation messageConversation = messageService.getMessageConversation( uid ); + org.hisp.dhis.message.MessageConversation messageConversationConversation = messageService.getMessageConversation( uid ); - if( messageConversation == null ) + if( messageConversationConversation == null ) { response.setStatus( HttpServletResponse.SC_NOT_FOUND ); RootNode responseNode = new RootNode( "reply" ); @@ -120,7 +119,7 @@ return responseNode; } - if( !canReadMessageConversation( currentUserService.getCurrentUser(), messageConversation ) ) + if( !canReadMessageConversation( currentUserService.getCurrentUser(), messageConversationConversation ) ) { throw new AccessDeniedException( "Not authorized to access this conversation." ); } @@ -129,9 +128,9 @@ } @Override - protected List getEntityList( WebMetaData metaData, WebOptions options, List filters ) + protected List getEntityList( WebMetaData metaData, WebOptions options, List filters ) { - List entityList; + List entityList; if ( options.getOptions().containsKey( "query" ) ) { @@ -161,23 +160,23 @@ @Override public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { - Message message = JacksonUtils.fromXml( input, Message.class ); - postObject( response, request, message ); + MessageConversation messageConversation = JacksonUtils.fromXml( input, MessageConversation.class ); + postObject( response, request, messageConversation ); } @Override public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { - Message message = JacksonUtils.fromJson( input, Message.class ); - postObject( response, request, message ); + MessageConversation messageConversation = JacksonUtils.fromJson( input, MessageConversation.class ); + postObject( response, request, messageConversation ); } - public void postObject( HttpServletResponse response, HttpServletRequest request, Message message ) + public void postObject( HttpServletResponse response, HttpServletRequest request, MessageConversation messageConversation ) { - List users = new ArrayList<>( message.getUsers() ); - message.getUsers().clear(); + List users = new ArrayList<>( messageConversation.getUsers() ); + messageConversation.getUsers().clear(); - for ( OrganisationUnit ou : message.getOrganisationUnits() ) + for ( OrganisationUnit ou : messageConversation.getOrganisationUnits() ) { OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( ou.getUid() ); @@ -187,7 +186,7 @@ return; } - message.getUsers().addAll( organisationUnit.getUsers() ); + messageConversation.getUsers().addAll( organisationUnit.getUsers() ); } for ( User u : users ) @@ -200,10 +199,10 @@ return; } - message.getUsers().add( user ); + messageConversation.getUsers().add( user ); } - for ( UserGroup ug : message.getUserGroups() ) + for ( UserGroup ug : messageConversation.getUserGroups() ) { UserGroup userGroup = userGroupService.getUserGroup( ug.getUid() ); @@ -213,10 +212,10 @@ return; } - message.getUsers().addAll( userGroup.getMembers() ); + messageConversation.getUsers().addAll( userGroup.getMembers() ); } - if ( message.getUsers().isEmpty() ) + if ( messageConversation.getUsers().isEmpty() ) { ContextUtils.conflictResponse( response, "No recipients selected." ); return; @@ -224,9 +223,9 @@ String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT ); - int id = messageService.sendMessage( message.getSubject(), message.getText(), metaData, message.getUsers() ); + int id = messageService.sendMessage( messageConversation.getSubject(), messageConversation.getText(), metaData, messageConversation.getUsers() ); - MessageConversation conversation = messageService.getMessageConversation( id ); + org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation( id ); ContextUtils.createdResponse( response, "Message conversation created", MessageConversationSchemaDescriptor.API_ENDPOINT + "/" + conversation.getUid() ); } @@ -241,7 +240,7 @@ { String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT ); - MessageConversation conversation = messageService.getMessageConversation( uid ); + org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation( uid ); if ( conversation == null ) { @@ -295,9 +294,9 @@ throw new UpdateAccessDeniedException( "Not authorized to modify this object." ); } - Collection messageConversations = messageService.getMessageConversations( uids ); + Collection messageConversationConversations = messageService.getMessageConversations( uids ); - if ( messageConversations.isEmpty() ) + if ( messageConversationConversations.isEmpty() ) { response.setStatus( HttpServletResponse.SC_NOT_FOUND ); responseNode.addChild( new SimpleNode( "message", "No MessageConversations found for the given UIDs." ) ); @@ -307,7 +306,7 @@ CollectionNode marked = responseNode.addChild( new CollectionNode( "markedRead" ) ); marked.setWrapping( false ); - for( MessageConversation conversation : messageConversations ) + for( org.hisp.dhis.message.MessageConversation conversation : messageConversationConversations ) { if( conversation.markRead( user ) ) { @@ -346,9 +345,9 @@ throw new UpdateAccessDeniedException( "Not authorized to modify this object." ); } - Collection messageConversations = messageService.getMessageConversations( uids ); + Collection messageConversationConversations = messageService.getMessageConversations( uids ); - if ( messageConversations.isEmpty() ) + if ( messageConversationConversations.isEmpty() ) { response.setStatus( HttpServletResponse.SC_NOT_FOUND ); responseNode.addChild( new SimpleNode( "message", "No MessageConversations found for the given UIDs." ) ); @@ -358,7 +357,7 @@ CollectionNode marked = responseNode.addChild( new CollectionNode( "markedUnread" ) ); marked.setWrapping( false ); - for( MessageConversation conversation : messageConversations ) + for( org.hisp.dhis.message.MessageConversation conversation : messageConversationConversations ) { if( conversation.markUnread( user ) ) { @@ -418,9 +417,9 @@ throw new DeleteAccessDeniedException( "Not authorized to modify user: " + user.getUid() ); } - MessageConversation messageConversation = messageService.getMessageConversation( mcUid ); + org.hisp.dhis.message.MessageConversation messageConversationConversation = messageService.getMessageConversation( mcUid ); - if( messageConversation == null ) + if( messageConversationConversation == null ) { responseNode.addChild( new SimpleNode( "message", "No messageConversation with uid: " + mcUid ) ); response.setStatus( HttpServletResponse.SC_NOT_FOUND ); @@ -429,10 +428,10 @@ CollectionNode removed = responseNode.addChild( new CollectionNode( "removed" ) ); - if( messageConversation.remove( user ) ) + if( messageConversationConversation.remove( user ) ) { - messageService.updateMessageConversation( messageConversation ); - removed.addChild( new SimpleNode( "uid", messageConversation.getUid() ) ); + messageService.updateMessageConversation( messageConversationConversation ); + removed.addChild( new SimpleNode( "uid", messageConversationConversation.getUid() ) ); } response.setStatus( HttpServletResponse.SC_OK ); @@ -467,9 +466,9 @@ throw new DeleteAccessDeniedException( "Not authorized to modify user: " + user.getUid() ); } - Collection messageConversations = messageService.getMessageConversations( mcUids ); + Collection messageConversationConversations = messageService.getMessageConversations( mcUids ); - if( messageConversations.isEmpty() ) + if( messageConversationConversations.isEmpty() ) { response.setStatus( HttpServletResponse.SC_NOT_FOUND ); responseNode.addChild( new SimpleNode( "message", "No MessageConversations found for the given UIDs." ) ); @@ -478,7 +477,7 @@ CollectionNode removed = responseNode.addChild( new CollectionNode( "removed" ) ); - for( MessageConversation mc : messageConversations ) + for( org.hisp.dhis.message.MessageConversation mc : messageConversationConversations ) { if( mc.remove( user ) ) { @@ -517,11 +516,11 @@ * Determines whether the given user has permission to read the MessageConversation. * * @param user the user to check permission for. - * @param messageConversation the MessageConversation to access. + * @param messageConversationConversation the MessageConversation to access. * @return true if the user can read the MessageConversation, false otherwise. */ - private boolean canReadMessageConversation( User user, MessageConversation messageConversation ) + private boolean canReadMessageConversation( User user, org.hisp.dhis.message.MessageConversation messageConversationConversation ) { - return messageConversation.getUsers().contains( user ) || user.getUserCredentials().hasAnyAuthority( AclService.ACL_OVERRIDE_AUTHORITIES ); + return messageConversationConversation.getUsers().contains( user ) || user.getUserCredentials().hasAnyAuthority( AclService.ACL_OVERRIDE_AUTHORITIES ); } } === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/MessageConversation.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/MessageConversation.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/MessageConversation.java 2014-10-14 03:55:34 +0000 @@ -0,0 +1,153 @@ +package org.hisp.dhis.webapi.webdomain; + +/* + * Copyright (c) 2004-2014, 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 com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.common.view.DetailedView; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.user.User; +import org.hisp.dhis.user.UserGroup; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Morten Olav Hansen + */ +@JacksonXmlRootElement( localName = "message", namespace = DxfNamespaces.DXF_2_0 ) +public class MessageConversation +{ + private String subject; + + private String text; + + private Set organisationUnits = new HashSet<>(); + + private Set users = new HashSet<>(); + + private Set userGroups = new HashSet<>(); + + public MessageConversation() + { + } + + public MessageConversation( String subject, String text ) + { + this.subject = subject; + this.text = text; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getSubject() + { + return subject; + } + + public void setSubject( String subject ) + { + this.subject = subject; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getText() + { + return text; + } + + public void setText( String text ) + { + this.text = text; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 ) + public Set getOrganisationUnits() + { + return organisationUnits; + } + + public void setOrganisationUnits( Set organisationUnits ) + { + this.organisationUnits = organisationUnits; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "users", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "user", namespace = DxfNamespaces.DXF_2_0 ) + public Set getUsers() + { + return users; + } + + public void setUsers( Set users ) + { + this.users = users; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "userGroups", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "userGroup", namespace = DxfNamespaces.DXF_2_0 ) + public Set getUserGroups() + { + return userGroups; + } + + public void setUserGroups( Set userGroups ) + { + this.userGroups = userGroups; + } + + @Override + public String toString() + { + return "Message{" + + "subject='" + subject + '\'' + + ", text='" + text + '\'' + + ", organisationUnits=" + organisationUnits + + ", users=" + users + + ", userGroups=" + userGroups + + '}'; + } +}