dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38434
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19572: wrapped ImportTypeSummary in a WebMessageResponse
------------------------------------------------------------
revno: 19572
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 11:24:08 +0700
message:
wrapped ImportTypeSummary in a WebMessageResponse
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessageStatus.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.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
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java 2015-06-08 03:02:05 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java 2015-07-08 04:24:08 +0000
@@ -33,6 +33,7 @@
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.webmessage.AbstractWebMessageResponse;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +42,7 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@JacksonXmlRootElement( localName = "importSummaries", namespace = DxfNamespaces.DXF_2_0 )
-public class ImportSummaries
+public class ImportSummaries extends AbstractWebMessageResponse
{
private int imported;
@@ -53,6 +54,7 @@
public ImportSummaries()
{
+
}
public void addImportSummaries( ImportSummaries importSummaries )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2015-04-05 20:00:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2015-07-08 04:24:08 +0000
@@ -28,18 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.HashSet;
-import java.util.Set;
-
-import org.hisp.dhis.common.DxfNamespaces;
-
import com.fasterxml.jackson.annotation.JsonProperty;
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.DxfNamespaces;
+import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse;
+
+import java.util.HashSet;
+import java.util.Set;
@JacksonXmlRootElement( localName = "importSummary", namespace = DxfNamespaces.DXF_2_0 )
-public class ImportSummary
+public class ImportSummary extends AbstractWebMessageResponse
{
private ImportStatus status = ImportStatus.SUCCESS;
@@ -57,15 +57,18 @@
public ImportSummary()
{
+
}
public ImportSummary( ImportStatus status )
{
+ this();
this.status = status;
}
public ImportSummary( ImportStatus status, String description )
{
+ this();
this.status = status;
this.description = description;
}
@@ -78,7 +81,7 @@
{
return this.status != null && this.status.equals( status );
}
-
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java 2015-07-08 04:24:08 +0000
@@ -44,8 +44,7 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@JacksonXmlRootElement( localName = "typeSummary", namespace = DxfNamespaces.DXF_2_0 )
-public class ImportTypeSummary
- extends ImportSummary
+public class ImportTypeSummary extends ImportSummary
{
private String type;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java 2015-07-08 04:24:08 +0000
@@ -42,27 +42,27 @@
* <p/>
* Some examples might be 'ImportCount', 'ImportSummary', etc.
*/
- private String type;
+ private String responseType;
public AbstractWebMessageResponse()
{
- this.type = getClass().getSimpleName().replaceFirst( "WebMessageResponse", "" );
+ this.responseType = getClass().getSimpleName().replaceFirst( "WebMessageResponse", "" );
}
- public AbstractWebMessageResponse( String type )
+ public AbstractWebMessageResponse( String responseType )
{
- this.type = type;
+ this.responseType = responseType;
}
@JsonProperty
@JacksonXmlProperty( isAttribute = true )
- public String getType()
+ public String getResponseType()
{
- return type;
+ return responseType;
}
- public void setType( String type )
+ public void setResponseType( String responseType )
{
- this.type = type;
+ this.responseType = responseType;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessageStatus.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessageStatus.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessageStatus.java 2015-07-08 04:24:08 +0000
@@ -33,5 +33,5 @@
*/
public enum WebMessageStatus
{
- OK, ERROR
+ OK, WARNING, ERROR
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2015-06-11 02:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2015-07-08 04:24:08 +0000
@@ -314,10 +314,10 @@
property.getSetterMethod().invoke( persistedObject, value );
}
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
ImportStrategy.UPDATE, MergeStrategy.MERGE );
- serialize( request, response, summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
private List<String> getJsonProperties( String payload ) throws IOException
@@ -395,10 +395,10 @@
property.getSetterMethod().invoke( persistedObject, value );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
ImportStrategy.UPDATE, MergeStrategy.MERGE );
- serialize( request, response, summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
protected void translate( List<?> entities, TranslateOptions translateOptions )
@@ -496,21 +496,21 @@
preCreateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
ImportStrategy.CREATE, importOptions.getMergeStrategy() );
- if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
+ if ( ImportStatus.SUCCESS.equals( importTypeSummary.getStatus() ) )
{
postCreateEntity( parsed );
- if ( summary.getImportCount().getImported() == 1 && summary.getLastImported() != null )
+ if ( importTypeSummary.getImportCount().getImported() == 1 && importTypeSummary.getLastImported() != null )
{
response.setHeader( "Location", contextService.getApiPath() + getSchema().getRelativeApiEndpoint()
- + "/" + summary.getLastImported() );
+ + "/" + importTypeSummary.getLastImported() );
}
}
- renderService.toXml( response.getOutputStream(), summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
@RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
@@ -526,21 +526,21 @@
preCreateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
ImportStrategy.CREATE, importOptions.getMergeStrategy() );
- if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
+ if ( ImportStatus.SUCCESS.equals( importTypeSummary.getStatus() ) )
{
postCreateEntity( parsed );
- if ( summary.getImportCount().getImported() == 1 && summary.getLastImported() != null )
+ if ( importTypeSummary.getImportCount().getImported() == 1 && importTypeSummary.getLastImported() != null )
{
response.setHeader( "Location", contextService.getApiPath() + getSchema().getRelativeApiEndpoint()
- + "/" + summary.getLastImported() );
+ + "/" + importTypeSummary.getLastImported() );
}
}
- renderService.toJson( response.getOutputStream(), summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
//--------------------------------------------------------------------------
@@ -567,15 +567,15 @@
preUpdateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
ImportStrategy.UPDATE, importOptions.getMergeStrategy() );
- if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
+ if ( ImportStatus.SUCCESS.equals( importTypeSummary.getStatus() ) )
{
postUpdateEntity( parsed );
}
- renderService.toXml( response.getOutputStream(), summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
@@ -598,15 +598,15 @@
preUpdateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportTypeSummary importTypeSummary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
ImportStrategy.UPDATE, importOptions.getMergeStrategy() );
- if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
+ if ( ImportStatus.SUCCESS.equals( importTypeSummary.getStatus() ) )
{
postUpdateEntity( parsed );
}
- renderService.toJson( response.getOutputStream(), summary );
+ webMessageService.send( WebMessageUtils.importTypeSummary( importTypeSummary ), response, request );
}
//--------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java 2015-07-08 03:52:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java 2015-07-08 04:24:08 +0000
@@ -178,6 +178,7 @@
model.addAttribute( "model", grid );
model.addAttribute( "viewClass", "detailed" );
+
return "grid";
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java 2015-07-08 03:52:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java 2015-07-08 04:24:08 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
import org.hisp.dhis.dxf2.webmessage.WebMessage;
import org.hisp.dhis.dxf2.webmessage.WebMessageResponse;
import org.hisp.dhis.dxf2.webmessage.WebMessageStatus;
@@ -172,6 +174,31 @@
return createWebMessage( message, devMessage, WebMessageStatus.ERROR, HttpServletResponse.SC_UNAUTHORIZED );
}
+ public static WebMessage importTypeSummary( ImportTypeSummary importTypeSummary )
+ {
+ WebMessage webMessage = new WebMessage();
+
+ if ( importTypeSummary.isStatus( ImportStatus.ERROR ) )
+ {
+ webMessage.setStatus( WebMessageStatus.ERROR );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
+ }
+ else if ( importTypeSummary.isStatus( ImportStatus.SUCCESS ) && !importTypeSummary.getConflicts().isEmpty() )
+ {
+ webMessage.setStatus( WebMessageStatus.WARNING );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
+ }
+ else
+ {
+ webMessage.setStatus( WebMessageStatus.OK );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_OK );
+ }
+
+ webMessage.setResponse( importTypeSummary );
+
+ return webMessage;
+ }
+
private WebMessageUtils()
{
}