------------------------------------------------------------ revno: 17099 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Tue 2014-10-14 14:01:10 +0700 message: new Message class for info/error messages, wip added: dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/AbstractMessageResponse.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/HttpMessage.java 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/MessageResponse.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageStatus.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses/ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses/ImportCountResponse.java
-- 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
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message' === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/AbstractMessageResponse.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/AbstractMessageResponse.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/AbstractMessageResponse.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,67 @@ +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.dataformat.xml.annotation.JacksonXmlProperty; + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +public class AbstractMessageResponse implements MessageResponse +{ + /** + * Optional type property. Since we are using the somewhat generic name 'response' for the data + * part of the message, this can be used to signal what kind of response this is. + * <p/> + * Some examples might be 'importCount', 'importSummary', etc. + */ + private String type; + + public AbstractMessageResponse() + { + } + + public AbstractMessageResponse( String type ) + { + this.type = type; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getType() + { + return type; + } + + public void setType( String type ) + { + this.type = type; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/HttpMessage.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/HttpMessage.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/HttpMessage.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,90 @@ +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.JsonPropertyOrder; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.google.common.base.Objects; + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +@JsonPropertyOrder( { + "status", "code", "httpStatusCode", "message", "devMessage", "response" +} ) +public class HttpMessage extends Message +{ + /** + * HTTP status code. + */ + protected Integer httpStatusCode; + + public HttpMessage( MessageStatus status ) + { + super( status ); + } + + public HttpMessage( MessageStatus status, Integer httpStatusCode ) + { + super( status ); + this.httpStatusCode = httpStatusCode; + } + + public HttpMessage( MessageStatus status, Integer httpStatusCode, String message ) + { + this( status, httpStatusCode ); + this.message = message; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public Integer getHttpStatusCode() + { + return httpStatusCode; + } + + public void setHttpStatusCode( Integer httpStatusCode ) + { + this.httpStatusCode = httpStatusCode; + } + + @Override + public String toString() + { + return Objects.toStringHelper( this ) + .add( "status", status ) + .add( "code", code ) + .add( "httpStatusCode", httpStatusCode ) + .add( "message", message ) + .add( "devMessage", devMessage ) + .add( "response", response ) + .toString(); + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/Message.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,167 @@ +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.JsonPropertyOrder; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.google.common.base.Objects; +import org.hisp.dhis.common.DxfNamespaces; + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +@JacksonXmlRootElement( localName = "message", namespace = DxfNamespaces.DXF_2_0 ) +@JsonPropertyOrder( { + "status", "code", "message", "devMessage", "response" +} ) +public class Message +{ + /** + * Message status, currently two statuses are available: OK, ERROR. + * + * @see org.hisp.dhis.dxf2.message.MessageStatus + */ + protected MessageStatus status; + + /** + * Internal code for this message. Should be used to help with third party clients which + * should not have to resort to string parsing of message to know what is happening. + */ + protected Integer code; + + /** + * Non-technical message, should be simple and could possibly be used to display message + * to an end-user. + */ + protected String message; + + /** + * Technical message that should explain as much details as possible, mainly to be used + * for debugging. + */ + protected String devMessage; + + /** + * When a simple text feedback is not enough, you can use this interface to implement your + * own message bodies. + * + * @see MessageResponse + */ + protected MessageResponse response; + + public Message() + { + this.status = MessageStatus.OK; + } + + public Message( MessageStatus status ) + { + this.status = status; + } + + public Message( MessageStatus status, String message ) + { + this.status = status; + this.message = message; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public MessageStatus getStatus() + { + return status; + } + + public void setStatus( MessageStatus status ) + { + this.status = status; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public Integer getCode() + { + return code; + } + + public void setCode( Integer code ) + { + this.code = code; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getMessage() + { + return message; + } + + public void setMessage( String message ) + { + this.message = message; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getDevMessage() + { + return devMessage; + } + + public void setDevMessage( String devMessage ) + { + this.devMessage = devMessage; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public MessageResponse getResponse() + { + return response; + } + + public void setResponse( MessageResponse response ) + { + this.response = response; + } + + @Override + public String toString() + { + return Objects.toStringHelper( this ) + .add( "status", status ) + .add( "code", code ) + .add( "message", message ) + .add( "devMessage", devMessage ) + .add( "response", response ) + .toString(); + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageResponse.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageResponse.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageResponse.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,36 @@ +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. + */ + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +public interface MessageResponse +{ +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageStatus.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageStatus.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/MessageStatus.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,37 @@ +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. + */ + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +public enum MessageStatus +{ + OK, ERROR +} === added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses' === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses/ImportCountResponse.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses/ImportCountResponse.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/message/responses/ImportCountResponse.java 2014-10-14 07:01:10 +0000 @@ -0,0 +1,95 @@ +package org.hisp.dhis.dxf2.message.responses; + +/* + * 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.JsonPropertyOrder; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.dxf2.message.AbstractMessageResponse; + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +@JsonPropertyOrder( { + "type", "created", "updated", "deleted" +} ) +public class ImportCountResponse extends AbstractMessageResponse +{ + private int created; + + private int updated; + + private int deleted; + + public ImportCountResponse( int created, int updated, int deleted ) + { + setType( "importCount" ); + this.created = created; + this.updated = updated; + this.deleted = deleted; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public int getCreated() + { + return created; + } + + public void setCreated( int created ) + { + this.created = created; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public int getUpdated() + { + return updated; + } + + public void setUpdated( int updated ) + { + this.updated = updated; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public int getDeleted() + { + return deleted; + } + + public void setDeleted( int deleted ) + { + this.deleted = deleted; + } +}
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp