← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18663: use RenderService to get jsonMapper instead of JacksonUtils

 

------------------------------------------------------------
revno: 18663
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-23 16:54:57 +0700
message:
  use RenderService to get jsonMapper instead of JacksonUtils
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/I18nController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-02-22 20:02:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-03-23 09:54:57 +0000
@@ -28,22 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
+import org.hisp.dhis.dxf2.render.DefaultRenderService;
 import org.hisp.dhis.dxf2.render.RenderService;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
 import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.hibernate.exception.ReadAccessDeniedException;
 import org.hisp.dhis.system.util.DateUtils;
@@ -64,8 +58,13 @@
 import org.springframework.web.context.request.ServletWebRequest;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.fasterxml.jackson.core.JsonParseException;
-import com.google.common.collect.Lists;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Lars Helge Overland
@@ -75,15 +74,15 @@
 public class AppController
 {
     private static final Log log = LogFactory.getLog( AppController.class );
-    
+
     public static final String RESOURCE_PATH = "/apps";
 
     @Autowired
     private AppManager appManager;
-    
+
     @Autowired
     private RenderService renderService;
-    
+
     @Autowired
     private LocationManager locationManager;
 
@@ -94,7 +93,7 @@
         throws IOException
     {
         List<App> apps = appManager.getApps();
-        
+
         renderService.toJson( response.getOutputStream(), apps );
     }
 
@@ -105,21 +104,21 @@
     {
         File tempFile = File.createTempFile( "IMPORT_", "_ZIP" );
         file.transferTo( tempFile );
-        
+
         String contextPath = ContextUtils.getContextPath( request );
-        
+
         try
         {
             appManager.installApp( tempFile, file.getOriginalFilename(), contextPath );
         }
         catch ( JsonParseException ex )
         {
-            ContextUtils.conflictResponse( response, "Invalid JSON in app manifest file" );            
+            ContextUtils.conflictResponse( response, "Invalid JSON in app manifest file" );
             log.error( ex );
         }
         catch ( IOException ex )
         {
-            ContextUtils.conflictResponse( response, "App could not not be installed on file system, check permissions" );            
+            ContextUtils.conflictResponse( response, "App could not not be installed on file system, check permissions" );
             log.error( ex );
         }
     }
@@ -148,7 +147,8 @@
             return;
         }
 
-        App application = JacksonUtils.getJsonMapper().readValue( manifest.getInputStream(), App.class );
+        ObjectMapper jsonMapper = ((DefaultRenderService) renderService).getJsonMapper();
+        App application = jsonMapper.readValue( manifest.getInputStream(), App.class );
 
         if ( application.getName() == null || !appManager.isAccessible( application ) )
         {
@@ -163,9 +163,9 @@
             if ( "*".equals( application.getActivities().getDhis().getHref() ) )
             {
                 String contextPath = ContextUtils.getContextPath( request );
-                
+
                 application.getActivities().getDhis().setHref( contextPath );
-                JacksonUtils.getJsonMapper().writeValue( response.getOutputStream(), application );
+                jsonMapper.writeValue( response.getOutputStream(), application );
                 return;
             }
         }
@@ -217,42 +217,42 @@
     public void setConfig( HttpServletRequest request, HttpServletResponse response ) throws IOException
     {
         Map<String, String> config = renderService.fromJson( request.getInputStream(), Map.class );
-        
+
         if ( config == null )
         {
             ContextUtils.conflictResponse( response, "No config specified" );
             return;
         }
-        
+
         String appBaseUrl = StringUtils.trimToNull( config.get( AppManager.KEY_APP_BASE_URL ) );
         String appFolderPath = StringUtils.trimToNull( config.get( AppManager.KEY_APP_FOLDER_PATH ) );
         String appStoreUrl = StringUtils.trimToNull( config.get( AppManager.KEY_APP_STORE_URL ) );
-        
+
         if ( appBaseUrl != null )
         {
             appManager.setAppBaseUrl( appBaseUrl );
         }
-        
+
         if ( appFolderPath != null )
         {
             appManager.setAppFolderPath( appFolderPath );
         }
-        
+
         if ( appStoreUrl != null )
         {
             appManager.setAppStoreUrl( appStoreUrl );
         }
     }
-    
+
     @RequestMapping( value = "/config", method = RequestMethod.DELETE )
     @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
     public void resetConfig( HttpServletRequest request )
     {
         String contextPath = ContextUtils.getContextPath( request );
-        
+
         String appFolderPath = locationManager.getExternalDirectoryPath() + AppManager.APPS_DIR;
         String appBaseUrl = contextPath + AppManager.APPS_API_PATH;
-        
+
         appManager.setAppFolderPath( appFolderPath );
         appManager.setAppBaseUrl( appBaseUrl );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/I18nController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/I18nController.java	2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/I18nController.java	2015-03-23 09:54:57 +0000
@@ -29,8 +29,8 @@
  */
 
 import com.fasterxml.jackson.core.type.TypeReference;
+import org.hisp.dhis.dxf2.render.DefaultRenderService;
 import org.hisp.dhis.dxf2.render.RenderService;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nManager;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -65,7 +65,7 @@
         I18n i18n = i18nManager.getI18n( searchPackage );
         Map<String, String> output = new HashMap<>();
 
-        List<String> input = JacksonUtils.getJsonMapper().readValue( inputStream, new TypeReference<List<String>>()
+        List<String> input = ((DefaultRenderService) renderService).getJsonMapper().readValue( inputStream, new TypeReference<List<String>>()
         {
         } );